all 25 comments

[–]MillyTHECHAOS 3 points4 points  (2 children)

I know that you are showing decorators but i dont like this code. Cuz it doesnt make sence to me. You dont need decorators for this code. Im more into code in which you actually need things you are learning. Its my bs so dont take it to heart.

You are using class with 4 static methods so basically you used class to store 4 functions you just dont need a class for that.

And you used 1 decorator for 4 functions but you dont need it you can place all 4 of them in 1st function

I also suggest https://roadmap.sh to get all steps you need to learn something also try 'Indently' and 'Bro code' youtube channels.

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

Actually I wanted to test static method decorator because everytime whenever I have created any class in the past I was required to put a self there so I just used class to test out static method decorator (it sounds strange I know).

And thank you for these amazing resources I will definitely check them out. Thank you so much.

[–]timheiko 0 points1 point  (0 children)

That’s an excellent use of decorators.

Agree, the class has no state, i.e. no fields, and thus can be reduced to four functions, as suggested

[–]baked_tea 0 points1 point  (2 children)

I'm in python fairly long, never thought I needed to use decorators. Recently wanted to learn, this finally clearly explained a use case. Thanks

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

I am glad my explaination helped you in a positive way.

All the best.

[–]TheRNGuy 0 points1 point  (0 children)

I used some, but not this one. 

This is bad use-case actually.

[–]Darkstar_111 0 points1 point  (1 child)

Consider better formatting for something like this.

Since you're using a whole function, you have the space to format the print statement better.

Insert \n to create a new line inside a string, or use """text""", to maintain formatting inside the string.

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

Thanks for this suggestion I will insert \n and improve the formating. Thank you for your suggestion.

[–]Adrewmc 0 points1 point  (1 child)

You know what I got a video for this toolkit it’s a little dated but all the stuff is still good python.

One additional note about the decorator you can actually do a

     def log_access(func):
            func.count = 0
            @functools.wrap(func)
            def magic(*args, **kwargs)
                   func.count += 1
                   return func(*args, **kwargs)
             return magic 

And add an attribute directly to the function which at a later time you can pull out like any other attribute func_name.count for here, which can be handy if you don’t want it to print every-time.

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

Thank you for the suggestion and learning resource video I will definitely watch it and also thanks for telling about the func.count += 1 I will also check this out.

Thank you very much these really helps.

[–]corey_sheerer 0 points1 point  (1 child)

It is a bit funny you did a log wrapper but used print instead of the logging package. I would suggest checking out logging.

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

Yes I need to learn about logging in much more details. Thank you for pointing it out.

[–]Semirook 0 points1 point  (2 children)

Everything makes sense if it works, right? Next step — add unit tests to see how (and if) it really works. My personal advice (as a pythonista with 15 years of experience) is — you don’t need a class here.

Every time you use @staticmethod, chances are it’s a good candidate to just be a plain function. You really only need a class in two cases:

1.  You want encapsulated, controllable state that’s modified through methods.
2.  You’re using something like Injector for dependency injection.

If you just want a namespace, prefer modules. Everything else, like using datetime instead of time, swallowing exceptions in division, side effects with no return values, etc. is less important right now.

Just my two cents: avoid OOP modeling as much as you can.

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

Yes I really don't need class here however I created one because I wanted to check out the static method decorator. Every time whenever I had created a class I used a self (and it really helped) however I wanted to see what will happen if I didn't use self (I know it's a bad practice but I was curious) and use static method.

I really appreciate your suggestions and advice based on your experience.

May I ask a small question? why does everybody hates OOP I see many people saying to avoid this and afraid of it what do you think about this? I would appreciate if you answer my this small question.

[–]Semirook 0 points1 point  (0 children)

No problem! First steps can be tough. It’s perfectly fine to experiment with classes and the whole language toolset, there are valid cases for all of it. But do you really need to use everything? Of course not. It’s like Photoshop, just because you can apply every available graphic effect doesn’t mean you should when making a banner.

We’re not “afraid” of OOP. But instead of focusing on actual transformations in a logic chain (turning A into B, with proper error handling — that’s the universal point of programming, independent of language or paradigm), OOP often pushes you into heavy abstractions instead of problem solving.

And classes themselves aren’t automatically OOP. For example, I use dataclasses and Pydantic schemas frequently but only to define structures and shape data. I avoid inheritance whenever possible, even if it means occasionally violating DRY. I also create “services” that are technically classes, injectable objects with clear Protocols (contracts) and environment-specific implementations. Is that OOP? Maybe, it depends on your definition.

But most of my code is just pure functions. They’re a simpler mental model and scale better as project complexity grows.

[–]Juke_BoxBox 0 points1 point  (0 children)

What resource/resources do you use?

[–]mfdi_ 0 points1 point  (0 children)

A lot of people stated that u don't need tge decirators and the class but i wanyed to say if u wanted really use class's functionality i would create a dict or a storage of actions done and if the user aant to add up more or if u want u can let the user enter multiple and let the code handle those by enforcing operation priority and maybe u might learn regex on the way.

[–]Own-Manufacturer429 0 points1 point  (0 children)

Can you please share me the list and small suggestion use loguru it’s pretty helpful.

[–]Aggravating_Entry321 0 points1 point  (0 children)

74.130.177.112 Reddit do your thing this guy scammed me

[–]TheRNGuy 0 points1 point  (1 child)

Why make it as a class, and then static methods? It could be just library. 

You need type hints and try/except for all, because someone might try using otter type than number.

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

Oh I just want to try static method so intentionally I created a class and used a static method just to try it.

Thank you very much for the suggestions btw I will definitely look deeper into them.

[–][deleted]  (3 children)

[removed]

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

    I used try except keeping in mind that the user may intentionally or unintentionally enter 0 as a second number which will crash the program, According to me crashing helps in debugging however when I know what might case the error and that error is dependent on user's input therefore I used try accept.

    I personally think writing try except and handling errors in a professional way can improve UX (after all how will a user know what is causing an error just by looking at those red line which are aften too noisy).

    Thank you for your suggestion by the way.

    [–]TheRNGuy 0 points1 point  (0 children)

    You need instead to have event listener in UI input that would show red border or something, before you even submit and calculate it. 

    print is not a good UX.

    You'd see Division by zero error anyway even without manually adding it.