Live data from Hacker News

Nastiest Python list comprehension ever

blog.garlicsim.org

51–55 of 55 posts

Re: Nastiest Python list comprehension ever

#51

Earlier quoted context omitted.

I think you've mistaken my argument. I didn't say that the Python version looks good or is the best way to do it. It's not. I was saying that "something that is long and full of moving parts" is easier to read than something that is short and idiomatic. I am not saying either of them represent the ideal way to do it. My definition of readability includes the ability to convey the programmer's intention to the mind of…

The reader should be able to work out what is intended by the code with minimal requirements placed on them.... That's where the argument goes wrong, if the idea of "minimal requirements" means "avoid idioms".

[deleted]

Re: Nastiest Python list comprehension ever

#52

Earlier quoted context omitted.

I think you've mistaken my argument. I didn't say that the Python version looks good or is the best way to do it. It's not. I was saying that "something that is long and full of moving parts" is easier to read than something that is short and idiomatic. I am not saying either of them represent the ideal way to do it. My definition of readability includes the ability to convey the programmer's intention to the mind of…

The reader should be able to work out what is intended by the code with minimal requirements placed on them.... That's where the argument goes wrong, if the idea of "minimal requirements" means "avoid idioms".

Well, I'd welcome an explanation of your opinion here.

Re: Nastiest Python list comprehension ever

#53
post #48

Earlier quoted context omitted.

Are you sure that's Perl? Are you sure it's not... nothing? Seriously, I cannot fathom why this would work, let alone how. The syntax is completely alien to me.

I am sure that this is Perl. Let me build it up as it executes. First, pop returns the last element of an array. If no array is specified, @_ is used, which is the default array into which function arguments are passed. Therefore pop gets at the last argument. If this function is called with one argument, it gets at the first argument. sub sieve3 { pop } Next .. is the range operator. It builds up a list from one num…

Huh, it actually makes sense now, thank you.

Re: Nastiest Python list comprehension ever

#54

Earlier quoted context omitted.

Are you sure that's Perl? Are you sure it's not... nothing? Seriously, I cannot fathom why this would work, let alone how. The syntax is completely alien to me.

Add some spaces: sub sieve { sub p { $_[0] , @_>1 ? p(grep$_%$_[0],@_) : 1; } p(2..pop) } And if you get rid of some terse syntax: sub p { my ($first, @rest) = @_; if (@rest > 1){ return $first, p(grep { $_ % $first } @rest); } return 1; } sub sieve { my $arg = shift; return p(2..$arg) } BTW, you can even have Perl do this automatically for you, by running: $ perl -MO=Deparse sub p { $_[0], @_ > 1 ? p(grep(($_ % $_[0…

Thanks, I have indeed never programmed in perl and was feeling a bit facetious.

Re: Nastiest Python list comprehension ever

#55

Earlier quoted context omitted.

The reader should be able to work out what is intended by the code with minimal requirements placed on them.... That's where the argument goes wrong, if the idea of "minimal requirements" means "avoid idioms".

Well, I'd welcome an explanation of your opinion here.

Unless I'm writing training material for novices, I write code with the assumption that anyone else maintaining it is reasonably competent with the languages, libraries, and tools in question. That to me is a minimal requirement.
Post reply on HN