Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 6,125 | Comments: 45,488

filter by tags archive

It is a matter of style...

time to read 1 min | 113 words

Today I freaked out two co-workers by looking at their code and saying (respectively) "How long have you worked with C?" and "You didn't get a lot of time with C++, right?"

The pieces of code in question were: (for the C comment)

Customer customer = null
for(int i=0;i<array.Length;i++)
{
	customer = new Customer();
	//do stuff
}

And: (for the not a lot of time in C++ comment)

int totalCarCount;
if( IsValid )
{
	totalCarCount = GetValidTotalCars();
}
else
{
	totalCarCount = GetInvalidTotalCars();
}

int totalWheelCount;
DoComplexWheelCalculation( out totalWheelCount);

And yes, the examples here are fake, and both are good developers, and I just said what came to mind first :-)


Comments

MarkK

As an enthusiatic young developer, I dont suppose you would kindly point out why you made the comments?

I confess I'm naive and dont see the issue with the code samples :)

Ayende Rahien

There isn't any issue with the code samples. :-D

C programmers tend to put declarations at the top of the function, basically.

Mats Helander

Actually, Classic Basic coders do that too.

/Mats

Frans Bouma

as a person who is raised with assembler and C, I had to look very carefully before I saw the issue :) (I first thought: it's the 'GetValid/InvalidTotalCars method which should 1 method with a parameter ;)). It's indeed something one has to work on really hard to get rid of, it took me several years before I got used to declare things when I first needed them instead of at the top of the method.

And then you run into a try/finally clause and you have to declare the variable OUTSIDE the try to be able to access it in the finally block :(

clayton collie

there was a spell a few years back where i was contributing to an opensource project (in c), consulting on a Delphi project (Pascal), while doing C# for some personal work.

needless to say, it was confusing keeping my code from looking confused...

Pierre Henri

For the C++ comment, is it because he didn't use the ternary operator?

Or because he used an output parameter instead of a return value?

Ayende Rahien

That was for the NON C++ comment, actually, and it was the variable placing that gave the hint.

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. The design of RavenDB 4.0: Physically segregating collections - 4 hours from now
  2. RavenDB 3.5 Whirlwind tour: I need to be free to explore my data - about one day from now
  3. RavenDB 3.5 whirl wind tour: I'll have the 3+1 goodies to go, please - 4 days from now
  4. The design of RavenDB 4.0: Voron has a one track mind - 5 days from now
  5. RavenDB 3.5 whirl wind tour: Digging deep into the internals - 6 days from now

And 12 more posts are pending...

There are posts all the way to May 30, 2016

RECENT SERIES

  1. The design of RavenDB 4.0 (14):
    03 May 2016 - Making Lucene reliable
  2. RavenDB 3.5 whirl wind tour (14):
    04 May 2016 - I’ll find who is taking my I/O bandwidth and they SHALL pay
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats