Friday, October 19, 2007

Source Code

Scott Hanselman has a new column/category (Hanselman - Weekly Source Code) based on the tag to be a better developer started by Justice Gray (Be a Better Developer in 6 Months).

Like Justice Gray committed to reading 1 book per week, Scott Hanselman started reading good source code (as it's one of the best ways to be a better programmer, with which I deeply agree - Reading to Be a Better Developer - The Coding4Fun DevKit).
In one of the recent blogs in this category, I discovered this post: LukeH and a fully LINQified RayTracer. It's a LINQified C# ray tracer (in one Linq Expression that extends over 60 lines!!):

var pixelsQuery =
from y in Enumerable.Range(0, screenHeight)
let recenterY = -(y - (screenHeight / 2.0)) / (2.0 * screenHeight)
select from x in Enumerable.Range(0, screenWidth)

...

select new { X = x, Y = y, Color = traceRay(new TraceRayArgs(ray, scene, 0)) };

He advises against this type of programming (big bang methods/expressions), but it's one heck of an example for Linq.

In the same vein, he links to a list of Programming Guiding Principles by Patrick Cauldwell (This I Believe- The Developer Edition), that start with general principles and has good advices on Unit Tests, Test coverage, Buy vs Build, Dependencies, Contracts (code), Visibility, Authentication, Tracing, Error handling and The definition of done (it means different things to every developer that I know).

Reading all this stuff about code (and the code itself), I started thinking about what are good qualities of Source Code. So, to every beginner (and as a reminder to all senior developers that practices and repetition makes perfection) go [re-]read Code Complete by Steve McConnell...

To me, the first that comes to mind is:

  • stop and think for five minutes before defining the name of a method, variable;
  • think early on on the design of the code (method or class), it's complexity, performance and all other important characteristics;
  • DRY (Don't repeat yourself - don't copy paste code, documentation, use cases, ...)
  • KISS (Keep it Simple ..., the design, the methods)
  • ...

2 comments:

Unknown said...

These louis vuitton are long lasting as they are made of the highest quality leather that are durable and can stay with you for the rest of your life. Louis vuitton bags will have to spend your money once for purchasing these bags and they would be a part of your accessory forever. louis vuitton handbags can keep on adding more bags of the company as many of them keep on coming, providing you more style and fashionably designed handbags. They are available in every color and are there to provide you great levels of lv" and style. You can easily grasp the attention of people around you and they would consider you the fashion icon.

Unknown said...

While the Chanel
changes hardly from year to year do not about buy chanel watches
. All-embracing the Chanel bags
has array of a aboveboard attending to it.