Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What features do you wish were in common languages? [closed]

What features do you wish were in common languages? More precisely, I mean features which generally don't exist at all but would be nice to see, rather than, "I wish dynamic typing was popular."

like image 791
Brian Avatar asked Nov 21 '08 16:11

Brian


2 Answers

I've often thought that "observable" would make a great field modifier (like public, private, static, etc.)

GameState {
   observable int CurrentScore;
}

Then, other classes could declare an observer of that property:

ScoreDisplay {
   observe GameState.CurrentScore(int oldValue, int newValue) {
      ...do stuff...
   }
}

The compiler would wrap all access to the CurrentScore property with notification code, and observers would be notified immediately upon the value's modification.

Sure you can do the same thing in most programming languages with event listeners and property change handlers, but it's a huge pain in the ass and requires a lot of piecemeal plumbing, especially if you're not the author of the class whose values you want to observe. In which case, you usually have to write a wrapper subclass, delegating all operations to the original object and sending change events from mutator methods. Why can't the compiler generate all that dumb boilerplate code?

like image 163
benjismith Avatar answered Oct 04 '22 18:10

benjismith


I guess the most obvious answer is Lisp-like macros. Being able to process your code with your code is wonderfully "meta" and allows some pretty impressive features to be developed from (almost) scratch.

A close second is double or multiple-dispatch in languages like C++. I would love it if polymorphism could extend to the parameters of a virtual function.

like image 23
Joris Timmermans Avatar answered Oct 04 '22 16:10

Joris Timmermans