MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Pages: 1

twistyAdministrator
Space Lord
Reged: 09/18/03
Posts: 15570
Send PM


Top Ten of Programming Advice NOT to Follow
#113826 - 06/12/07 12:03 AM


http://www.chrylers.com/top-ten-of-programming-advice-to-not-follow






Vas Crabb
BOFH
Reged: 12/13/05
Posts: 4462
Loc: Melbourne, Australia
Send PM


Re: Top Ten of Programming Advice NOT to Follow new [Re: twisty]
#113840 - 06/12/07 02:33 AM


I have to say I wholeheartedly disagree with most of what he says. I've had to deal with "software engineers" who think like him, and the effects they have on products. Just briefly:

10. An exception is a hidden goto that may only be hit under very specific circumstances. You don't know when it might happen, and it's easy not to catch an exception you didn't think of. It's far simpler to properly check error codes than properly catch exceptions.

9. There are perfectly good reasons for using unsigned integers, and indicating to the person reading the code that the value should never be negative is one of them. Another good use is dealing with a quantity value which can never be negative by definition. Signed integers don't protect you from anything. They can still overflow or underflow with bad consequences and you need to be wary of this.

8. I agree with most of what he says here. Designing classes around physical objects causes lots of trouble.

7. Whether you can read anyone's code or not, it's grating to be working on a module where the code doesn't look uniform. I don't mind different styles in different modules, but within a module, it's far easier to read if everything looks the same. Where I work, the rule is you follow the coding style of the person who started work on the module.

6. Sure, code should be self-documenting, and if code is confusing, you should rethink it. But while self-documenting code explains the "how", comments explain the "why", and that's what you're probably going to have trouble understanding later, anyway. If you find yourself having to explain the "how" in comments, you probably have a problem, but if you don't explain the "why", you're making trouble for yourself later.

5. Mixed feelings on this one. I believe properties are evil in general, as it's a hidden method call - you should be able to tell from the language syntax whether a line of code accesses a field or calls a method. But I do think accessors are better than public fields, because they give you the freedom to change the underlying implementation while preserving the interface.

4. There are some things that should be global to a process or a thread. It's a fact of life. Things like the file system (process global), run loop (thread global), window server connection (process global), etc. You should use singletons to implement these things, or you'll just be digging a hole for yourself.

3. This is one where you can have your cake and eat it too. Your debug build should be horribly strict on input. Check that everything's perfect every time. This is what assertions are for. Do lots of testing with your debug build. Then in your production build, have more tolerance for borderline input. This way, you can be reasonably sure you aren't abusing your functions, but still have a contingency plan for unexpected cases.

2. No strong opinion here.

1. Designing something properly to begin with saves endless pain later. If a system isn't designed to scale from the beginning, it's very hard to make it scale later, etc. Avoiding upfront design may seem easier at first, but it will hurt you. I'm not saying you have to follow some formal design process, or produce a set of "design specifications", I'm just saying that the design phase gives you a great opportunity to think about ideas and how they might or might not work before you spend a whole lot of time building what may be a flawed solution.



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Top Ten of Programming Advice NOT to Follow new [Re: Vas Crabb]
#114010 - 06/13/07 06:01 PM


Yeah, I agree with Vas a lot more than the original article. Exceptions instead of error codes my @$$ - clearly someone who's never dealt with an embedded environment.



Anonymous
Unregistered
Send PM


Re: Top Ten of Programming Advice NOT to Follow new [Re: R. Belmont]
#118474 - 07/20/07 04:42 PM


> Yeah, I agree with Vas a lot more than the original article. Exceptions instead of
> error codes my @$$ - clearly someone who's never dealt with an embedded environment.

I have mixed feelings about this. I find exceptions can be extremely handy, I've even implemented them in C. However they make it very easy to get into the habit of writing code that has bad error checking.

After you have added all the required exception handling then sometimes the code can look just as untidy as checking and returning error values. Except you don't decrease the range of your return values in the process.

It goes hand in hand with the finish each function idea. Sometime it's easier to grow a system as you can test it quicker but you have to go back and finish your code. You always have to do the work at sometime & going back is boring.

If you don't care whether it works properly or not then it's probably easier to just hack code as you go along and not worry if something might fail. I think that really is the future of software development.

smf


Pages: 1

MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Pi 
0 registered and 59 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 3867