code contest

Pages: 1... 6789
May 8, 2011 at 5:06pm
Apparently he was "repeatedly" reported... hmm... I wonder who else reported him.

-Albatross
May 8, 2011 at 5:08pm
It wasn't me. Was it you?
May 8, 2011 at 6:35pm
No...

-Albatross
May 8, 2011 at 8:03pm
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?
May 9, 2011 at 5:35am
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 May 9, 2011 at 5:41am
May 9, 2011 at 4:49pm
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.
May 10, 2011 at 9:10am
@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".
May 10, 2011 at 7:51pm
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.
May 10, 2011 at 11:16pm
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
May 13, 2011 at 10:51pm
How did we do?
May 14, 2011 at 7:02pm
Yeah, who won?
May 14, 2011 at 7:04pm
I did! ;)

-Albatross
May 14, 2011 at 7:43pm
What did you submit?
May 14, 2011 at 8:21pm
Nothing, actually. I don't much like competition.

-Albatross
May 15, 2011 at 5:12am
Hmmm I vote for avlagrath for the successful roll.
May 15, 2011 at 8:44pm
Second.
May 16, 2011 at 9:40am
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;
}
May 18, 2011 at 9:09pm
@unregistered:

Too late for you unfortunately. That would have definitely won too...
May 19, 2011 at 8:29am
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.
May 19, 2011 at 1:29pm
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 May 19, 2011 at 1:30pm
Pages: 1... 6789