5 ms·
> One problem is that the "known good perl code" likely doesn't have comprehensive tests, it was probably written before TDD became prevalent. I'd argue that p
by jlg23 10y ago
> One problem is that the "known good perl code" likely doesn't have comprehensive tests, it was probably written before TDD became prevalent.
I'd argue that perl made TDD mainstream, though we did not call it that way 20 years ago. Well, 30, but I did not join in until the mid 90s. Perl's test protocol TAP was around since at least 1988[1] and back then when I was coding perl for a living, I rarely encountered "known good perl code" that did not have tests (notable exception: usemod wiki).
[1] https://testanything.org/history.html https://testanything.org/history.html
- BWStearns 10y agoHaving used TAP I'm glad it existed for the things it arguably precipitated but I will never do it voluntarily again.
- logicallee 10y ago>I'd argue that perl made TDD mainstream, because wtf else are you going to do when you develop using lines like next if (/^(#|$)/); (totally 100% typical totally normal line - I found it by clicking the source for the very first CPAN module for a very common word - I knew I would find a typical line like that. I swear there was zero bias to this methodology). I just use this example because it ends in what is line noise. I'm pretty sure it means "don't process this line (skip to the nexct one) if it's a line that either starts with a #, or is an empty line). But how do I really know what it does? By testing it, of course! When good code is line noise, how else do you know that it works? Of course you're going to test it. :D - EDIT: Downvoters aren't disagreeing with me. You can't downvote me just because you don't like the truth. Perl coders have a heavy culture of testing. It's the only way anyone writes Perl code - period. This is in contrast with C++ programmers, for example, who historically were more content to reason about their code. Historical fact - sorry.
- majewsky 10y agoThat's a weak argument. Just because you are not familiar with Perl regexes doesn't mean that this line is unreadable. Not saying that there is unreadable Perl code; there's troves of it. But this line is reasonably clear and idiomatic Perl.
- logicallee 10y agoIt's not about being unreadable (I gave you my reading! It means skip this line if it starts with a literal # character or "starts with" the end-of-line marker, i.e. is blank. # is a literal, $ is the end of line character and | separates them with an or. You have to be completely familiar with regexes to know that this is correct. This line is simple. More complicated lines are...more complicated. Testing lets you know that code is working. Perl is the first major project that had amazing, obscene amounts of test coverage. I would say it is due to the grammar and difficulty. I agree with you that it is clear and idiomatic Perl! Clear and idiomatic Perl is also easy to misparse using just your brain. Test code is what tells you what you wrote is doing what it is supposed to be doing. Nobody writes Perl code, reads it carefully and reasons about it, and figures that if it compiles it is probably correct. Further, nobody has ever written code in Perl that way. Instead Perl has a heavy culture of testing. You can argue with it but it's simply true. Contributors to CPAN have had more test coverage than the average project, and this has been true for a very long time. There's no real way to debate this.
- GlitchMr 10y agoIn C-like programming language (yes, I know that == may not be string equality and so on, but that's a minor thing) it could be written like that. if (line == "" || line[0] == '#') continue; Seems fairly straightforward to me, Perl programmer won't have any problem understanding the line you provided (with `next` keyword). If you see such a line just after loop, it's clear that it skips particular lines (in this case, empty lines and probably comment lines). Such a thing may look cryptic when not used to regular expressions, however once used, it's actually easier to understand and less bug prone compared to imperative implementation (as there is less code, which means less chance to have a bug somewhere).
- logicallee 10y agoHistorically (not today) C++ programmers were far less likely to ever write a test to make sure if (line == "" || line[0] == '#') continue; does what they think it does than the Perl programmer was to write a test to make sure next if (/^(#|$)/); does what they think it does. The C++ programmer was far more likely to eye-ball it. This is a simple, historic fact. TDD came to Perl before it came to C++. I am making a simple statement about actual practices, not some kind of larger point. TDD came to Perl earlier. simple fact.
- smitherfield 10y ago“if (line == "")” most certainly does not do what you "think it does" in C++.
- singingfish 10y agoFTFY: my $comment_or_blank =~ /^ # beginning of line \s+ # bugfix - any amount of whitespace (\#|$) # comment char or blank line /x; # x modifier allows commented regexen. next if $comment_or_blank;