Click here to Skip to main content
15,867,453 members
Articles / Programming Languages / Java

Eccentricity in Programming Languages

Rate me:
Please Sign up or sign in to vote.
3.60/5 (4 votes)
21 Feb 2013CPOL6 min read 19.2K   3   17
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

This article was originally posted at http://rationaltech.net?q=node%2f9

License

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


Written By
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1

Comments and Discussions

 
GeneralMy vote of 2 Pin
Bartlomiej Filipek27-Feb-13 4:07
Bartlomiej Filipek27-Feb-13 4:07 
GeneralRe: My vote of 2 Pin
Mukit, Ataul27-Feb-13 5:19
Mukit, Ataul27-Feb-13 5:19 
GeneralRe: My vote of 2 Pin
Bartlomiej Filipek27-Feb-13 5:51
Bartlomiej Filipek27-Feb-13 5:51 
GeneralRe: My vote of 2 Pin
Mukit, Ataul27-Feb-13 7:48
Mukit, Ataul27-Feb-13 7:48 
GeneralRe: My vote of 1 Pin
Mukit, Ataul22-Feb-13 17:06
Mukit, Ataul22-Feb-13 17:06 
GeneralLink bait Pin
mrchief_200022-Feb-13 8:34
mrchief_200022-Feb-13 8:34 
QuestionI prefer C but wish it had inline functions like C++ Pin
dusty_dex22-Feb-13 8:21
dusty_dex22-Feb-13 8:21 
AnswerRe: I prefer C but wish it had inline functions like C++ Pin
Mukit, Ataul22-Feb-13 17:04
Mukit, Ataul22-Feb-13 17:04 
GeneralRe: I prefer C but wish it had inline functions like C++ Pin
dusty_dex23-Feb-13 0:47
dusty_dex23-Feb-13 0:47 
GeneralMy vote of 1 Pin
Altaf N Patel22-Feb-13 3:25
Altaf N Patel22-Feb-13 3:25 
GeneralRe: My vote of 1 Pin
Mukit, Ataul22-Feb-13 4:23
Mukit, Ataul22-Feb-13 4:23 
GeneralMy vote of 5 Pin
Mukit, Ataul16-Feb-13 4:20
Mukit, Ataul16-Feb-13 4:20 
GeneralRe: My vote of 5 Pin
John Brett18-Feb-13 4:30
John Brett18-Feb-13 4:30 
GeneralRe: My vote of 5 Pin
Mukit, Ataul18-Feb-13 4:35
Mukit, Ataul18-Feb-13 4:35 
GeneralRe: My vote of 5 Pin
mrchief_200022-Feb-13 8:35
mrchief_200022-Feb-13 8:35 
GeneralRe: My vote of 5 Pin
Mukit, Ataul22-Feb-13 20:40
Mukit, Ataul22-Feb-13 20:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.