Discussion
Loading...

#Tag

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Paolo Amoroso boosted
The Last Psion | Alex
The Last Psion | Alex
@thelastpsion@oldbytes.space  ·  activity timestamp 4 days ago

I've been musing on #OOP style. I have a question for the more experienced programmers out there.

How do you decide when a class's method doesn't actually need to be a method, but instead could just be a regular function?

I'm not talking about functions that need to be shared between classes. I'm talking about intentionally moving a method outside of a class, even though it will only ever be used by that class.

For example, if I've got a parser-related function that is only needed by the parser, I will normally just put it in the parser class as a method. It keeps things neat, I can make it private and lock down the class. But I've never before stopped to think whether this is the correct thing to do every time.

After all, #Pascal (my language of choice) has the concept of units. I could just have some functions just as functions, and only have methods for things that directly need to update the class's properties.

It would make things easier for testing, too. I wouldn't need to create an instance of a class just to test a specific function works as intended.

But I don't know if it's the "right" way to do things in OO, or #ObjectPascal for that matter.

#OO

  • Copy link
  • Flag this post
  • Block
The Last Psion | Alex
The Last Psion | Alex
@thelastpsion@oldbytes.space  ·  activity timestamp 4 days ago

I've been musing on #OOP style. I have a question for the more experienced programmers out there.

How do you decide when a class's method doesn't actually need to be a method, but instead could just be a regular function?

I'm not talking about functions that need to be shared between classes. I'm talking about intentionally moving a method outside of a class, even though it will only ever be used by that class.

For example, if I've got a parser-related function that is only needed by the parser, I will normally just put it in the parser class as a method. It keeps things neat, I can make it private and lock down the class. But I've never before stopped to think whether this is the correct thing to do every time.

After all, #Pascal (my language of choice) has the concept of units. I could just have some functions just as functions, and only have methods for things that directly need to update the class's properties.

It would make things easier for testing, too. I wouldn't need to create an instance of a class just to test a specific function works as intended.

But I don't know if it's the "right" way to do things in OO, or #ObjectPascal for that matter.

#OO

  • Copy link
  • Flag this post
  • Block
amen zwa, esq.
amen zwa, esq.
@AmenZwa@mathstodon.xyz  ·  activity timestamp 2 months ago

Why I adore 6502 #assembly:
• Simplicity of 8-bit
• Honesty of early CPU design
• Powerful addressing modes
• Pervasiveness—Apple ][, C64, Beeb

Why I adore C #PP:
• Hardware proximity
• Succinctness
• Pointers
• \(\texttt{struct}\) product type and \(\texttt{union}\) sum type

Why I adore Smalltalk #OO:
• Purity without sacrificing simplicity
• Classes are objects, too
• Simple syntax that fits on a postcard
• Strong, dynamic type system

Why I adore ML #FP:
• Hindley-Milner simple, inferencing type system
• Strict (eager) evaluation
• Modules and functors
• Modern-FP matriarch

  • Copy link
  • Flag this post
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct