Overloading
Overloading
Posted Apr 26, 2014 17:54 UTC (Sat) by rsidd (subscriber, #2582)In reply to: Overloading by apoelstra
Parent article: Porting the Go compiler to Go
I never learned C++ and I never learned Perl, basically because I couldn't read either -- both looked like line noise to me. My main exposure to C++ concepts, sad to say, is via this old fake Stroustrup interview, which has gems like this:
Take operator overloading. At the end of the project, almost every module has it, usually, because guys feel they really should do it, as it was in their training course. The same operator then means something totally different in every module. Try pulling that lot together, when you have a hundred or so modules.(and much else, which is probably vvery familiar to LWN readers)
Posted Apr 28, 2014 18:21 UTC (Mon)
by drag (guest, #31333)
[Link] (15 responses)
You should. It's fun.
Posted Apr 28, 2014 18:33 UTC (Mon)
by HelloWorld (guest, #56129)
[Link] (10 responses)
Posted Apr 28, 2014 18:44 UTC (Mon)
by rsidd (subscriber, #2582)
[Link] (3 responses)
As I remember, one stumbling block was this: the logical way to do what I wanted was via a list of lists, which in python would look like [[1,2],[3,4],[5,6]]. But perl flattens lists for you, and the syntax to get it to not flatten it was not widely known to people I talked to.
Posted Apr 28, 2014 19:33 UTC (Mon)
by madscientist (subscriber, #16861)
[Link]
Posted Apr 28, 2014 19:36 UTC (Mon)
by dtlin (subscriber, #36537)
[Link]
Posted Apr 28, 2014 21:54 UTC (Mon)
by drag (guest, #31333)
[Link]
Since perl has so much freedom each developer ends up their own idiosyncratic style. Since each style is so divergent it becomes very difficult to decypher what is going on. When you combine that with the fact that perl has so many little hidden variables and weird things that it does then it becomes difficult to understand what other people's code is doing.
I much rather prefer a language were there is just a small number of ways to do any single thing and one that enforces some sort of formatting rules and other things that helps make it more readable.
I am thinking that a lot of the overloading type things being discussed above for syntactic sugar type things may actually belong in the editor and not in the language. Like you can have all these language short cuts and 'jive terms' you prefer to use and have it expanded by the editor in the actual code you are working on so that it's easily read by other people that don't know your 'jive'. The editor can take care of translating back and forth for you, and if it can't figure it out then it's probably not worth doing.
Posted Apr 28, 2014 21:32 UTC (Mon)
by drag (guest, #31333)
[Link] (5 responses)
If it hurts when you do that, don't do that.
Posted Apr 28, 2014 22:33 UTC (Mon)
by HelloWorld (guest, #56129)
[Link] (4 responses)
Posted Apr 28, 2014 23:22 UTC (Mon)
by alankila (guest, #47141)
[Link]
$ perl -we 'sub x { my $x = shift; sub y { $x } }'
Perl's major fault is that too few of its warnings are fatal errors. I know, I know, you can opt-in to have warnings go fatal. My point is that the defaults are wrong.
Posted Apr 28, 2014 23:45 UTC (Mon)
by rgmoore (✭ supporter ✭, #75)
[Link] (1 responses)
It's not that unreasonable. Perl makes a fairly big deal about anonymous values, and only anonymous functions can be turned into closures. If you like writing with closures, you'll learn the rules for them pretty quickly. This is the blessing and the curse of big languages like Perl. There's lots of cool features there to learn and use, but it means that different people program in different dialects that aren't as mutually comprehensible as you'd like. My take on this is that Larry Wall said he wanted Perl to be more like a human language than like a computer language, but that his idea of what human language is like is heavily influenced by being a native English speaker.
And I believe the properly snarky response to "If it hurts when you do that, don't do that." is "That's why I avoid Perl."
Posted Apr 29, 2014 0:03 UTC (Tue)
by HelloWorld (guest, #56129)
[Link]
Posted Apr 29, 2014 6:21 UTC (Tue)
by niner (subscriber, #26151)
[Link]
Posted May 2, 2014 12:29 UTC (Fri)
by renox (guest, #23785)
[Link] (3 responses)
I disagree with this: the more I develop in Perl, the less I like it..
Latest trap which caught me:
Not fun!
Posted May 2, 2014 17:51 UTC (Fri)
by Wol (subscriber, #4433)
[Link] (2 responses)
In fact, I think FORTRAN is illogical here. I can't remember much about it, but I used to program in FORTRAN IV and Fortran 77, and one of the switches available in Fortran was "always run loops at least once, like FORTRAN does". I can't remember whether that was the standard, or the Pr1me implementation, but I was well aware of it as something to be looked out for.
Cheers,
Posted May 2, 2014 18:47 UTC (Fri)
by dtlin (subscriber, #36537)
[Link] (1 responses)
What renox means is the keywords last, next, and redo (analogous to break and continue in C) work inside while (..) { ... } but don't work inside do { ... } while (..). It's a syntactic oddity in Perl because do { ... } is an expression, not a block, and postfix while (..) turns an expression into a (looping) statement.
This is mentioned in perldoc perlsyn #Statement Modifiers, along with workarounds.
Posted May 3, 2014 13:29 UTC (Sat)
by madscientist (subscriber, #16861)
[Link]
Overloading
Overloading
You should. It's fun.
If you're into BDSM I guess.
This prints 11:
sub a {
my $x = shift;
sub b {
$x;
}
\&b;
}
print a(1)->();
print a(2)->();
This prints 12:
sub a {
my $x = shift;
sub {
$x;
}
}
print a(1)->();
print a(2)->();
And this leaks memory every time it's called:
sub s {
my $x;
$x = \$x;
}
Thanks, but no thanks.
Overloading
Feh. "The people you talked to" must have not known the first thing about Perl. Perl has its flaws (as does Python, Ruby, and just about everything else), but this is not one of them:
Overloading
$ perl -e 'my @foo = ([0, 1], [3, 4]); print "$foo[0][1] $foo[1][0]\n";'
1 3
Lists (the non-reference kind) do get flattened in list context, but the exact same syntax - [[1,2],[3,4],[5,6]] - gives you a reference to an array of array references in Perl. Nobody you talked to had read perldoc perllol?
Overloading
Overloading
Overloading
Overloading
Overloading
Variable "$x" will not stay shared at -e line 1.
Overloading
Overloading
It is, it's completely nonsensical. I don't care about the excuses Larry might come up with.
Overloading
Overloading
'do { ... } while(..)' doesn't work like 'while () { ... }', in the latter next/last work, not in the former???
Overloading
Wol
Overloading
Overloading
