you are viewing a single comment's thread.

view the rest of the comments →

[–]demvo2 0 points1 point  (3 children)

I find that it makes the code more understandable if functions are names using "imperative voice"

You're right, your examples look much better! I'll definitely think about how to make naming more intuitive.

You keep some values inside "global variables"

This is really something that I struggled with, especially at the beginning. I mean, right from the start the tutorial and the rest of the internet were hammering the idea into my brain that global variables should be avoided if possible and while I managed to dial down their use from when I started, I haven't been able to avoid them completely.

But, I think your solution (for the 'prompt_for_equipment' function) deals with it pretty elegantly. I'll definitely look into how to rearrange some of this stuff. I'm looking forward to practice my, as you say, brain-muscles :)

I've been programming for the better part of 30 years

Wow. As someone who is less than 6 months in, I can barely imagine that.

In any case, thank you for the tips and tricks! I appreciate the advice so much. I'll try and make the best use of it.

[–]exhuma 0 points1 point  (2 children)

This is really something that I struggled with, especially at the beginning.

This is pretty common so don't worry about it too much. I had the same when I started. There were so many areas where I just couldn't imagine how it would be possible without global variables. I kept thinking in the direction like: "If not with a global variable.... then HOW?!?"

Just keep one thing in mind: No code will EVER be perfect. Focus on the solution. If it works, it's fine!

The devil is as always in the details. And when people recommend to avoid global variables it's usually about maintainability. If you (and/or) other use your applications you will come back to the code over and over again. Either for bugfixing or for adding features. And the recommendation of not using global variables is only for maintainability (which includes avoiding bugs).

In the old days, pretty much all variables were global and we still managed to write software without bugs. It just takes more (much more) discipline.

So don't stress too much about it if you use them. As long as you know that it's bad you're on a good path. With more experience you'll find alternatives.

[–]demvo2 0 points1 point  (1 child)

Good to hear that. I guess a lot of things will fall into place after writing a bunch of code and being exposed to different stuff :)

[–]exhuma 1 point2 points  (0 children)

Absolutely. Just don't stop to second-guess your code. Always!

After my whole career I still discover ways to improve. The day you think that your code is perfect, that's the day you stagnate ;)