1

I find myself reworking my code quite a bit, especially when learning to write algorithms that involve keeping track of multiple attributes and labels.

I feel that having the pseudo-code written up, having a small numerical example worked out, and a few test cases is usually a good approach. Yet, I find myself making mistakes and reworking code constantly.

Is there a better approach or a structured methodology that I should follow? Greatly appreciate the advice.

2
  • 2
    Can you give an example of what you're talking about? It's not entirely clear exactly what you mean.
    – user28988
    Commented Feb 28, 2014 at 3:06
  • For example, I can get an algorithm like Floyd Warshal to work after a number of tries...just makes me wonder if it is just lack of enough discipline on my part, or is there a systematic way to approach such tasks. My approach is "pseudo-code --> small numerical example worked out by hand ---> a few test cases". However, I am not a professional programming...just wondering if there are better ways to approach such tasks.
    – akrishnamo
    Commented Feb 28, 2014 at 3:12

2 Answers 2

1

Yet, I find myself making mistakes and reworking code constantly. Is there a better approach or a structured methodology that I should follow?

Some decades ago some people believed that there would be a better methodology and called it "waterfall model". But nowadays its widely accepted that when trying to develop a non-trivial program, you will almost never "get it right" on the first shot - even if you are very experienced. There will be bugs, requirements and edge cases you overlooked at the first sight, performance considerations, necessary design improvements only getting visible when your program reaches a certain size, and some things more.

IMHO the key point for professionalism is learning to manage the changes. This starts with simple things like a priority list of open requirements, making some design considerations before coding (like the ones have described in your comment), the use of version control (to keep track of any changes), and it goes further with release planning, automatic tests (to make sure future changes don't break existing behaviour) and application of the SOLID principles.

1

There's a few things you can do to minimize rework still.

  • If you start with clean code, you won't need to clean it up.
  • If you write loosely coupled code, it won't need to impact as much code if you just need to touch up on a few things. Same applies to monster classes and and methods. Having it all one one place is sometimes handy, but not necessarily easy to edit.

You'll make less initial mistakes as you get more experience, and find better test cases from the start as well. For the rest, it's pretty much your normal developer's everyday life.

Not the answer you're looking for? Browse other questions tagged or ask your own question.