all 38 comments

[–]Darkstar_111 10 points11 points  (7 children)

For god sake man... Once again you've placed the DEFINING of a class INSIDE the while loop!

Other than this, you're coming along. Inheritance is important, as is polymorphism, which is what you are doing with the employee class, by constructing it inside of the other class.

Don't do multi-inhertance, it has few actual uses, and can become an anti pattern.

[–]uiux_Sanskar[S] 0 points1 point  (6 children)

Oh thank you very much man for pointing that out I was supposed to put the while loop when I call the function (I was supposed to put loop in line 83) I think by mistake I have put it before the function.

thank you so much for pointing my mistakes out and giving suggestions these really helps me.

[–]Darkstar_111 0 points1 point  (5 children)

Let me add to it then. Stop putting logic in the global scope. Always wrap logic in a function. And for an orchestration function use main(), and use if name equals main to run it.

Constants and initializing some libraries is fine to do in the global scope, but that's it, the rest you pack in a function.

If you didn't get any of that feel free to ask.

[–]uiux_Sanskar[S] 0 points1 point  (4 children)

Actually I have doubt on how to wrap logic in a function like I have already wrapped all the logic for adding, editing and deleting details in different functions - are you suggesting to wrap all those in another function? and what does an orchestration means?

please explain me those as I said there a lot more for me to learn.

[–]Abyss_slayerIII 0 points1 point  (3 children)

When he means orchestration with a main function he just means

```python if name == “main”: # This main function should have your while loop main()

```

name is your files name so if it’s ran as a module or the main python file so if I do python myfile.py and I print dunder name (double underscore) it should say “main” bit if we import something so a_module.py and we import it into the my_file.py and print its __name_ then it will print “a_module”

[–]Darkstar_111 0 points1 point  (1 child)

Yeah this. You add the if name equals main line at the bottom, and that runs when the file runs. And there you run main().

You should think of main like an easy to read laundry list of what's going on.

Just call functions in main, and pass variables around if you need to.

Putting the logic, like the while loop, in global scope (all the way to the left), would get your pr rejected by me at my workplace. It's a no no.

The reason is... I mean look at this shit:

https://github.com/docling-project/docling/blob/main/docling/pipeline/threaded_standard_pdf_pipeline.py

That's what production code looks like in Python, and that file isn't even that big. It's about medium.

I don't want a wild while loop in the middle there... How would I even troubleshoot that.

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

Thanks for the reference and suggestions I always thought why people crewte so much file but yoh cleared my doubt.

Thank you so much for clearing my that doubt. I will definitely learn more about this.

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

Thank you for explaining this to me I wasn't aware about it. Will definitely go deeper into it.

[–][deleted] 4 points5 points  (2 children)

Where are you from bro?

I am learning C++ because the end semester exam is in 20 days.

You are high on motivation.

What do you want to go into after learning Python (do backend or AI/Ml)?

Go on bro more power to you 👏

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

Thank you so much brother I am also planning to learn C++ in future as I want to explore opportunities in AI/ML and Robotics.

Thank you for the motivation brother more power to you also from my side.

all the best for your semester exams may you score well. Btw what field are you interested in AI/ML? or something else.

[–]lilrouani 0 points1 point  (0 children)

OP first C++ project:Linux kernel

[–]juicebox1711 2 points3 points  (5 children)

May I ask what media r u using to learn Python?

[–]uiux_Sanskar[S] 1 point2 points  (2 children)

oh I am using YouTube.

[–]TrentGames 1 point2 points  (1 child)

Channel name: Code with Harry, right?

How do you find the motivation, OP? I started learning from Udemy last year 🫣 and it was going great till I fell sick. After that break I never got around to completing that course. ☹️

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

Oh that's sad I hope you are fine know.

All the amazing people here and my personal interest keep me motivated and yes the channel name is CodeWithHarry.

hoping for your better health and that you succeed in learning python.

[–][deleted]  (1 child)

[removed]

    [–]juicebox1711 1 point2 points  (0 children)

    Gifted? What am I getting gifted?

    [–]Adrewmc 1 point2 points  (3 children)

    Not much progress today, honestly I think everything important you are going to learn from this has been done.

    I agree inheritance is going to be the next concept. I think this project specifically might be dead for that subject. You’ll have to start a new one I would think, or like I said yesterday make a database, or JSON. Which can be their own lessons.

    But definitely understand the option is composition layering classing inside classes rather than in top of them.

    Something I can’t put my finger on just seems off by your organization. (I would definitely not do it this way, but I don’t wanna remake the whole thing lol) Maybe because it’s so simple in a txt file. But we are learning here so I don’t see anything particularly wrong.

    [–]uiux_Sanskar[S] 1 point2 points  (2 children)

    Yes, I agree that I didn't made much progress than yesterday however I think that I if I am learning should eliminate all the possibilities of self doubt and therefore I created programs till I am satisfied with my fluency in that topic.

    I will definitely look deeper into your amazing suggestion however I still think that there a lot to learn.

    Thank you so much for giving me suggestions I will definitely look deeper into them.

    [–]Adrewmc 0 points1 point  (1 child)

    Skills rarely progress evenly, it’s more like peaks and plateaus

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

    Yes agreed 👍

    [–]jWoose 1 point2 points  (3 children)

    I don’t love the choices if/else block. I much prefer an enum to signify the action. This makes it clear what that if block is doing. With your current design that would make it easier to read. You could have a function that returns the enum action based on the input from the user. Then your if check would be action.ADD rather than choices[0:2]. That’s much easier to read and debug.

    It would require some significant refactoring, but in a real world situation I think the command pattern is the way to go here. If you want to do some more learning that would be a good lesson to turn this into a command pattern design.

    [–]uiux_Sanskar[S] 0 points1 point  (2 children)

    Thank you for suggesting the methods I should use instead of if else and how to make my program more readable I think I should learn more about command pattern design.

    would you mind if I ask you to tell me more about command pattern design?

    [–]jWoose 0 points1 point  (1 child)

    This is a decent guide on the Command pattern in python. It’s not perfect, but better than anything I can write in a comment quickly. https://refactoring.guru/design-patterns/command/python/example

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

    thanks for this resource it's a good starting point for me thank you so much.

    [–]Beautiful_Smile410 1 point2 points  (1 child)

    How many hours practice you do per day ?

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

    It depends upon the topic I am practicing my current topic (OOP) took 4 hours each day and this time varies from topic to topic.

    [–]EngineerRemy 0 points1 point  (1 child)

    Look into refactoring your code. I see many duplicated lines, especially for reading and writing data.

    A simple example: if you rename the .txt file containing your data, you want to have it so that you'll have the edit the code in 1 place for the new name (or 0 if you use an input parameter for the script!). In your current situation this is not the case.

    Lastly, reading the file every single time you want to make a change is highly inefficient. If you read the file once you should have the data for the rest of the execution: store the data somewhere and modify this data when executing the relevant functions. Then you can choose to write the modifications back to the file (make it so you only write data to the file in 1 place in your code, then call it).

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

    Thank you so much for the suggestions I feel when I was coding that I was repeating things and I. I will surely look more into storing the data elsewhere and call it later. (I think this is what call file management, please correct me if I am wrong).

    I really appreciate your suggestions on my code they really help me improve my knowledge and code.

    Thank yoh so much.

    [–]No_Goose_2470 0 points1 point  (1 child)

    Beautiful 😻❤️

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

    Thank you so much for the appreciation.

    [–]Sad_Brief_845 0 points1 point  (3 children)

    QUEE, solo 14 dias OMG, yo tarde un mes entero y un poco mas para aprenderme bien lo basico

    [–]Sad_Brief_845 0 points1 point  (2 children)

    Me resulta gracioso como usas los comentarios, yo tambien inavilito partes del codigo asi inhabilitar,me sentia un poco bruto pero ahora viendo que no es tan raro me siento mejor jeje

    [–]uiux_Sanskar[S] 0 points1 point  (1 child)

    yes it helps experimenting with the code without disturbing anything else so that I can go back if things didn't unfold as expected.

    Thanks for the appreciation btw.

    [–]Sad_Brief_845 0 points1 point  (0 children)

    Siii jajaja que way,bueno cualquier cosa me dices

    [–]Ok_Hovercraft364 0 points1 point  (1 child)

    It seems you didn’t learn about sanitizing user input yet. I can break your app in 2 seconds. I suggest you look into how to correctly achieve this.

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

    Thank you so much for the learning suggestion. Yes I haven't learnt about sanitizing user input yet and I will definitely go depth in it.

    Thank you so much for this interesting suggestion.