Python Forum
writing a class or a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
writing a class or a function
#10
(Dec-28-2018, 08:00 PM)nilamo Wrote: There are no cases where classes are required.

Python is a great example, being written in C, which itself doesn't support classes. It then follows, that anything in python is also possible in C, and that anything you could accomplish with a class, you could also accomplish without one.

So no, there are no cases where a class is essential over a function.

but, or course, doing this could mak you Python code as ugly as the frequent mangled messes that often happen with C.

(Dec-28-2018, 08:00 PM)nilamo Wrote: That said, they were created for a reason, and that reason is state management. If you have state you're keeping track of, classes help encapsulate that state, as well as grouping related functions together to strongly indicate to other readers that the functions are, in fact, related to one another.
state can be encapsulated many ways. a class is not needed just for that. but when using a class, that code can gain benefits like duplication of that state.

is the "grouping related functions together" aspect being done by the functions being methods and being coded as attributes of the class so that the reader of the code sees the common usage of the class name? can't longer names do that, too, such as scaled_sin() and scaled_sqrt()

i'm just trying to pin down what all a class brings to the table.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
writing a class or a function - by Skaperen - Dec-28-2018, 06:59 AM
RE: writing a class or a function - by Gribouillis - Dec-28-2018, 07:40 AM
RE: writing a class or a function - by Larz60+ - Dec-28-2018, 10:21 AM
RE: writing a class or a function - by ichabod801 - Dec-28-2018, 03:04 PM
RE: writing a class or a function - by Skaperen - Dec-28-2018, 07:18 PM
RE: writing a class or a function - by nilamo - Dec-28-2018, 08:00 PM
RE: writing a class or a function - by Skaperen - Dec-30-2018, 04:30 AM
RE: writing a class or a function - by ichabod801 - Dec-28-2018, 08:56 PM
RE: writing a class or a function - by Gribouillis - Dec-28-2018, 09:01 PM
RE: writing a class or a function - by Larz60+ - Dec-29-2018, 12:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extracting a function/class/method from code Skaperen 5 2,285 Mar-30-2022, 12:13 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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