Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>And then C# has some questionable features (extension methods: methods for a class but that are not part of the class code).

I dont think people share this opinion.

Extension methods are very handy and powerful while being simple and you can see how similar vision works well in Rust: impl trait for type

It allows e.g library makers to create strong small core and users/community to create their wrappers/integrations easily



Extension methods are "I want a function whose first parameter is this type defined outside, but the programming language shoehornes me so much into classes and objects that I have to do all this extra ~bullshit~ boilerplate to have a function whose first parameter is this type defined outside".

Imagine having to create a monad, including the `pure` and `bind` operations every time you want to increment a variable. That would be bullshit, well, because it's bullshit. Even the haskell guys figured out it's bullshit and implemented types and operations (IORef) to simplify it.

C# hasn't figured out yet you should not have to wrap your function in a namespace and a class.


Weird definition since it misses the point.

Extension methods are: I want to add a new method(not function) to object which I dont have control of (in the code sense)

So I can call "externalObj.MyNewMethod()", so extend its behaviour


Yep, a weird definition.

"I want to add a new not-a-method (because it can't access private stuff, unlike real methods) so that I can do "externalObj.MyNewMethod()" because doing "myNewOperation(externalObj)" is somehow forbidden."


Of course it cannot access internals because youd break "sane oop"




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: