Programming the right way?

Started by
22 comments, last by Ronnie Mado Solbakken 10 years, 8 months ago

Greetings all,

This is my first post here, and I suppose the write place to be asking,

I've been programming for several years but I would describe myself as a hack and slash programmer, with buggy code and not very well written.

Can anyone point me in the right direction to coding the right way with less bugs and more reliability?

My preferred learning platform is visual and audio :)

I mainly program in vb6 and vb.net but am currently learning c++ I don't know if the proper technique can be applied across all languages or whether there is a proper way to do each one?

Any help/links would be greatly appreciated.

Thanks

Richard

Advertisement

Hey Richard,

I always like these kinds of questions, and I ask it about myself all the time. For me, the best way to gain the information you are looking for was to work with/learn from other more experienced developers and see what they do. I also browse code on projects that are more "mature" and have industry experienced professionals writing it. Take a look at some major open source projects in the language of your choice. You may be able to pick up some patterns and ideas that make you say "Oh, I wouldnt have thought to do it this way". It might also help you if when you feel you have some problem code to post it here and ask for input. I have seen many devs on here give some valuable feedback on how to organize or refactor things.

Sorry I don't have any books or visual aids that have helped me. =(

Generally though, books on software architecture and "best programming practices" type articles would be something to look for.

Good Luck!

jmillerdev.com

Follow me @jmillerdev

Thanks for your reply tharealjohn,

I hadn't really considered looking over peoples source code, but I will definitely start having a nosy at other open source projects and how they are built.

To me it comes down to working on projects and meeting your objectives. Experience is the first thing.

After that I'd suggest looking up books on clean code. I learned a lot from working with people that had worked a lot in the business and every place I've worked at I have had the opportunity to learn even more.

Hit up amazon for "Clean Code". There should be a book with that title, and its pretty good IMO. Goes over some things that people do all the time that contribute to the downfall of their own code.

For more on my wargaming title check out my dev blog at http://baelsoubliette.wordpress.com/


Hit up amazon for "Clean Code". There should be a book with that title, and its pretty good IMO.

That book it is a bit extreme. For instance, they advocate that each function should do only one thing, so you shouldn't write code like this:

void compute_salary() {
  double result = 0.0;
  try {
    result += compute_base_salary();
    result += compute_bonus();
    result += compute_adjustments();
  }
  catch (...) {
    complain("Problem computing salary: Returning 0.");
    return 0.0;
  }
  return result;
}

The reason is that this function does two things: Exception handling and computing something. The book advocates placing a single function call in the `try' block, so that this function's only purpose is exception handling. Unfortunately, I find myself struggling to find a good name for such a function (`compute_salary_without_exception_handling'?), which is my primary guide as to whether something should be in its own function.

But it is still a good read, and it will make you think about many interesting issues.

I found looking at other peoples code helped a lot but also looking at my old code that I wrote years ago and spotting the mistakes in them. This will also give you a sense of growth as a programmer in that you get to see what you are doing better now.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


Can anyone point me in the right direction to coding the right way with less bugs and more reliability?

First things first, there's no "right" way - there are a bunch of ways that will get the job done well.

Beyond that, I would look at the code you have written, and figure out why there are bugs. Did you use certain patterns that made the code fragile? Did you name things poorly so they got misused? Did the functions have too many side effects? Did you not have a good process to prevent typos/merge errors/etc?

Books and even good programmers can only bring you so far. Eventually you have to internalize the knowledge so that you can get the feel of what things are troublesome and why; what things are usually good and why. Then you can better apply those things to the problems at hand.

For C++ programming I highly recommend checking out Scott's "Effective" books: http://www.aristeia.com/books.html

They are a great resource and point out common techniques that everyone should use.

This is in my opinion the best resource ever on this topic: http://www.infoq.com/presentations/Simple-Made-Easy

Also, you might wanna read this: https://sites.google.com/site/steveyegge2/being-the-averagest (and maybe this, this is where the name of the other article comes from: http://www.paulgraham.com/avg.html)

I'm always happy to point people to Code Complete (2nd ed.). It's got lots of great language-agnostic information and is easy to use as a reference. But as others have said, it's only through experience that you improve at coding.

-------R.I.P.-------

Selective Quote

~Too Late - Too Soon~

This topic is closed to new replies.

Advertisement