The Artima Developer Community
Sponsored Link

Weblogs Forum
The Principles of Good Programming

19 replies on 2 pages. Most recent reply: Feb 9, 2012 10:29 AM by Rudolf Pecinovský

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 19 replies on 2 pages [ « | 1 2 ]
Jan Samohyl

Posts: 14
Nickname: asgard
Registered: Feb, 2008

Re: The Principles of Good Programming Posted: Aug 2, 2011 2:58 AM
Reply to this message Reply
Advertisement
> DRY - Don’t repeat yourself - This is probably the single most fundamental tenet in programming is to avoid repetition.

I disagree with this claim. DRY is not a fundamental tenet in programming at all. I think people wish it were, but it isn't.

Look at mainstream programming languages. There is very little of actual support for DRY. The languages that supports DRY principle the most are probably Common Lisp with its macro system, Forth with its immediate words and Haskell with its higher order functions. Java/C++/C# don't even come close.

And as you can see from adoption rate of Lisp, Forth and Haskell, DRY has also its disadvantages (worse readability?). So no, DRY is not that important as it is made to be; though I certainly wish it were, because I like Common Lisp and Forth (I don't know much about Haskell, and have reservations about the purity of functions).

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: I think Open/Closed Principle has issues too Posted: Aug 4, 2011 12:49 PM
Reply to this message Reply
> > What YAGNI says is: If you're writing software for
> > an 8-bit camera, don't write 16 bit algorithms.
>
> But that's the idea I don't agree with.
> The point was that I spent the extra time to develop
> templated code so that I didn't write 8 and 16 bit
> image algorithms, I wrote one algorithm that worked
> for any bit depth. And if the algorithm needed updating
> then it was updated for all image types. Writing for just
> 8 bit depth would have been short-sighted and dumb.

While there is something to YAGNI (I'll wager that we all have worked with over-designed systems), I agree strongly with John that blindly following this is stupid.

Where I work, we are building the Nth version of a large number of systems. We have to do this because of the brittleness of the previous implementations. So when we are building say a fundamental web service specification, we already have a pretty good idea what it needs to support. Basically, the business we are in hasn't changed and we needed to have a certain functionality 5 out of the last 5 times we've done it. It makes no sense for us to pretend like we don't know we will need it the 6th time but the people who walk in off the street talking about stuff like YAGNI don't have that background information.

Certain aspects of system design are extremely costly to add in later. For example, how fault-tolerance is implemented can fundamentally change the approach of a system. The best analogy I can think of is that when you build a house, you better think ahead before you lay the foundation. Obviously, software isn't a house but there are ways to paint yourself into a corner when building software.

A good example of this was a system I heard about where all dollar amounts were stored in 16 bit ints. They were smart enough not to use floats but didn't create/use a special money type or anything (YAGNI). But then, a potential customer wanted to use the system to sell big ticket items like airplanes and they lost out on a big contract.

A little bit of forethought can go a long way. It just needs to be balanced. The more experience you have the more likely your foresight will pay off and the less you need to blindly adhere to YAGNI.

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: I think Open/Closed Principle has issues too Posted: Aug 4, 2011 1:17 PM
Reply to this message Reply
It's probably better to describe these aspects of coding as aspirations rather than principles. Calling them principles gives them the veneer of being rules that must be followed. In the worst case keeping to the rules becomes as important as delivering the customer requirements, with any compromise then seen as a Bad Thing. Aspirations, on the other hand, are things that have to be aimed for, rather than hit. Seen that way, they are a Good Thing. Not meeting them is not seen as a failure, and compromise and balance is built in to their working.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: I think Open/Closed Principle has issues too Posted: Aug 4, 2011 5:28 PM
Reply to this message Reply
> It's probably better to describe these aspects of coding
> as aspirations rather than principles.
> Calling them principles gives them the veneer of being
> g rules that must be followed. In the worst case keeping
> to the rules becomes as important as delivering the
> customer requirements, with any compromise then seen as a
> Bad Thing. Aspirations, on the other hand, are
> things that have to be aimed for, rather than hit. Seen
> that way, they are a Good Thing. Not meeting them
> is not seen as a failure, and compromise and balance is
> built in to their working.

I think the problem with a lot of these rules of thumb is that they are stated in terms that are subject to wildly different interpretations. All of these contain an essential truth but understanding what those truths are requires a breadth and depth of knowledge that the target audience does not have.

For example, a lot of people might argue that the simplest thing that could possibly work is to eliminate all layers of abstraction. You would look at the code and know exactly what it does. Someone else would say that the simplest thing possible is to name all methods 'eval' and use polymorphism for everything. 'Simple' is inherently subjective and to make these things truly meaningful and useful to the beginner, you have to have a detailed explanation of what 'simple' means. I find these kinds of things can actually be detrimental for this reason.

Rudolf Pecinovský

Posts: 1
Nickname: rudyment
Registered: Jul, 2004

Re: The Principles of Good Programming Posted: Feb 9, 2012 10:29 AM
Reply to this message Reply
I thing you forgot one of most important principles:
"Program to an 'interface', not an 'implementation'".
Probably it is so natural to you that you forgot that many programmers have problems with its acceptance.

Flat View: This topic has 19 replies on 2 pages [ « | 1  2 ]
Topic: WebSockets: A Glimpse of the Future Previous Topic   Next Topic Topic: Java 7: Too Little, Too Late?


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us