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

As someone who's worked heavily in C++/Java and tends toward functional programming approaches I enjoy PHP. There are some features in the language you should avoid, variable-variables being one of the ones that makes logic very difficult to decipher - but C, C++ and Java all have those - and Javascript has the wonderful combination of substr & substring. The useful portions of PHP are extremely powerful, having access to magic functions, a much more advanced concept of a local symbol table and a surprisingly good approach to inheritance & composition all end up bringing down code maintenance when well applied to provide clearly intentioned logic.


Going a bit off-topic, but I can't imagine doing "functional" programming in PHP or Java. C++ has const and top-level functions (PHP kind of does, but the autoloader...). It has (real) generics. It has move semantics, which is great for functional pipelines.


I do functional programming in C# and used to do it in Java at university. C# makes it marginally more pleasant but in general it’s pretty feasible, people will just look at you funny.


Just to tease it out more. What do you mean by functional? I assume that you design your classes to be immutable (only getters with defensive copies when needed). Do you also keep most business logic as pure, static methods on non-data-holding classes?

That's about as far as you can go with Java, I guess, but honestly, now that I type that out, I guess that does get you pretty far...


Yes, classes are just POCOs (sometimes with some sealed subclasses, to hack sum types) and business logic is static functions in separate classes. Like I said, C# makes this somewhat easier, with things like readonly fields, get-only auto-properties, System.Collections.Immutable, readonly structs, pattern matching, etc. With Java you have to take more care to encapsulate things properly, though I’m excited for records coming into the language.

The most salient problem is the fact that the languages do not distinguish between references and values (aka “mutability by default”) which means that the compiler will not maintain those invariants for you unless you annotate things specifically, and the authors of the libraries you use do the same.

My overall preference is for F#, which is ironically a better object oriented language than C#, by virtue of using ML-like syntax instead of C-like. Nonetheless, C# is a passable functional programming language these days, and the language designers keep adding more functional-inspired features with every release.




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

Search: