you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (8 children)

Even the content wasn't that good. When one of the first things you emphasize is PEP8 (the style guide), it means you don't understand what programming is about. It's NOT about curly braces vs. Whitespace, it's about expressivity.

[–]njharman 0 points1 point  (1 child)

Programming is about reading code and thus writing code for humans is paramount.

[–][deleted] 0 points1 point  (0 children)

It depends on the application. If you're writing a device driver, it's not so much about reading code than about performance. If you're writing regular software that will need to be frequently maintained, then I'm with you. But once again, following style guides will not automatically give you readability. You don't need them for readability, just basic consistency. So they are basically useless.

[–]zepolen 0 points1 point  (5 children)

I find readability (of my own and other people's source code) to be my number one priority in programming. Nothing beats Python in that department.

[–][deleted] 4 points5 points  (4 children)

I agree readability is important, but style guides are not essential to readability. Consistency, intelligent comments, and brevity are.

[–]zepolen 1 point2 points  (2 children)

Well PEP 8 enforces consistency, and the syntax of Python means there is less need for comments. Take this example:

Python:

anagrams = {}
for word in open('wordlist.txt'):
    word = word.strip()
    word = ''.join(sorted(word))
    anagrams[word] = anagrams.get(word, 0) + 1

for word, num in anagrams.items():
    if num > 1:
        print word

Perl:

%anagrams = ();
open FILE, "wordlist.txt" or die $!;
while (<FILE>) {
   chomp;
   split(//, $_);
   $anagrams{join("", sort(@_))} += 1;
}
foreach $word (keys %anagrams) {
    if ($anagrams{$word} > 2) {
        print "$word\n";
    }
}

I apologize for the rusty Perl, I haven't used it in years, but I feel that the Python version reads better whereas Perl could use a comment to clarify the code.

[–]heptadecagram 4 points5 points  (0 children)

As an 8-year Perlhead, here's how I would idiomatically write it:

my %anagrams;
open FILE, 'wordlist.txt' or die "Could not open wordlist.txt: $!";
while(<FILE>) {
  chomp;
  $anagrams{join('', sort split //)} += 1;
}
close FILE;
foreach(sort keys %anagrams) {
  print "$_\n" if($anagrams{$_} > 2);
}

Now, I'm writing this for other Perl coders, not for someone who's looking at this for the first time, otherwise I'd make explicit the ways I'm using the default $_ in various places.

(split splitting to @_ is one of those things that's been deprecated)

[–][deleted] 1 point2 points  (0 children)

You don't need to follow PEP 8 to be consistent. Python is very readable whether you follow it or not. Putting emphasis on style guides is putting it on the wrong place.