News for hackers. Stuff that matters.
Re:The use of `class` for things that should be simple free ... by hamandcheese on Thursday May 28, 2020 @04:19AM (#23334827)
Is there any real harm though? Free functions pollute the global namespace, which is something I tend to avoid (at least in Ruby where everything shares the same namespace).
Re:The use of `class` for things that should be simple free ... by cgrealy on Thursday May 28, 2020 @04:29AM (#23334874)
Just put the function in a namespace?
Re:The use of `class` for things that should be simple free ... by risorect on Thursday May 28, 2020 @04:47AM (#23334976)
In terms of ruby, we may be splitting hairs when it comes to namespaces vs classes. Modules, which are typically used for namespacing, can have state and extend themselves, making them effectively singleton classes.
Re:The use of `class` for things that should be simple free ... by ratww on Thursday May 28, 2020 @06:55AM (#23335851)
> Modules, which are typically used for namespacing, can have state

But there's nothing about state that makes it specific to classes. Namespaces in C++ can hold (static) state, for example. So it's actually the other way around: singleton classes can effectively be namespaces/modules.

Re:The use of `class` for things that should be simple free ... by cessor on Thursday May 28, 2020 @07:10AM (#23335936)
Object without state but with functions is just a namespace. But that depends on how the language implements it.
Re:The use of `class` for things that should be simple free ... by hamandcheese on Thursday May 28, 2020 @09:54PM (#23345492)
In Ruby that looks a lot like what the article says is an anti-pattern.
Re:The use of `class` for things that should be simple free ... by ClikeX on Thursday May 28, 2020 @04:47AM (#23334972)
In Ruby, that basically comes down to creating a static class.
Re:The use of `class` for things that should be simple free ... by cerberusss on Thursday May 28, 2020 @04:20AM (#23334839)
What's the difference between polluting the global namespace with a class name, or with a function name?

I get it, I also experience some reticience when adding free/bare functions in Swift. But maybe it's because of 15 years of OOP programming.

Re:The use of `class` for things that should be simple free ... by mcv on Thursday May 28, 2020 @10:37AM (#23337807)
Maybe the problem here is the global namespace. I really like modern javascript where you have to explicitly import everything.
Re:The use of `class` for things that should be simple free ... by aarong11 on Thursday May 28, 2020 @04:37AM (#23334917)
Maybe not so much of a problem in C++ but look at JavaScript. With the millions of dependencies / libraries you import, if they all used free standing functions you would inevitably end up with collisions.
Re:The use of `class` for things that should be simple free ... by wruza on Thursday May 28, 2020 @04:58AM (#23335029)
In c++ functions can be marked ‘static’ to make them translation-unit local, or you can put them in a library namespace, if they’re public. In a particular js bundler/runtime usually a module system is used (or just iife/umd wrap) which prevents function names from populating globals.
Re:The use of `class` for things that should be simple free ... by entha_saava on Thursday May 28, 2020 @06:38AM (#23335743)
The problem is unqualified imports though, not free functions.