9

So after a few struggles on my current uni assignment I’ve come to the realisation I need to change the way I write code, or at least the way I think about the code before I start.

I have a tendency to rush into coding something before I’ve planned it out properly, and over the last couple of days stupid mistakes on my part caused hours of stressing.

Are there any good methods for sitting down and planning stuff like this out, or is it just a case of getting some paper and a pen and writing out the logic etc in whatever way makes sense to you (me)?

Comments
  • 6
    - understand the problem.
    - devise a solution that addresses the problem.
    - architect an application that implements the solution.
    - switch your computer on.
  • 3
    For me it helps to first print the assignment instructions, to be able to highlight important parts. I’m not always writing all the logic on paper per see, but writing up abstract parts of how I’m trying to solve the problem. Like if it object-oriented, get som names of the classes I’m probably have to implement, instead of keeping it in my head.

    Git is also useful to use even by yourself, to make it easy to stash away code and try out some new idea without the pain of having to save away older versions.
  • 2
    I always start with pen and paper to sketch out information flow and then the main objects that will carry said information.

    After that it all depends on how complex it is going to be.

    But staying out of the computer to begin with help with keeping focus on the important structure and not implementation details.
  • 0
    I usually start with all of the h-files and then try to explain it all in two pre and post comments.

    //pre: this is what the function needs
    //post: this is what the function does

    Not sure if it's a good way of doing it, but that's what my OOP-course taught me
  • 1
    My process is sth.like:

    - think about the problem in general. What is the final goal?
    - find the entry point (web request, cli input, scheduled job, ...). When does your logic start?
    - Split the problem in independent tasks/components.
    - Find data flow between the components. (what data goes from. where to where? concurrent? sequential?)
    - Implement.

    Usually I plan this out by writing class and function Signatures with comments in the body what it does. Or, for more complex tasks, I make quick, dirty and syntactically wrong UML diagrams keep things ordered in my head.
  • 1
    @Katakompe I agree, the UML diagrams one does are ALWAYS syntactically wrong haha 😅. People who does them right are weird
  • 0
    split problem into smaller pieces, solve small piece one by one. The rest will come. Think of it as journey, you will not figure it out uiless you find the way how not to do it.
Add Comment