Python Forum
Calculating surface area - - OOP or functional? Derek Banas Udemy course
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculating surface area - - OOP or functional? Derek Banas Udemy course
#3
Depends on what you're optimizing for. If you have one task that will never be repeated or extended, and it's not huge, then creating a complex class isn't very useful. The code you've shown appears to be written as an example to show the basics of OOP, not to solve a particular problem.

As the task grows larger, with more components (and especially more authors), the benefits of cleaner separation between the parts of the code become greater and OOP practices can help with that.

That being said, the code looks horrible to me as an example of python OOP. It's using both regular and hidden attributes. Yes, they're possible to do, but I wouldn't recommend a python class to look like that, especially as an example for someone looking to learn it.

Your script is relatively fine for a quick script, but my concerns would be:
  • You're performing input both inside and outside the function. I'd rather do it in one place.
  • You're handling errors by recursion rather than a simple loop. Unlikely to be a huge problem, but not a good habit. Recursion has memory and depth limits that are smaller than some other cases. Don't invoke it arbitrarily. This case could be replaced with a loop and remove the recursion.
  • Minor (and done in the example as well), but you're truncating inputs to int(). I see no reason to do so. This could handle float() input just as easily.

To "optimize" or "improve" it requires some metric to optimize against. Do you want it to be able to run faster? Have more understandable code? Be able to use as an example of OOP programming?
Reply


Messages In This Thread
RE: Calculated surface area - - OOP or functional? Derek Banas Udemy course - by bowlofred - Mar-12-2021, 11:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  functional LEDs in an array or list? // RPi user Doczu 5 1,636 Aug-23-2022, 05:37 PM
Last Post: Yoriz
  Stuck in functional proggaming haze hammer 2 1,414 Oct-27-2021, 02:07 PM
Last Post: hammer
  OOP vs functional - - elaborate turn based RPG game (Derek Banas Udemy course again) Drone4four 6 3,958 Mar-14-2021, 08:38 AM
Last Post: ndc85430
  3d Surface where Z is not a function of X and Y richterjan 2 1,740 Nov-11-2020, 04:22 PM
Last Post: michael1789
  Plotting 3D surface plot for non-linear multivariate regression with 5 variables khwajaosama 0 2,717 Jul-02-2020, 04:50 AM
Last Post: khwajaosama
  matplotlib recursion error when repeatedly displaying a surface AdeIsHere 0 1,941 Sep-19-2019, 04:36 PM
Last Post: AdeIsHere
  Learning functional programming vndywarhol 2 2,485 Aug-15-2018, 02:17 AM
Last Post: micseydel
  Projected Surface in 2D [Difficult topic] Hans_K 6 3,870 Aug-02-2017, 09:16 AM
Last Post: Hans_K

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020