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
#4
(Mar-12-2021, 11:38 PM)bowlofred Wrote: 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.

Thank you. I appreciate your suggestions here.

Quote: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?

With my word choice of 'optimize', I didn't mean tweak to improve run-time performance. I meant make my code more understandable and readable. You've already provided three suggestions in this regard. Thank you for this. I will more carefully use the word 'optimize' in the context of programming especially on this forum but elsewhere too.
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  functional LEDs in an array or list? // RPi user Doczu 5 1,667 Aug-23-2022, 05:37 PM
Last Post: Yoriz
  Stuck in functional proggaming haze hammer 2 1,430 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,985 Mar-14-2021, 08:38 AM
Last Post: ndc85430
  3d Surface where Z is not a function of X and Y richterjan 2 1,766 Nov-11-2020, 04:22 PM
Last Post: michael1789
  Plotting 3D surface plot for non-linear multivariate regression with 5 variables khwajaosama 0 2,726 Jul-02-2020, 04:50 AM
Last Post: khwajaosama
  matplotlib recursion error when repeatedly displaying a surface AdeIsHere 0 1,952 Sep-19-2019, 04:36 PM
Last Post: AdeIsHere
  Learning functional programming vndywarhol 2 2,493 Aug-15-2018, 02:17 AM
Last Post: micseydel
  Projected Surface in 2D [Difficult topic] Hans_K 6 3,913 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