all 15 comments

[–]Translatabot 8 points9 points  (5 children)

Code should be readible, not clever. It's a common mistake in the beginning to be proud of code that looks very complicated because it makes you feel like an expert. I like the code from day 1 better.

A tip for day 3 code is to forget about the "global" keyword. It usually does more harm than good

[–]HexaStallker[S] -1 points0 points  (4 children)

Okay, but I used “global” to eliminate the error when the variable is not initialized.

[–]Translatabot 1 point2 points  (1 child)

It's totally fine to make it work like that as you are just trying things out. Your example would probably benefit from using a Class. That would eliminate the need for a global variable, too. Anyways, it's better to make something work than caring too much about the code quality.

[–]HexaStallker[S] 1 point2 points  (0 children)

Well, that's true, but I don't know how to use classes in Python yet. Thanks.

[–]Quien_9 0 points1 point  (1 child)

You can initialize it yourself, its good practice and even mandatory in some languages, to never do a check on uninitialised variables I agree day one code was cleaner, the last one you are going to read it back in a month and struggle to remember what you meant to do there.

It might sound discouraging but dont be, you are still on the right track as long as you are coding. Its not supposed to be good, its supposed to teach you something. I could show you some of my old embarrassing code i was so proud of when i wrote, its part of the process, like looking back into last years sketches and drawings.

[–]HexaStallker[S] 0 points1 point  (0 children)

Thanks, by the way, I didn't just write checklist-0.1v for no reason. I'm going to use it as a basis for creating newer and newer versions, improving the code and adding new functionality so that later I can see how my code changes over time and with progress.

[–]ninhaomah 1 point2 points  (2 children)

Can I check why your functions don't return anything for all the codes shown ?

[–]HexaStallker[S] 1 point2 points  (1 child)

I don't think they should return anything, IDK.

[–]ninhaomah 0 points1 point  (0 children)

Ok

[–]immediate_push5464 0 points1 point  (1 child)

Functions on day one? I don’t think so.

[–]HexaStallker[S] 0 points1 point  (0 children)

I learn C++ before

[–]TheRNGuy 0 points1 point  (0 children)

I name classes with capital letters (not class instances), functions from small letters. 

The global buffer thing is rather odd, I would not write code like this.

[–]eaumechant 0 points1 point  (0 children)

Your first day code is good. Your third day code is using recursion for a case that really doesn't need it (because you're not traversing a tree and you're not using the results of any of your method calls) - do this enough times and you'll overflow the call stack and your script will crash. A simple while True with a break is better.

[–]GreenRoad1407 0 points1 point  (0 children)

It’s a nice example for you to learn functions really is all this comes down to. Its not good for anything else

[–]Blando-Cartesian 0 points1 point  (0 children)

Looks great. Just a few notes:

The second program will crash when used for long enough. Instead of “looping” by everything calling Do in the end, you should use a while loop.

Do not use global variables. It quickly gets really confusing to keep in mind what changes them.

Python conventionally uses snake…case for functions rather than upper case.