www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Filtering even numbers in various languages

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
https://gist.github.com/817504

I added a D version.

Andrei
Feb 08 2011
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Andrei:

 https://gist.github.com/817504
 
 I added a D version.

Good :-) They have missed the lazy Python2.x version: (x for x in xrange(1, 5) if not x % 2) Bye, bearophile
Feb 08 2011
prev sibling next sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 2/8/11 8:02 PM, Andrei Alexandrescu wrote:
 https://gist.github.com/817504

 I added a D version.

 Andrei

Added a comment too (andralex). Andrei
Feb 08 2011
prev sibling next sibling parent reply Christopher Nicholson-Sauls <ibisbasenji gmail.com> writes:
On 02/08/11 19:02, Andrei Alexandrescu wrote:
 https://gist.github.com/817504
 
 I added a D version.
 
 Andrei

I would argue that (a & 1 == 0) is a cheaper simple test for evenness... </gratuitous-nitpick> Good show. Not really sure what the point of the list was... but sometimes these things are just (for) fun. -- Chris N-S
Feb 08 2011
parent spir <denis.spir gmail.com> writes:
On 02/09/2011 07:02 AM, Christopher Nicholson-Sauls wrote:
 On 02/08/11 19:02, Andrei Alexandrescu wrote:
 https://gist.github.com/817504

 I added a D version.

 Andrei

I would argue that (a& 1 == 0) is a cheaper simple test for evenness... </gratuitous-nitpick> Good show. Not really sure what the point of the list was... but sometimes these things are just (for) fun. -- Chris N-S

Isn't this, precisely, a typical case of expected compiler rewrite? while n%2 far better expresses the concept in source (in absence of to-be-inlined isEven() or general isMultipleOf(), indeed). Denis -- _________________ vita es estrany spir.wikidot.com
Feb 09 2011
prev sibling parent reply Max Samukha <maxsamukha spambox.com> writes:
On 02/09/2011 03:02 AM, Andrei Alexandrescu wrote:
 https://gist.github.com/817504

 I added a D version.

 Andrei

I am amazed at how Java guys still prefer their crappy, noisy and efficient way. And sadly they represent the majority.
Feb 09 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
Max Samukha:

 I am amazed at how Java guys still prefer their crappy, noisy and 
 efficient way. And sadly they represent the majority.

Well, compared to C++, a Java programmer needs to keep in mind far less arbitrary details, that if forgotten cause many bugs in C++ programs. Java compiler is strict and catches many bugs, it works well enough, and you just need small jars to distribute the compilation result. Today Java works on many machines, on 32 and 64 bit well enough, there are tons of libraries, Java programmers that you are able to hire, tons of tools to edit/debug/improve Java code, Java is today pretty fast and its GC is first world class. There are even other languages like Scala and Jthon that run on the JVM and interoperate with it and its libs. Given all that, the verbose syntax of Java becomes a minor thing. Java is full of faults and downsides, but most other languages/language ecosystems are worse. Bye, bearophile
Feb 09 2011
parent Max Samukha <maxsamukha spambox.com> writes:
On 02/09/2011 08:06 PM, bearophile wrote:
 Max Samukha:

 I am amazed at how Java guys still prefer their crappy, noisy and
 efficient way. And sadly they represent the majority.

Well, compared to C++, a Java programmer needs to keep in mind far less arbitrary details, that if forgotten cause many bugs in C++ programs. Java compiler is strict and catches many bugs, it works well enough, and you just need small jars to distribute the compilation result. Today Java works on many machines, on 32 and 64 bit well enough, there are tons of libraries, Java programmers that you are able to hire, tons of tools to edit/debug/improve Java code, Java is today pretty fast and its GC is first world class. There are even other languages like Scala and Jthon that run on the JVM and interoperate with it and its libs. Given all that, the verbose syntax of Java becomes a minor thing. Java is full of faults and downsides, but most other languages/language ecosystems are worse. Bye, bearophile

I was referring to the particular posters who praised the Java solution, which is obviously inferior to nearly every 'filter' variant provided by other posters.
Feb 09 2011