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.”
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.
So, lets use a string in each language as the subject of our examination.
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.
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 = 'J'
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
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:]
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 = 'c'
Not better or worse than the other languages necessarily though not my personal favorite.
If you run this code you will NOT get an error…
var name = 'coy';
name = 'J';
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);
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 = 'J';
The thing is if you try this code on JSBin (not a sponsor) you get this rather cryptic error:
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 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 = 'J';
The real difference being that with “immutable” strings you cannot change the value directly and instead have to reassign the value to another variable.
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!