Journal Sanity's Journal: An alternative to syntax extensions 9
value=map["key"]
In Java, you must use:
value=(ObjectType) map.get("key");
Java's syntax is obviously more verbose, but Java advocates defend this verbosity on the basis that a language's syntax should be as simple as possible, and the notion of extending the syntax to support a particular (albeit popular) type of datastructure is anathema.
This conservative attitude is understandable when one looks at a language like C++, which in many ways gleefully encourage the programmer to muck around with syntax, the result being that one practically needs to learn to interpret a new programming language every time they try to decipher a new developer's C++ code.
So, what hope for reducing Java's verbosity without falling into the C++ trap? Salvation may come from an unlikely source, the IDE. The notion that a developer might wish to have a more concise way to express and view common code structures and expressions is understandable, the difficulty comes when they must impose their syntactic preferences on others.
The solution? What if an IDE allowed a developer to define syntactic shortcuts which they could use, and which would be used in the code they are viewing, but which would automatically be converted to "vanilla" Java before being saved to disk.
This would afford most, if not all of the benefits of a more consise syntax, without the disadvantage of having to endure the ill-judged syntactic conventions of others.
Thoughts?
What you describe... (Score:2)
Is this not akin to the #define preprocessor command in C (and perhaps the typedef keyword too)?
Regardless, such a mechanism needs to be a language itself.
Re:What you describe... (Score:2)
Re:What you describe... (Score:2)
I was looking at your example with maps when I originally replied.
Of course, now looking at the article again, that suggestion of mine goes against the principles of OOP.
But the other -- that syntax extensions should reduce to some kind
*How* interoperable? (Score:2)
An algorithm could obviously be devised to map many of their changes back to your syntax, but then you'd be changing the source without knowing it the next time you posted.
If it's ok that your special syntax would disappear the second that someone else touched it, then you wouldn't wan
Re:*How* interoperable? (Score:2)
Re:*How* interoperable? (Score:2)
If you're talking about something as involved as Eclipse's incremental compilation, then yes, remapping someone else's code to your syntax style would absolutely be possible. It wouldn't work in all cases, and when it did work, it would change the source without you knowing it. At best, it'd be as good as a really good forms
Re:*How* interoperable? (Score:2)