3 ms·
Most modern codebases in Node and Python are devoid of OO—at least in the ones I’ve worked on over the last half-decade. Go is mainstream now too, and it doesn’
by rednafi 2y ago
Most modern codebases in Node and Python are devoid of OO—at least in the ones I’ve worked on over the last half-decade. Go is mainstream now too, and it doesn’t even allow writing OO code.
People love Python because it’s still one of the easiest languages to start with, as it doesn’t force any particular coding style on you. Underneath, it supports a bastardized version of OO, but it doesn’t care if you just use simple types and pass them around to mostly free-floating, stateless functions. This is how startups write Python anyway.
Add a huge ecosystem of libraries and a fairly well-designed type system, and you’ll appeal to a ton of people—despite being quite sluggish. C# and Java struggle to attract this crowd, which is gradually becoming the majority as the industry ages.
- ngrilly 2y agoI’ve learned programming with OOP in Turbo Pascal, C++ and Java. Switching to a different programming style, more data-oriented, using free-floating functions, in languages such as Python, Go, or more recently Zig, has been liberating. I have inherited a C# code base and I have to say that I’m not super excited about going back to using classes and objects everywhere. It’s really hard for me now to “unsee” the problem with that unnecessary complexity.
- zigzag312 2y agoFor data-oriented style you can use records, tuples and structs. You can import all methods from a static class to use them as free-floating functions. C# started as OO so older codebases are OOP heavy.
- rednafi 2y agoI still like C# more than Java and know that the language now allows you to break out of GoF-style OO. But the issue is, few people actually do, and those who want to aren’t writing C#.
- rednafi 2y agoQuite relatable. Writing a lot of Go and a bit of Rust has changed how I write Python and TypeScript. Most newcomers in startups write Python in a data-oriented manner, but that’s not the case even in new Java or C# codebases I’ve seen. One reason I dislike Kotlin is that, despite being fairly new, Java has infected it with OO, and most Kotlin code looks exactly like Java. The whole point of Kotlin was to escape Java’s OO baggage and appeal to a new generation of coders, but it flopped hard. I guess old habits die hard, and way more Kotlin is written by Java veterans than by the younger devs it was supposed to attract.
- pjmlp 2y agoWhat is happened is that a guest language cannot avoid the platform ways of working. Scala, Clojure do support OOP just as well. Glad to know you don't make use of methods, polymorphism and dynamic dispatch in Go, Python and Typescript.
- ngrilly 2y agoI'm wondering if the solution to my problem could be to start using F#, which seems to encourage a data-oriented style over an object-oriented style, while staying in the same C# and .Net ecosystem. F# has a concept of modules, holding all executable code and data. They elegantly replace C# static classes, and are mapped to static classes in the CLR.
- pjmlp 2y agoModules come from ML linage. https://smlhelp.github.io/book/docs/concepts/modules/ https://smlhelp.github.io/book/docs/concepts/modules/ However they aren't as powerful, because ML modules are the way to do OOP like stuff, via what is called functors. F# as .NET language naturally has other mechanisms for this, hence why it is a basic module concept, more in the linage of Modula-2 modules.
- pjmlp 2y agoIt is impossible, when Python and JavaScript have OOP concepts as integral part of their basic types. Go is also a OOP language, regardless of how people without CS degrees fool themselves it is not one. Not having inheritance one OOP language doesn't not make. By definition they are OOP languages, and anti-OOP folks could do better learning about type systems.
- rednafi 2y agoThis sounds like the pedantry FP folks are infamous for. By definition, Rust is also OO. But I’d rather write Python, Node, Go, or Rust in a bastardized, data-oriented, faux-OO way than deal with GoF-style OO in Java, Kotlin, or C#. Sure, you can write code in a non-OO way in C#, but no one does. Whereas in Python, these days, people default to a data-oriented style. This is just how I like to program. Plenty of folks enjoy OO thinking, and I have nothing against that. But when choosing a workplace, I’m fortunate enough to be able to ask if the codebase is OO-heavy—and politely decline if it is.
- pjmlp 2y agoIndeed, I have ported Weekend Raytracing Project from C++ OOP into Rust OOP, just fine and is available as contributions to mankind on Github. Are you aware Python basic types like numbers and functions are objects with methods and inheritance? num=23 print(num) print(type(num)) print(dir(num)) 23 <class 'int'> ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'as_integer_ratio', 'bit_count', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'is_integer', 'numerator', 'real', 'to_bytes'] How do use them in Python without OOP?