For right or wrong, better or worse, in sickness and in health… it happens to most of us at one point or another, we fall in love and I’m not talking that “puppy love” either…

I mean the “in it for the long term, I hear wedding bells” kind of love! πŸ˜›

When you have been programming for a goodly number of years and “gone steady” with at least a few languages, you find that generally there is a lot of overlap and similarity between them! Of course, there are differences… some specialize in their selected niche either by design or by homogenization of a developer community.

Essentially though, all programming languages are more or less capable of doing the same things, though they go about it in different ways.

I know you embedded developers are probably disagreeing with me at this point, let me just say I totally agree that when it comes to low level embedded situations, C Language is what you really want, so don’t bite my head off in the comments! πŸ˜›

My accedence (it’s a real word) about embedded applications notwithstanding, I think you can GENERALLY agree with this quote (though I’m not sure who to attribute the quote to) and I’m only just paraphrasing anyway, it goes like this:

“You can do just about the same things in all programming languages. What sets them apart is what they make easy and what they make hard.”

~Unknown

And that’s really the crux of it isn’t it!

After you have become familiar with your “lenguaje del amor” it’s suddenly like… traversing that billion-element 3D tuple isn’t so bad! πŸ˜›

Of course, it’s not quite that simple in reality but the fact that any given language can make something subjectively “easier” to an individual compared to another language due to a methodology or strategy employed by that language is very much at the heart of why programmers seem to “merry” their languages!

As I mentioned, there are various styles, methodologies and strategies implemented by the designers of programming languages that change how you think about problems they set out to tackle.

Further, despite comparing “multi-paradigm” languages with one another you get certain languages that just seem to fit better at solving certain types of problems.

I’ll give you an example of the subjectivity I’m talking about with 3 different “multi-paradigm” capable languages namely Python, JavaScript and my personal favorite PHP (some of you just gagged, please compose yourself… I’ll wait πŸ˜› )…

So, lets use a string in each language as the subject of our examination.

In Python and JavaScript strings are said to be “immutable” whereas in PHP strings are “mutable”, now before I begin I am NOT stating that one is objectively better than the other,Β but I am going to try to demonstrate that there are differences between languages, which in and of itself should not be controversial.

Each has its pros and cons (I.E. reasons why an individual programmer may prefer one over the other), but they are all capable languages and great to know!

I simply aim to show that there ARE differences and those stylistic differences are a large factor, though of course not the only factor.

Python

Let’s start with “immutable” strings in Python. Let’s say we have a string variable with the label ‘name’ and either mistakenly assign or “point it to” the value of ‘coy’ or as part of our project we simply need the ability to modify the string.

Let’s then give ourselves the challenge of correcting the string during program execution to ‘Joy’ but without simply reassigning the name variable to ‘Joy’, in other words let change the ‘c’ to a ‘J’.

Now since Python strings are “immutable” they cannot be directly accessed and changed however that doesn’t mean that you CAN’T change them.

>>> name = 'coy'
>>> name[0] = 'J'
>>> print(name)

If you ran this code you would get this lovely little error:


Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'str' object does not support item assignment
name[0]

HONESTLY… I don’t think I have ever seen as CLEAN and pleasantly descriptive error in my entire tech career! Extreme kudos to the Python community! πŸ™‚ That level of clarity is rare in programming errors!

In order to accomplish what we want we can do something like the following:

>>> name = 'coy'
>>> name = name[:0] + 'J' + name[1:]
>>> print(name)

The traditional “pythonic” response to this problem (I think) is to create a list and store the individual characters so that you can then get index access like this:

>>> name = list("Joy")
>>> name[0] = 'c'
>>> print(''.join(name))

Not better or worse than the other languages necessarily though not my personal favorite.

JavaScript

If you run this code you will NOT get an error…

var name = 'coy';
name[0] = 'J';
console.log(name);

Though the name variable remains ‘coy’! In order to accomplish what we want we can do something like the following:

var name = 'coy'; 
name = 'J' + name.substr(1);
console.log(name);

I don’t think there is a “prescribed” solution in the JS community though it is possible to do the Python solution and “split” the string into an array:

var name = 'coy'.split('');
name[0] = 'J';
console.log(name.join(''));

The thing is if you try this code on JSBin (not a sponsor) you get this rather cryptic error:

"error"
"@null.js:16:38
l</b.render/<@https://static.jsbin.com/js/prod/runner-4.1.0.min.js:1:13848
k</a.use/<@https://static.jsbin.com/js/prod/runner-4.1.0.min.js:1:10792
"

But it works fine on JSFiddle (not a sponsor) so I am not sure if it’s a versioning issue but coder beware! If there are Any JS coders in the audience feel free to contact me with the reason why this might be and I’ll credit you for the info! πŸ™‚

PHP

PHP is a little different in that all strings are “byte” arrays already which just means that the indexes are already open to direct modification and that works like this:

$name = 'coy';
$name[0] = 'J';
echo $name;

The real difference being that with “immutable” strings you cannot change the value directly and instead have to reassign the value to another variable.

In both the JavaScript and Python examples we used the same label (name) for the variables but the internal ID’s for those variables are different. Using this methodology basically means having to “split” the string by hand, cull the unwanted value, insert the new value and recombine the string.

Again, neither approach is is objectively “correct” but if you work with a lot of string data you might soon come to appreciate the ease of PHP in that respect, I certainly do! πŸ˜›

The funny thing is though that although you can “marry” your language, it might not excel in all ways and you are then forced to admit that only one language cannot be everything you need it to be all the time… In fact, in my article The Impending Death of the Programmer I briefly talked about the need for “transpiler” software which does level the “playing field” somewhat but not entirely.

Several interesting tranpilers in the PHP community are wxPHP (not a sponsor) that allows for native WIN, MAC, & LINUX application development using PHP.

There is also KikAppTools (not a sponsor) which allows native Android & iOS mobile application development using PHP.

These tools extend the reach of a language significantly!

I am still waiting for Unity3D to implement a PHP version. πŸ˜›

Still though, it’s hard for just one language to “be all things to all people”, so to continue the metaphor, you just might find that “polyamory”… er “polyglotism” is the way to go! πŸ˜›

In any case, even if we are comfortable working in multiple languages… there will always our favorites!

Please Fund, Subscribe, Like, Share & Comment:

This post was made possible by the generous contributions of my sponsors on Patreon & anonymous contributions to my Bitcoin Tip Jar.

 

 

I will see you all in my next post!

Much Love,

~Joy