DEV Community

Discussion on: Sometimes, the elegant implementation is just a function

Collapse
 
joelnet profile image
JavaScript Joel

I find it unfortunate that some languages, ahem Java and C#, don't even offer global functions.

This isn't completely accurate. C# has static classes and static functions that can achieve the same results.

You could even create a static class called Global and then call functions like:

Global.MyFunction()

This would act the same as a global function, it would just be prefixed with a namespace or type.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

I understand this, but I don't understand that reason why it was done. Why not allow functions at the namespace scope instead?

By overloading the functionality of a class it needlessly confuses its purpose.

Collapse
 
joelnet profile image
JavaScript Joel

C# was created at the peak of OOP mania. Other options weren't as popular. It's one of the reasons why I transitioned from C# to JavaScript.