Is this bad practice and how can I improve on this

Is this bad practice and how can I improve on this
0

Lately I’ve been wasting a lot of time trying to anticipate what methods I might need to make a project work. partially because I have in mind that such functions might be easier to test

what ive tried doing today i just start writing once super function where I print every variable to see what my function does, then I split repetative code into their own function. I figure these smaller functions are what I will write code to test but only after Ive written my super function.

I know TDD doesnt mean test first which i thought for a long time but still feels kinda wrong because I have it burned in my mind that smaller code is better

heres my code

took me like 5 hours to write because I kept making mistakes and starting over then I just said fk it and went for mono code which took me less than an hour but it works so far and is absolutely unmaintainable

like I said, i plan to break this up down the line, just want to get some tips for faster coding with less confusion

(Disclaimer: I am not a professional; I am a college student)

What you do is actually what they do at large companies, I think. This strategy, like any that you could possibly use, has its benefits and drawbacks. The benefit is that it is much more organized: no uncertainty. The drawback is that if you have a new idea for a feature, it may be hard to add what you want.

What I do is just identify, in plain english, what I want my program to do and how exactly I am going to do it. If you do that, you will notice you are using a lot of verbs, like “we need to do this and then we need to do this”. Those verbs are your functions, and per your own definition, those are necessary.

For example, in your code I can see a bunch of todo comments and stuff where you say, for example, create index file. By your definition, that’s something you need to do in the program, right? So, why not make a function called createIndexFile? And then, whatever that entails, maybe make functions for all those. But don’t go too far too early. Just make the function and write some plain english in comments, then deal with details when you get to it.

I don’t know anything about testing :smile:. The tests I write are not formal or anything, I just print things for the console and compare the result to what I was expecting. If I get a result I didn’t expect, I use the console for debugging, too. May be slow in comparison to using unit testing or whatever, but it’s very effective.

Hope this helps.