Favorite Language Features

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

*crosses figures in hopes that this doesn't not turn into a debate blood bath..* Before we start I'll try to be clear on what this thread is NOT about: 1) This is not a language A vs B debate. 2) This is not a feature A vs feature B debate. 3) This is not a debate. I want this thread to be an open discussion about what features people appreciate in the languages they use, why, and for what programming purpose. Obviously the features that help you the most will differ depending on your programming goals. If you are making a quick 3 week single platform project with little math, or a complex cross-platform project with 3D graphics, you will likely have different needs and preferences. So, please specifically state your purpose first for what you use these features for. When I am programming complex OO projects where performance isn't absolutely critical and the math is simpler than the security concerns, I appreciate: In PHP5 I appreciate the ability to create associative arrays with ease, and the ability to pass them as return values. In C# and C++ I appreciate generics or C++ templates for the reduction of code duplication. I also appreciate when I can be specific about what kinds of types type "T" can be within a template or generic. I like the idea of an Interface in Java, C#, and PHP5 that only contains abstract functions. This is because I appreciate its specificity in meaning when I am mixing inheritance with objection composition. I like the ability to apply RAII in C++ as a means of deterministically closing resources when I am done with them. I find this method useful for resources such as file handles, databases, graphics card resources, and some implementations of state machines. I like the C++ ability to restrict and define what kinds of types can be sent to a function. In large projects this helps eliminate many possible headaches. I appreciate the ability to mix procedural, object oriented, and functional programming methods in C++ using its STL and Boost. I find that mixing these methods allows me to solve a greater spectrum of problems in ways that suit them. I like the ability to use weak pointers and shared pointers in C++ with Boost, as I have found a few cases where the idea of a weak pointer is a very elegant solution.

Share on other sites
In C++, I like the expressive power of templates, and how they can greatly reduce code duplication, in making powerful generic constructs.

In Ocaml, I like the safety of the language (many complains that "3.5 + 3" will raise a compiler error, but I love it!), and I like the terseness and power of the functional constructs (List.fold_left is my personal favorite!). The top-level for immediate evaluation is also a killer feature, I wish C++ had something similar when I have a doubt on how a piece of code will behave!

Share on other sites
When working with trees I enjoy destructive pattern matching on algebraic data types and recursion.
fun rewrite(p) =  case cond of    Not(Not(p)) => rewrite(p)  | Not(And(p, q)) => Or(rewrite(Not(p)), rewrite(Not(q)))  | ...// Compare:Condition rewrite(Condition p) {  boolean done = false;  while(!done) {    if(cond isinstanceof Not) {      Condition innerCond = ((Not) cond).getArgument();      if(innerCond isinstanceof Not) {        // I can't even be bothered to write the rest of this      } else if(innerCond isinstanceof And) {        // Or this      }    ...  }}

It's not a completely fair comparison, but I think the first version speaks for itself even in the absence of the imperative example.

[Edited by - Ahnfelt on December 1, 2007 4:39:56 PM]

Share on other sites
I also like the separation of "reference" and "may be null" in types. About a third of the errors I get when I'm programming in Java is the NullPointerException. The stack trace is often useless because it didn't get dereferenced before much later in the code than where the unwanted null actually came from. I could sprinkle the code with assert statements to fail fast, but that's it - the type system won't help me at all.

Most functional language has an "optional" type that may or may not contain a value, separate from the "reference" type, which is something completely different. I wonder why this isn't yet the standard in imperative languages.

(I don't mean to sound like I hate imperative languages - I use these much more than I use functional languages, but I just miss some features)

Share on other sites
Partial function application and first-class functions are something I miss greatly when I return to a language without them.

Share on other sites
Features I like in Python:

- List Comprehension syntax sugar

- Meta classes

- Automatic "pickling" of any type

- No "unsafe" behaviour

Features I like in C++:

- namespaces, no need for a common prefix of all your functions like you did in C

- goto, can be easily abused, but when used right can make code simple and fast

- The const keyword, to encourage the use of immutable variables

- The CPP preprocessor, although it is ancient technology and can be abused, can sometimes be a life saver

- List Comprehension (inspired the Python feature)

- Everything is calculated with lazy evaluation

- Type classes, for specifying common properties of types

- "do" notation for monads and arrows, a nice syntax sugar

- Foreign Function Interface makes it easy to call any C function

- First Class functions

- Generic Algebraic Data Types, for complex embedded languages

- Type inference, cuts down on code size

- Software Transactional Memory, for safe and fast communication between concurrent threads

- Pattern matching

Share on other sites
Haskell - I love the type inference and hope to soon find the time to build this into my own scripting language. In case you aren't familiar with this concept: Haskell is a statically typed language but you generally don't have to declare types. Instead, the language determines the types from how you use variables, function parameters or return values. It works great and saves a lot of typing.

Erlang - The way this language deals with concurrency is great. It doesn't have shared state which makes locking unnecessary and it's still a pretty useful language. Actors in this language can be sent messages which are then stored in a message queue and processed when the actor is available.

Lisp and other languages - I always loved the concept of languages not having keywords. In the C family of languages, you have certain primitives like operators, for-loops, exceptions, etc. In languages like Lisp (and also for example Smalltalk) you don't have any of that. Instead, you can define all of those yourself. In the purest form, Lisp doesn't even have numeric literals. It's not so much about wanting to control everything, it's more about having a language that is so self-sufficient, it can literally define itself.

Assembly - I know it sounds silly, but there's a part of me that simply loves having the ability to fine-tune everything. It generally doesn't make a lot of sense nowadays to write stuff in assembly, but I still do it from time to time just for the fun of it.

Self - Self is an object oriented language that doesn't have classes. Instead it has objects and prototypes (javascript borrowed that concept) which is an entirely different way of looking at OOP. Also, Self brought JIT-compilers to the level they're at today. A lot of people working on Self-JIT-compilers now work on the Java hotspot VM. They mastered the idea of dynamic-recompilation where individual bits of code are optimized at runtime often producing better performance than static optimizing compilers.

C# - At first I thought C# was "just another Java". However, Anders Hejlsberg and the other folks working on the language are gradually merging two worlds with the newer releases of C#. C# is still an inherently imperative language, but it borrows quite a few concepts from the functional world (lambdas and with LINQ now monads).

C++ - There are a lot of things I like about C++, things like templates or its implementing classes while staying true to its sort of low-level roots.

Share on other sites
-Unicode by default is great.
-Language concept of threads is useful.
-Duck typing when I want it is great.
-Non-duck typing when I want it is great.
-Functions as params is great, now if imperative languages can stop sucking at it.
-Not a language feature per se but garbage collection/automatic memory management rocks.
-.NET style common runtime is good. (ease of interlanguage operation)
-Parameterizing on type (where types exist) is useful.
-Reflection can be useful, and I suspect will become more useful once done better.

Share on other sites

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628682
• Total Posts
2984197

• 13
• 12
• 9
• 10
• 10