C++ launched its community survey, too

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Feb 28 20:01:34 UTC 2018


On Wed, Feb 28, 2018 at 06:45:29PM +0000, TheFlyingFiddle via Digitalmars-d wrote:
[...]
> My least preferredlanguage of all times would be Perl. With (PHP 5.3)
> coming in at a close second :)
> 
> Perl is just... I get it, you can write somewhat nicer bash scripts in
> the language.

I was actually a Perl (5) fan for many years, before finding D.  As you
said, it's very nice for replacing brittle (and ugly!) shell scripts,
not to mention with superior performance instead of spawning a
subprocess (somtimes multiple) for basically every command, even
fundamental things like evaluating an expression. (Though bash may have
built-in some of it... but still.)

PHP is just... well, OK, one has to admit that the idea of embedding
code in HTML and vice versa in a smooth syntax that you can easily
transition into and out of, was an extremely clever one.  It removed the
burden of constant escaping (aka the leaning toothpick syndrome) that
was prevalent in such kind of code back in the day.  But other than
that.. PHP has some pretty serious fundamental design flaws that became
calcified as features because just about everything depended on it, and
after a while, it was just a monster of a language, most eloquently
described as:

	https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/


> But people... they just go with it and build these huge crazy systems
> that somehow 10+ years later become my problem.

Yeah... Perl is great for one-off scripts and clever hacks.  But the way
it's designed also makes it not very scalable.  Once you get past a
certain size, the quirky syntax and general looseness (in typing,
semantics, data structures, etc.) just start becoming more and more of a
maintenance burden.

At least, that was the case for Perl 5, which was around the time I
found D and left Perl behind.  Can't speak for Perl 6 or later.


> The designer of Perl was clearly insane. Let's store everything in fun
> global "invisible" variables, functions don't specify arguments... And
> lets have the first letter of the variable define how/what $, @, %,
> with fun auto conversions everywhere :D.

The idea of sigils is actually not a bad one.  It does, after all, have
basis in natural languages. But the way it was implemented in Perl is,
shall we say, rather quirky, leading to all sorts of unexpected
interactions with other things and generally become a cognitive burden
in large projects, where a disproportionate amount of time is spent
fighting with syntax rather than getting things done.  (E.g., is it
@$x[$y] or $x->y or ${x}{y} or ${x->$y}[$z] or something else?)

D's dot syntax, by comparison, is worlds better. One dot to rule 'em
all.  Symmetry is powerful. ;-)


> PHP is better but there is some really weird stuff in it.

Actually, IMO, PHP is far worse than Perl.  Perl is pretty crazy, yeah,
but it does have a certain kind of logic behind it (albeit a twisted
one, just like its creator :-P), a kind of consistency that makes you go
"yeah, in retrospect it *does* make sense, even though it's still really
weird".  PHP, OTOH, is full of exceptions and corner cases *without* any
underlying consistency.  There is no pattern to it, not even a twisted
one, it's just a bunch of arbitrary exceptions and special cases that
you basically have to memorize.  And random things just Don't Work(tm),
just because they don't, for no discernible reasons whatsoever.  Like
the inability to overload class constructors, even though polymorphism
is supported, a very strange combo.  And the word "overload" is used in
a strange, different sense, just to confuse you.


> Of the top of my head is the auto type conversion system. This works,
> by design...
> 
> //PHP
> $a = 5;
> $b = $a * "10 trains";
> echo $b; //$b is now 50... Fun and interesting stuff right there

Yeah, that's 10 trains worth of WATs right there. :-D

And the whole thing about == vs === is just one huge WAT.  It "makes
sense" if you understand why it's necessary, but it just begs the
question, why, oh why, wasn't the language designed properly in the
first place so that such monstrosities aren't necessary?!


> Compared to them, programming in C++ or Java for that matter is like a
> dream.

C++ is hardly any better, actually:

	https://bartoszmilewski.com/2013/09/19/edward-chands/

Java... well, Java is a walled garden, a somewhat nice (if verbose) one
that's somewhat detached from reality, but forcefully anchored to it by
big commercial interests.  As a language it's not too bad; the core
language is pretty nicely designed -- in an idealistic, ivory tower sort
of sense.

But in practice, it's more of a Write Once, Debug Everywhere deal.  The
verbosity and IDE dependence sucks.  The OO fanaticism also sucks
(singleton classes IMO is a big code smell, esp. when it's really just
syntactic lip service to the OO religion for what's essentially global
functions).  The lack of real generics is total suck, and a showstopper
for me. Even the half-hearted attempt at generics that they shoehorned
into it later doesn't fully save it from being sucky.  The only saving
grace of Java is the extensive library support -- you can find just
about anything you might imagine as a library, which saves you from
dealing with the suckier parts of the language. Most of the time.


> But when I can, I always use D. Mainly because unlike every other
> language, it has static introspection, ctfe and mixins. A whole new
> world of expressive power is gained by this.

D to me is like the nexus of all the best things from the languages I
worked with: it has the conciseness and expressive power of Perl and is
suitable for one-off, shell-script-like utilities, yet with the safety
of static typing and the sanity of clean syntax.  It also has a GC, one
of the non-sucky aspects of Java, which saves it from being C hell in
large projects where 90% of your mental energy is spent worrying about
memory management instead of focusing on the problem domain, or C++ hell
with a pathological syntax that must be parsed before it can be lexed.
It has templates with a sane syntax, unlike C++, but goes beyond that
with static introspection, CTFE, and mixins like you said.

D also empowers the user to build their own functionality where the
built-ins aren't good enough. This is actually a huge point for me.
Recently I started a thread complaining about the new int promotion
deprecation rules, and not long after, somebody described an almost
beautiful workaround that uses operator overloading and `alias this` to
basically completely bypass the casts.  The fact that such a thing is
*possible* in D speaks volumes.

If this were in, say Java, I would have basically been told, "what you
want isn't supported. Suck it up, or go to another language". As Andrei
wrote in TDPL, (and I paraphrase,) it sucks when built-in types have
magical abilities inaccessible to user code.  This is a common defect in
many programming languages... the "magical" behaviour is wonderful when
it works. But if you need something that said "magic" doesn't cover,
you're left up the creek without a paddle.  In D, however, you're given
the tools to build your own equivalents of language built-ins.  Language
built-ins not good enough?  No problem: we give you the tools to write
your own.

The concept of empowering the user (rather than shoehorn everything into
a preconceived cage) is a powerful one, that would-be programming
language designers would do well to take heed to.


> Only thing missing is the ability to do arbitrary system calls during
> compilation :D

AKA compile-my-source-code-and-get-a-trojan-installed-on-your-system.
:-D  If this (mis)feature ever gets merged into DMD, give me a call
right away -- I have a lot of source code to sell you. For free. :-D


T

-- 
By understanding a machine-oriented language, the programmer will tend to use a much more efficient method; it is much closer to reality. -- D. Knuth


More information about the Digitalmars-d mailing list