• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Richard Mountain

Programming the right way?

23 posts in this topic

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

1

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites


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.

2

Share this post


Link to post
Share on other sites

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.

+ rep for you, I was about to recommend that same book.  It really is "the" book about how write quality code.  Just a short 960 pages of line after line great advice.  I took notes while reading this book, the notes were on a large white board I keep on the wall by my computer, they've been there for a year, I know them by heart now but I can't bring myself to erase them.

0

Share this post


Link to post
Share on other sites

1) Design before writing code

2) Refactor duplicated code

3) Make sure the code is short and straightforward

 

When you write code, make sure the other person can understand it without comments

 

Well-written code are straightforward

1

Share this post


Link to post
Share on other sites

here is a little tip i just caught myself in - don't use random numbers in your code - give the number a variable name somewhere..

 

i just found a line in my code that said if ( pos.x * 1.27f <= 23.45f )

 

this took me like an hour to figure out why i wrote that

0

Share this post


Link to post
Share on other sites

I think the thing that's most important when writing any program is thinking about maintainability before you start writing it.

No matter what framework, or tools you decide to use, you should always break the functionality of your program into organized pieces, so that you always know where to look if you're extending, or if something breaks.

 

You can use patterns like MVC for this, or you can create your own.

As long as you understand how your app is built without having to dig for anything, you're in good shape.

0

Share this post


Link to post
Share on other sites

here is a little tip i just caught myself in - don't use random numbers in your code - give the number a variable name somewhere..

 

i just found a line in my code that said if ( pos.x * 1.27f <= 23.45f )

 

this took me like an hour to figure out why i wrote that

 

Or you could save some time and just write in a comment on the same line what the numbers are about. Then you don't have useless variables that could get you confused.

0

Share this post


Link to post
Share on other sites

 

here is a little tip i just caught myself in - don't use random numbers in your code - give the number a variable name somewhere..

 

i just found a line in my code that said if ( pos.x * 1.27f <= 23.45f )

 

this took me like an hour to figure out why i wrote that

 

Or you could save some time and just write in a comment on the same line what the numbers are about. Then you don't have useless variables that could get you confused.

 

 

It takes no more time to declare a well-named variable than it does to write in a comment explaining a number, and a well-named variable shouldn't be confusing. Using magic numbers is a terrible habit. I'm sure there are situations where the approach you describe is appropriate, but advocating it as a rule sounds to me like saying that doing cocaine is fine as long as you go jogging afterwards because jogging is healthy, right? It's focusing on the wrong end of the problem.

1

Share this post


Link to post
Share on other sites

 

 

here is a little tip i just caught myself in - don't use random numbers in your code - give the number a variable name somewhere..

 

i just found a line in my code that said if ( pos.x * 1.27f <= 23.45f )

 

this took me like an hour to figure out why i wrote that

 

Or you could save some time and just write in a comment on the same line what the numbers are about. Then you don't have useless variables that could get you confused.

 

 

It takes no more time to declare a well-named variable than it does to write in a comment explaining a number, and a well-named variable shouldn't be confusing. Using magic numbers is a terrible habit. I'm sure there are situations where the approach you describe is appropriate, but advocating it as a rule sounds to me like saying that doing cocaine is fine as long as you go jogging afterwards because jogging is healthy, right? It's focusing on the wrong end of the problem.

 

 

I never said it should be a rule. Just my opinion. I don't like it when i have variables that are only used once just for the sake of knowing what they are used for. That's what comments are for. If i use them more than once i almost always use variables for them because it's easier to change the value of it. I only have to change one value and not find and replace 3 values. But if the value is only used once in the whole program why not just write it in there and make a small comment. I know it's preference but still i don't like it when there are 'unnecessary' variables.

0

Share this post


Link to post
Share on other sites
I'm quite new to programming (c++) and I've been trying to make sure I'm learning good techniques. A lot of things I'm reading is to avoid older ways of doing things. Like you should be using containers such as Vector instead of Arrays, trying to avoid pointers, and if you use a lot of New/Delete's then it's worth reading about RAII.
0

Share this post


Link to post
Share on other sites


I never said it should be a rule. Just my opinion. I don't like it when i have variables that are only used once just for the sake of knowing what they are used for. That's what comments are for. If i use them more than once i almost always use variables for them because it's easier to change the value of it. I only have to change one value and not find and replace 3 values. But if the value is only used once in the whole program why not just write it in there and make a small comment. I know it's preference but still i don't like it when there are 'unnecessary' variables.

 

As I said, there are bound to be cases where your preference here is the best choice. But in practical terms, as I also said, declaring a variable with a good name takes no more time than writing a comment, and a well-named variable should be equally clear about its purpose as well as more concise and more convenient for code maintenance.

It will normally be true that a number, used only once and only in a function's local scope, can be similarly well represented by a plain integer/float/double/whatever or a named variable. But it is less convenient and less natural for a programmer to refer to a comment, located outside of the code fragment being reviewed, to figure out the significance of a variable which is being used when a descriptive variable name can document its own purpose and significance in-place.

There are other design issues related to this, described quite well in the book I mentioned above. The shortest summary is that named variables help a programmer manage the complexity of the project, while magic numbers do not. A magic number is improved by a descriptive comment, but is still inferior to a named variable. But my main point is that your preferred approach on this offers no advantages over a named variable, not even saving time, while being less clear, less concise, and less expandable.

I would suggest that you think a bit more broadly about both approaches when comparing them. Just because you aren't using named variables in these cases doesn't mean that they are useless, and aside from satisfying your pre-existing preference your style isn't even providing the one benefit you attributed to it. I would be interested to hear any other arguments you have, but at the moment I am entirely unpersuaded.

 

EDIT: Added quote to make the response clearer.

Edited by Khaiy
0

Share this post


Link to post
Share on other sites

In the case I was talking about it was a simple mistake - I was just in a hurry testing my grid system... a comment or a good variable name - both good solutions to the problem.

 

My tip really was more aimed at when your in a hurry and just throwing numbers around to test stuff - or code around in general - make sure if you were to not see that piece of code for weeks you could easily see why its there.. This situation happens a lot I think and a simple variable or comment could have saved me some time (it turns out I got distracted with something else and didn't look at that code again for a few weeks).

 

Moral of the story always try to write your code as if someone else is going to read it - it may seem a bit tedious but the time saved is almost always more than the time it takes to write code that way

0

Share this post


Link to post
Share on other sites

Here are some other useful books about best practices that I have picked up and seem to be popular:

 

Design Patterns: Elements of Reusable Object-Oriented Software

http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1374776130&sr=8-1&keywords=design+patterns

 

C++ Coding Standards: 101 Rules, Guidelines, and Best Practices

http://www.amazon.com/gp/product/0321113586/ref=wms_ohs_product?ie=UTF8&psc=1

0

Share this post


Link to post
Share on other sites

Hey Richard,

 

There is nothing wrong with hack and slash / rapid prototyping it can make you very productive, with that being said you need to train yourself to spot potential issues with the code you write and know the impact it may have.

 

That should give you a long term to-do list, just remember premature optimisation is the root of all evil.

 

So what to do?

 

Pick challenging personal projects which cover broad areas that are just beyond your current level, for example: an account management system with a login and user profile front end.

 

That should cover database and class design, security, state management etc, also you may end up with a reusable system for your future game projects.

 

Read up on topics before tackling them to give yourself a degree of confidence that you are going in the right direction.

 

Object Oriented Programming Concepts (Overview)

Object Oriented Programming Concepts (In Detail)

S.O.L.I.D. Principles of Class Design (Overview)

Software Design Patterns (Overview)

 

A couple of "classic" books which are fairly language agnostic:

  • Code Complete.
  • Patterns of enterprise application architecture.
  • The Pragmatic Programmer
  • Refactoring: Improving the Design of Existing Code

 

Useful websites for finding answers to technical questions:

 

http://stackoverflow.com/

http://programmers.stackexchange.com/

 

Try picking up another programming language once you are confident, it will make you a more rounded programmer and will teach you something new that you can take with you in future.

 

Sorry this is a bit of scatter gun approach to answering your question, but hopefully you can find some useful information in there!

 

Jamie.

Edited by redellion
0

Share this post


Link to post
Share on other sites

Like you should be using containers such as Vector instead of Arrays, trying to avoid pointers, and if you use a lot of New/Delete's then it's worth reading about RAII.


That doesn't sound like particularly good advice to be honest, at least not for a beginner. Arrays and pointers have particular uses and using a vector when an array is the more ideal solution is just as wrong as using an array when a vector would be better. At first, it's better to learn the difference between the two, and then learn when, and when not, to use them.

Avoiding pointers is just non-advice really (at least without context). If you're using Java, then you don't even have pointers, and if you're using C, just try and do anything meaningful without them.

0

Share this post


Link to post
Share on other sites

I can only talk about what I've been doing myself:

 

a) - Watch videos about computer science and programming, e.g. from Stanford University or UNSWlearning.

b) - Get/Read books about general programming concepts.

    b1 - For Java Programming (my discipline atm), get books like Effective Java Second Edition, Java The Complete Reference, etc.

    b2 - For general Programming and Problemsolving, get The Art of Computer Programming by Donald Knuth.

c) - Get a better IDE (if applicable) and be sure to make your own code as easy to read as possible, even to yourself. Proper commenting is key.

d) - Github and open source code sharing is your friend.

 

etc.

Edited by Malabyte
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0