views:

193

answers:

4

If your company was being audited, or you were in an interview, and you were asked to provide an example of your best code for peer review, what would you submit? (I would like actual code examples for people to vote on).

Try to keep the sample small (less than 100 lines) and for the purposes of this forum lets keep it limited to JAVA, C# and PL/SQL.

This is a hypothetical question that might become practice soon. I am interested in what the hive mind finds to be a good example of excellent code.

Also, do you think this is a fair way of evaluating someone's skills and abilities?

A: 

Clean, concise, and commented.

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}

I'll make this community wiki in case anyone else would like to add extra functionality :)

Eric Petroelje
Pretty lousy comment - it says what the code does, not why. If I'm looking at the code, I almost definitely know it's displaying the string... but what I don't know is why you decided to write an entire program to print out a hard-coded "Hello World!" instead of just using echo.
Illandril
I think this answer was meant as a joke.
Brandon
@Illandril - well, echo would have been better, but I was limited to Java, C# or PL/SQL. Yes, the comment is lousy and the program is pointless. The point was more that the question itself is (while potentially somewhat interesting) is also pretty pointless.
Eric Petroelje
A: 

A while back I found some Java code an intern had written:

double cheeseburger;
char broiled;
long time;

Might have been his best code...

The problem with this is that it shows what someone can do given the time to make something "perfect" (as that's what people will do when asked to give sample code; they will polish it).

It really says nothing about their day-to-day coding skills, and how they will perform when given too little time, or when burining themselves out 80 hours a week...

Scott Stanchfield
+1  A: 

It can only give you a vague idea of how the guy programs.

Usually the best code cannot be shown for an experienced developer, for legal reasons obviously. The code is owned by the companies that the programmer worked for. Once I was talking about my previous projects to a guy and he was like "Can I see the code?". I answered "Please write an email to my previous employers and if they accept, I have no problem with it".

For an entry level developer or a guy without a job/life, they probably have some open source projects or examples that they can show.

The "legal reasons" bit is a good point. I wouldn't / can't post anything for that reason.
Pauk
+1  A: 

Without a joke, this was my best code:

No code. When I got the requirement I pointed out that the problem originates from elsewhere and they should change their workflow. Sometimes, you need to see a bigger picture and recognize the true problem.

kd304