Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Java

Eccentricity in Programming Languages

3.60/5 (4 votes)
21 Feb 2013CPOL6 min read 20.8K  
Eccentricity in programming languages

Over the years, now almost a decade with bits and bytes (at an abstract level), I have had to come to terms with some (not many) strange programming language constructs in a variety of programming languages. On second thought, not so much the constructs, rather some of the features provided by these languages I found un-intuitive and unnecessary in some ways.

The languages I personally worked with are mainly C/C++, Java, C# and more recently PHP and JavaScript.
On the weight(!) of my experience, I would like to list down the strange phenomena and unintuitiveness I encountered in these languages. 

Let me start with my very favorite C.
And obviously, the first thing that springs to mind is pointers. Could I do away with pointers? No. Pointers are a must when you are dealing with low level programming languages such as C. But the syntax, it might have been better. int *pAddr = &p, *qAddr = &q; -> This as a syntax is damaging, arising a lot of confusions.

Why associate the * with the pointer variable name? Rather, int* pAddr = &p, qAddr=&q would sound a little easier. The variable's data type, in this case, int*, is a data of pointer type.

in C++, they came up with a better solution for pointers with reference concept. Alas, it would have been very helpful if I could declare a reference inside a class and instead of constructor, I could assign the reference at a later time.

For example:

C++
class DeviceContextWrapper
{
.....
public:
DeviceContext& dc;
.......
};

Later, in some place other than the constructor, I could assign as follows:

C++
DeviceContextWrapper wrapper;
wrapper.dc = & (new DeviceContext());

And while talking about difficult syntax and phenomena, let me conclude for this section of C and C++ by saying template syntax can create one of the most unreadable pieces of code in history.

Coming to Java, they have made everything a little too complex for my liking by deriving everything from JObject.
I wonder if an Integer has enough properties or necessities for it to become a class. Probably I have been influenced by the great Bjarne Stroustrup in this regard who said:
"They believe that you should do everything by creating a class as part of a class hierarchy with lots of virtual functions. This is the kind of thinking that's reflected in a language like Java for instance, but a lot of things don't fit into class hierarchies. An integer shouldn't be part of a class hierarchy. It doesn't need to. It costs you to put it there. And it's very hard to do elegantly.
You can program with a lot of free-standing classes. If I want a complex number, I write a complex number. It doesn't have any virtual functions. It's not meant for derivation. You should use inheritance only when a class hierarchy makes sense from the point of view of your application, from your requirements"

And as I move on to complexities, Java's over usage of design patterns has taken the simplicity out it. For example, usage of decorator pattern to read a simple user input from the console. I even forgot how you write this... inputstreamreader(new buffered reader..)... whatever. And I am sure they have to go to through hell to introduce generics and templates in Java.

C#, more or less exists with limited flaws. I may blame the overuse of interfaces as something that gives pain to my eyes.
Implement an interface ISortable to sort items in a list.. Here, we are shooting cannons to gun down a fly I believe (This made up proverb sounds more nice in Bengali though Smile | <img src= " /> ).

JavaScript - to me, a heavenly language for basic client side operations. But it is difficult to really come up with a solid flawless architecture for bigger programs containing several modules with the prototypical hierarchy it offers. I have seen people trying to fit JavaScript into classical hierarchy model a notion itself I believe is flawed. I plan to write on this later, some other time maybe.

JQuery syntax, I need to grasp it more to understand if it really makes sense or not. Usually, I don't face too much readability problems with languages. But this JQuery thing, and the way programmers are implementing over the world looks very unreadable to me.

PHP: The reason I believe I have started written this post. It was the === operator that I commented about which created a discussion in my friend group (who are in the programming side of things of-course). To quote a highly talented friend of mine,
"I have no idea how PHP works, but it will take highly trained eyes to see == and === differently in a sea of code. I don't quite see the benefit".
In my humble view, putting different types intentionally in two variables and using a comparator operator for type comparison purpose is a strange way of doing things.. and whenever you are doing something unusual, you should use a syntax that's easily identifiable, such as is_identical($p, $q).

Another unintuitive syntax I have observed is the usage of array of arrays in PHP.

The assigning sign means actually appending.

Example:

PHP
$col = array();
$col["title"] = "Id";// caption of column
$col["name"] = "id"; // grid column name, 
                     // must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "10";
$cols[] = $col;

$col = array();
$col["title"] = "Date";
$col["name"] = "invdate";
$col["width"] = "50";

$cols[] = $col;

Believe it or not, the $col array is being appended to $cols. In my view, even a newcomer in PHP without any documentation should be able to understand the workings of an operator. It shouldn't bypass normal conventions.

The thing that really got into my nerves in PHP is the usage of dot (.) as a string append operation. It makes no sense at all. It is highly counter intuitive and a very unusual notion, that a dot should be an append operator. I do admit, it makes the writing of the codes a little easier some of the time, but the trade off between un-intuitiveness and ease of writing is way too too much. This one heads the top of my list when it comes to strange syntax. The intuitive syntax for string operations should always be +; the reason being + stands for addition. Therefore, it is intuitive that + as an operator can add any type of variables together. So, it can add string as well. You may make a case about what about * as an operator for multiplication? I would defend my case with the following argument:
It is well established that * is an operator for multiplication in programming languages, so it would be silly to come up with a new notion for that.

My point is, you have to show inventiveness with new features in a new language, not change the well established and readable syntax that exists for basic operations.

A little off topic, I am seeing an over-reliance on frameworks such as code-igniter which abstracts stuff too much for my liking. However, I haven't spent that much time with PHP to comment in more detail.

I have some observations about how the web programming is evolving and where it is leading to and what are the lags - I plan to write about it someday. But till then,

Astana vista comrades...
Signing off - mukit

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)