code contest

Pages: 1... 6789
Apparently he was "repeatedly" reported... hmm... I wonder who else reported him.

-Albatross
It wasn't me. Was it you?
No...

-Albatross
kfmfe04

Veltas, if you had worked out in industry and have had to debug other developer's overly verbose, obfuscated, spaghetti code that has dependencies going in all directions, then maybe you, too, can appreciate that less is, indeed, more.

Awesome code is awesome code, whether or not it's in C++.


kfmfe04, how long have you been in the industry (I'm assuming you have from the way you've written your post)? It's not at all uncommon for people to write very short code that makes little or no sense whatsoever, and debugging that sort of code is hell, almost as bad as very long and verbose code that doesn't make logical sense. I'm not in the industry but I've worked on a lot of code, and a fair amount of C++, so I don't think being in the industry should have much effect on my appreciation for easy to understand code. More importantly, you very obviously haven't read this argument right through properly because your last point is completely besides what me or rapidcoder have said, and I've been fully appreciative of industry code, more so than others.

hamsterman

@Veltas http://www.stanford.edu/class/cs242/readings/backus.pdf
Food for thought.


hamsterman, thank you for the link. My Mechanics teacher talks a lot about his Fortran days, back when after being taught by the computer science people how to use it he quickly ran into problems designing his numerical analysis program that quite frankly nobody in the computer science department had any idea how to solve. I'm very appreciative of Functional Programming myself, as I happen to know what it is and what it means for us in many languages today. I get the impression that what the article describes as functional programming is now generally seen as a structured programming varient, however, as functional programming seems to be something completely different these days. I'm not entirely sure myself, as the rules seem to be very abstract (not that it matters in common programming tasks). Perhaps you could help out?
closed account (S6k9GNh0)
At some point, smaller code can also generally mean smaller image size. For instance, having a completely straight-line piece of code containing a 1000 lines instead of a 3 line for loop can increase image size greatly. I agree that smaller code tends to be easier to read and often more flexible which is what I work towards. This is obviously not always the case. I'd rather write 3 lines of code than make a for loop to do the exact same thing the 3 lines of code would have done, although, I never find myself doing this.
Last edited on
I like to split functions up into small blocks and then arrange them in reverse-chronological order (actually I order them by dependency first, so that the function at the bottom is not used by ay other function in that file). Most of the time I try to keep functions less than 10 lines long each.
@Veltas - let's just say I started my programming career in the 80's in the same Murray Hill building where K&R worked...

unfortunately, anytime generalities such as "shorter code is better" is stated, there are going to be exceptions and various interpretations; for example, it's possible to write shorter (in number of characters) Brainfuck code, but that's not going to be easier to understand or to maintain. in the same vein, some design patterns or "generalized code" can get so complex that only the original author knows how to modify it without breaking something. I've seen many intermediate-level developers who are so obsessed with flexibility that they forget the costs: added complexity and difficulty of understanding.

in the end, working on a large set of code is a fight against complexity - you want your dependencies to go in one direction - you want small enough modules that express ideas concisely, and without fuss. why? in general, defects have a harder time hiding in simple code.

it's analogous to math equations - if you can simplify it, why not make your life easier?

I think that's the spirit of "shorter code is better".
It's better to say "concise" or "elegant" than "short"r. Short code brings up throughts of short, non-descript function and variable names... Not that long, non-descript function/variable names are any better, mind.
today is the last day!!!! all codes are to be turned in today!!!!!
codes that are turned 1 day late will be acceptable but no later
How did we do?
Yeah, who won?
I did! ;)

-Albatross
What did you submit?
Nothing, actually. I don't much like competition.

-Albatross
Hmmm I vote for avlagrath for the successful roll.
Second.
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using std::cout;
using std::endl;

int main()
{
        cout << "Hello World!" << endl;
        return 0;
}
@unregistered:

Too late for you unfortunately. That would have definitely won too...
Unregistered:
1
2
3
4
5
6
7
8
9
#include <iostream>
using std::cout;
using std::endl;

int main()
{
        cout << "Hello World!" << endl;
        return 0;
}


Good stuff.
That code doesn't work because you just get a black box that shows up and then disappears.

Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <conio.h>
#include <curses.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <windows.h>
#include <algorithm>
#include <stdio.h>
#include <stdint.h>
#include <cmath>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

using namespace std;

void main(int argc, char* argv[])
{
        int x;
        for (float i = 0; i < argc; ++i)
                printf(std::string("hello, world").c_str());
        cout << flush;
        x = strlen("hello world") * 4 - 2;
        cout << "Press any key to continue...";
        getch();
        system(cls);
        clrscr();
        refresh();
        x = strlen("hello world") * 4 - 2; // in case x forgot its value
        exit(log10(pow(10, 42)) - x);
}


I know, I know, a little advanced for this sort of contest, but I thought I'd actually try on this one ;)
Last edited on
Pages: 1... 6789