Python Forum
Use of classes or functions discussion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of classes or functions discussion
#11
There are only two answers there, and neither supports using a class where a function will do.

A few recommendations to others using this thread for example code:

Don't overcomplicate code.
Different languages do things in ways that make sense for them, don't force all languages to use the some patterns.
A copy-pastable version of the spirit of this code is
def has_internet():
   return '127.0.0.1' != socket.gethostbyname(socket.gethostname())
Reply
#12
(Oct-12-2016, 11:38 PM)wavic Wrote: This video is quite popular. I think it tells everything

I actually quite dislike that video.  He comes off pretty damn condescending.  Yes you shouldn't write a class when you don't need one which are the examples he shows.  But if you do need one you should use one.

His examples deal with a lot of cases where people write place holders for future potential use cases.  So yes, don't overthink and write a bunch of useless code for the ostensible reason of "future proofing" but nonetheless, if you need encapsulated state with associated methods, you should be writing classes.
Reply
#13
Hey did criticize the the standard libs for not using a Heap class. He's definitely more anti-class than I am, but he's still not really anti-class. And I think this OP is an example that makes his video worth having done.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  discussion: API proposal for a better numpy jimy_byerley 0 1,468 Jul-19-2020, 08:56 PM
Last Post: jimy_byerley
  ok to post functions/classes/modules? Skaperen 2 2,959 Jul-03-2018, 12:22 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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