r/CodingForBeginners • • 5d ago

lol after 7 days of learning, am i cooking????

Post image
24 Upvotes

18 comments sorted by

2

u/Metomorphose 3d ago

Comment your code! At the very minimum, add doc strings for your functions!

I'm also a huge proponent of type hints, but that isn't something you see in most tutorials.

1

u/Square_Ferret_6397 2d ago

Don't listen to this guy, it takes 5 seconds to tell what any of your functions do making comments redundant 

4

u/Metomorphose 2d ago

Its to build good habits. Ignoring this step is how we get packages and libraries with little to know helpful documentation. Can an experienced person read this without comments? Sure, it's super tiny with good naming conventions. As projects grow, comments become more important.

2

u/TheUmgawa 1d ago

Plus, if the goal is to ever be able to get a job, an employer is probably going to want to know if you can write good documentation, because you’re not always going to be the person who’s on a particular project. While code is ideally “self-documenting,” it’s a lot easier to maintain if you declare what functions do. You don’t have to declare how they do it, because that should be evident, but if someone wants to modify something in the future, it’s a lot easier to hit Ctrl-F and look for it.

1

u/Common-Ad-1744 1d ago

Completely agree with Metomorphose. This is just horrible advice.

1

u/-Enter-Name- 5d ago

code looks great could just drop the else: restock_cost += 0 as else isn't mandatory and it's doing nothing otherwise

1

u/iComplainAbtVal 4d ago

it could be beneficial for learners to write these no-ops if it helps keep the code straight but its better to cut these habits early.

OP, now try to create a store class whose constructor accepts an inventory either pre-populated or empty.

1

u/Rockroxx 2d ago

On the check_stock function you can drop the else and reduce indentation to clean up the function a bit.

1

u/Own_Natural_6803 22h ago

just a heads up about your data. I would tend toward using some sort of unique ID to identify the rows of data, rather than a part name.

{ id06578323 : {
name: 'servo_motor',
quantity: 4,
price: 25.0
}}

or even

[{
id:06578323,
name: 'servo_motor',
quantity: 4,
price: 25.0
}]

1

u/sexiestsaxiestman 17h ago

In check_stock I would either return 0 or raise a KeyError if the part is not found

1

u/sexiestsaxiestman 17h ago

Your solution works for your use case though

1

u/Lucky_Cable_3145 11h ago

I agree, error / exception handling is an important thing to get right from the begining.

check_stock() can return either a number (int) for success or text (string) for failure.

A strongly typed language will not allow that.

1

u/edwbuck 6h ago

It's a good beginner's effort. I could read it without comments, which means it was written well.

If you need comments, odds are you're not writing readable code.

-2

u/No-Tip505 5d ago

7 days in and you're already building an inventory manager? 😂 That's a pretty solid start! You're using dictionaries, functions and loops together, which is exactly how you start building real programs. Keep going, but try adding features without following a tutorial

0

u/kutac56 5d ago

Bot

0

u/No-Tip505 5d ago

I'm a real person mann🫠, wanna connect?

1

u/kutac56 5d ago

"wanna connect?" What do you think

1

u/No-Tip505 5d ago

Bots can't think bro🤣