📜 ⬆️ ⬇️

On the issue of programming languages ​​...

Since the vote does not allow you to leave comments, I will make comments in a separate article.

Particularly interested in the opinion of people who believe that they can not happen (the penultimate item in the survey). Why?

Under the cut - a complete example in one of the most common programming languages. Bonus! Not even one programming language, but two.
')
Javascript:
function remove_element(/* array */ a, /* element */ e) {
var b=[];
for (var i=0;i<a.length;i++) {
if (a[i]!=e) b.push(a[i]);
}
return b;
}
var before=[7, "13", "5", 6];
var after=remove_element(before, "13");


PHP (example fixed , thanks to Sannis ):
function remove_element(/* array */ $a, /* element */ $e) {
$b=array();
foreach($a as $m) {
if ($m!=$e) array_push($b, $m);
}
return $b;
}
$before=array("11", "a", 2, 3);
$after=remove_element($before, "a");

What other languages, allowing similar, you know and do you think that the convenience provided by this approach justifies the problems that it causes?

PS Many programming languages ​​have many oddities when working with floating-point numbers - but this is well known and can be protected as a maximum of half a point. Although even if you draw floating-point numbers in sane programming languages ​​(C / C ++, Java, Python, Lisp), I can't think of anything (without overlapping operators, which is understandable to have clean cheating).

PPS In general, the whole topic grew out of the discussion where they tried to explain to me that I don’t understand anything in programming and my unwillingness to put up with similar, if I may say so, programming languages ​​indicates my dullness and wretchedness, and not problems in the language.

Source: https://habr.com/ru/post/48624/


All Articles