Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Java vs. brainfuck vs. Python.

Name: Anonymous 2007-04-24 18:38 ID:oUkHXcjW

http://en.wikipedia.org/wiki/Brainfuck
http://en.wikipedia.org/wiki/Java
http://en.wikipedia.org/wiki/Python_%28programming_language%29

Now that we're all up to speed, discuss the pros and cons of each language, as well as which you believe to be the superior language.

Name: Anonymous 2007-04-24 18:57 ID:DwbH7Sj5

Brainfuck is sadomasachism for geeks.
Python is Haskell for dummies.
Java is for dummies.

Name: Anonymous 2007-04-24 20:24 ID:fgYYp+33

NO EXCEPTIONS

Name: Anonymous 2007-04-24 20:31 ID:qNEckRqU

Java is a useful yet verbose and ugly language. The libraries it has are set out sort of ok, anyway I find it amusing for coursework because at least you emulate functional programming.

Python,
ONE WORD,
 THE FORCED INDENTATION OF CODE,
  THREAD OVER!


brainfuck is a beautifully elegant gem of programming but idiots like >>2 cant appreciate it

and of course, lisp is superior http://www.paulgraham.com/hundred.html

Name: Anonymous 2007-04-24 21:10 ID:2i4Y1DNA

Brainfuck is the only one of those three that's touring-complete.

Name: Anonymous 2007-04-24 21:40 ID:qNEckRqU

>>5
whats touring-complete?

Name: Anonymous 2007-04-24 22:19 ID:i1BM2VAN

>>5 I LOLed.

Name: Anonymous 2007-04-25 2:21 ID:FnUmtpzy

>>6
The correct spelling for turing-complete. The world was wrong and 4chan is always right.

Name: Anonymous 2007-04-25 2:42 ID:WHkU4Y7B

>>8
stop trolling

also, QUACK

Name: Anonymous 2007-04-25 3:34 ID:FnUmtpzy

>>9
stop lying.

Name: Anonymous 2007-04-25 7:36 ID:404aoXXF

Brainfuck is a Turing tarpit, and a Touring tarpit. Only for lulz.

Java is a piece of shit of a language (good syntax, but stupid object model, stupid operators, stupid lack of features such as operator overloading, stupid constraints, stupid static typing) with a piece of shit of an API (extensive and useful, but completely insane, overengineered, ridiculous, full of enterprise-grade best-practices that create synergy between business logic and operative cost). Productivity will suck, and it may very well be even worse than C.

Python is a quite good languge with a feature set similar to that of Ruby and, to a lesser scale, Lisp. It has a clean syntax (good looking save for __, easy to read, forces idiots to indent statement blocks though nothing else) and a powerful object model, and supports structured, OO and functional programming. It comes with an extensive and useful API that's usually simple to use. Get things done very fast, and good execution speed for an interpreted dynamic languge. Also, QUACK.

Name: Anonymous 2007-04-25 8:48 ID:OurY95A9

ECMAScript 4 is better than all of them.

Name: Anonymous 2007-04-25 10:24 ID:XE9ELJVe

>>11
did you say forces idiots to indent..


DID YOU SAY FORCED INDENTAATION OF CODE??

I THINK THREAD IS OVER

also JAVA programmers use a language so fucking verbose they dont mind using  a build system which rqeuires them to write XML files

Name: Anonymous 2007-04-25 10:31 ID:IZnYf7Az

I used to think Java was pretty cool. Now I have to use it all the time for uni projects.. If real programming jobs are like this, I will become an hero.

Name: Anonymous 2007-04-25 11:02 ID:eBsE8c7r

>>14
Yes, real programming jobs are like this.
real programmers do programming for a hobby and not to get paid.

Name: Anonymous 2007-04-25 11:29 ID:x2wGFFqe

>>14
get used to fapping to multi-platform, enterprise-grade, scalable solutions to produce synergy using the industry standards

Name: Anonymous 2007-04-26 6:00 ID:UV3pGa0T

>>15
Truth

Name: Anonymous 2007-04-26 6:08 ID:E2YYEntS

>>14

You'll be pleased to know that not all real programming jobs are Java wankfests. But far too many are.

True story, one of my friends had a mental breakdown from having to program Java every day, for 70+ hours a week (he worked in London in the financial sector, they love long hours there)

Name: Anonymous 2007-04-29 15:53 ID:gSxLSN9T

>>4
GTFO. How can you say Java lets you emulate functional programming? It lets you do object-oriented. You obviously have no idea what functional programming is. Python, on the other hand, is multi-paradigm, and lets you try your hand at functional programming.

Name: Anonymous 2007-04-30 3:43 ID:Mz6NxB8Y

>>19
java.lang.reflectiowned!

Name: Anonymous 2007-04-30 15:49 ID:JLIUaydy

python takes away all your power because it's sad excuse for functional programming is not supported  by Guido van faggot Russo or whatever the fuck and it is dog slow.

Name: Anonymous 2007-04-30 15:58 ID:pLvBtLNK

>>21
Learn to fucking spell. I had to read your post three times to understand what you are trying to say (protip: there's a difference between `it's' and `its'). Anyway, Python indeed sucks really badly for functional programming, and that's a very sad thing. Python itself is pretty useful though, mostly due to the hueg number of do-what-I-want libraries.

Name: Anonymous 2007-04-30 16:14 ID:LLFBVlcK

Python doesn't have lambda's anymore. End of story.

Name: Anonymous 2007-04-30 16:38 ID:Mz6NxB8Y

>>23
ONE WORD, FORCED LACK OF LAMBDAS, THREAD OVER

Name: Anonymous 2007-04-30 16:49 ID:pLvBtLNK

>>23
Python lambdas have always sucked so badly that they have been almost useless. Are they actually going to be dropped in 3K?

Name: Anonymous 2007-04-30 20:49 ID:RmMdNz80

>>21
You can bash Guido for not liking FP much, but Python is the fastest of the modern dynamic languages (at least the barely popular ones).

>>23
Lies

>>25
They're going to be dropped to /opt.
Nah, they'll stay exactly as they are. Guido said so.

Name: Anonymous 2007-05-01 6:07 ID:ZmWZXdsP

>>26
but Python is the fastest of the modern dynamic languages

------------------
$ time python <<EOD
i = 0
while i != 100000000:
    i = i + 1
print i
EOD
100000000

real    0m37.950s
user    0m37.230s
sys     0m0.050s

------------------
$ time perl <<EOD
for (\$i=0; \$i != 100000000; ++\$i ){}
print \$i;
EOD
100000000
real    0m20.060s
user    0m19.890s
sys     0m0.010s
------------------
$ time php <<EOD
<?php
for (\$i=0;\$i !== 100000000; ++\$i);
echo \$i;
?>
EOD
Content-type: text/html; charset=utf-8

100000000
real    0m11.167s
user    0m10.910s
sys     0m0.020s
------------------

Versions:
Python 2.4.3
PHP 5.2.1 (cgi-fcgi)
Perl v5.8.8

uname -a:
Linux Emilie 2.6.20-gentoo-r7 #1 Sun Apr 29 09:52:13 CEST 2007 x86_64 AMD Athlon(tm) 64 Processor 3500+ AuthenticAMD GNU/Linux

Name: Anonymous 2007-05-01 6:09 ID:2+gDRZ+M

Lisp is the fastest of the modern dynamic languages.

Name: Anonymous 2007-05-01 6:37 ID:nXrhTwoy

JScript .NET is the fastest of the modern dynamic languages.

Name: Anonymous 2007-05-01 7:22 ID:Heaven

Use Assembler.

Thread over desu~.

Name: Anonymous 2007-05-01 7:22 ID:+g9m3NvU

Haskell is the fastest of the modern static languages.

Name: Anonymous 2007-05-01 7:29 ID:5HSVbBGx

Machine code is an interpreted language.

Name: Anonymous 2007-05-01 7:34 ID:ZmWZXdsP

>>30
Could assembly (and machine code) be said to be a dynamic language because you can access the data as any type you want it to be?

Name: Anonymous 2007-05-01 8:22 ID:nXrhTwoy

JScript .NET is the fastest of the modern static languages.

Name: Anonymous 2007-05-01 8:24 ID:ehjjvnxF

>>29,34
lol

Name: Anonymous 2007-05-01 8:50 ID:ZmWZXdsP

$ cat >> count.hs << EOD
* count :: Int -> Int
* count i = if i == 100000000 then i else count (i+1)
*
* main = putStrLn (show (count 0))
* EOD
$ ghc --make count.hs -o count
Chasing modules from: count.hs
Compiling Main             ( count.hs, count.o )
Linking ...
$ time ./count
100000000

real    0m10.569s
user    0m10.560s
sys     0m0.010s

$ cat > count.c <<EOD
* main() {
*    int i;
*    for(i=0;i!=100000000;++i);
*    printf("%d", i);
* }
* EOD
$ gcc -o count count.c
$ time ./count
100000000
real    0m0.399s
user    0m0.400s
sys     0m0.000s
$ gcc -O3 -o count count.c
$ time ./count
100000000
real    0m0.003s
user    0m0.000s
sys     0m0.010s

Name: Anonymous 2007-05-01 9:25 ID:2UqWc0AY

>>33
Even though you can treat any sequence of bytes in assembly as whatever type you like, whenever you want without indicating that intent, it's not strictly "dynamic" because there is no automatic type conversion.  There really isn't any types at all.  The only notion of types that assembler has is the difference in some math instructions, which vary depending on data length and whether it's signed or not.  FP instructions are also different than integer instructions.  But your original data can be any type and the assembler nor the program won't bitch, notice, or even care.  Pretty much the only built-in type conversion available period is offered by some sign extend instructions like CBW, CWD, CDQ.  (There are instructions available to help convert binary to ascii or BCD but they need other instructions).  You have to manually do any type conversion yourself.

Name: Anonymous 2007-05-01 9:25 ID:5HSVbBGx

>>33
No. What you described is weak typing. Dynamic typing != weak typing.

Name: Anonymous 2007-05-01 9:29 ID:ZmWZXdsP

>>37
>>38
Ok, thank you both.

Name: Anonymous 2007-05-01 10:45 ID:2+gDRZ+M

>>31
OCaml is the fastest of the modern static languages.

Name: Anonymous 2007-05-01 10:54 ID:Heaven

>>26,28,31,40
those languages aren't modern.

Name: Anonymous 2007-05-01 11:34 ID:+g9m3NvU

>>36
Let's do something that can't be optimized away:
% seq 1 1000000 | tee sorted | shuf > shuffled
% cat > Sort.hs
module Main where
import Data.List (sort) -- Pure Haskell implementation: http://darcs.haskell.org/ghc-6.6/packages/base/Data/List.hs
main = readFile "shuffled" >>= return . unlines . map show . sort . ((map read) :: [String] -> [Int]) . lines >>= writeFile "unshuffled"
^D
% ghc -O9000 Sort.hs --make -osort
% time sort
./sort  59.82s user 1.70s system 100% cpu 1:01.52 total

I'm too lazy to write something in C, of course.  Oh, and copying the sorted file or generating a list of numbers is cheating.  And this code sucks of course, read is slow as hell.

Name: Anonymous 2007-05-01 21:35 ID:ySgzKHvm

>>27
Try a real application.

However, I was surprised at PHP 5's performance so I've done a more realistic test (n times more realistic than yours, n times less realistic than reality; n is a large number).

It consists of a function f(n) -> list of primes up to n, using a simple algorithm. It involves nested loops, simple Maths and list concatenation. Code available below results. Tested on Win32 for 500000 primes.

PHP 4.3.11: 17.078 s
Perl 5.8.7: 11.453 s
PHP 5.2.2RC2: 7.750 s
Python 2.4.2: 6.437 s
Python 2.4.2 + Psyco: 1.141 s
g++ 3.4.2 MinGW -O0: 0.625 s
g++ 3.4.2 MinGW -O3 -funroll-loops: 0.515 s

Important things to see:
1. PHP 5 has got a massive improvement in performance. Now it outperforms Perl, and it's closer to Python than it's to Perl.
2. Python is still the fastest.
3. Python + Psyco is half as fast as C++ for intensive computation, offering a language that's vastly more powerful and flexible, ridiculously more productive, and easier to learn.
4. CFLAGS JUST KICKED IN, YO!

-----------------------

Sauce:

PHP:

<?php
function Primes($max) {
    for ($i = 1; $i <= $max; ++$i) {
        $prime = true;
        $limit = (int) sqrt($i);
        for ($j = 2; $j <= $limit; ++$j)
            if (!($i % $j)) {
                $prime = false;
                break;
            }
        if ($prime)
            $a[] = $i;
    }
    return $a;
}

Primes(500000);
?>


Perl:

sub Primes {
    @a = ();

    $max = @_[0];
    for ($i = 1; $i <= $max; ++$i) {    
        $prime = 1;
        $limit = int(sqrt($i)) + 1;
        for ($j = 2; $j < $limit; ++$j) {
            if (!($i % $j)) {
                $prime = 0;
                last;
            }
        }
        push @a, $i if $prime;
    }
           
    return @a;
}


Primes(500000);


Python:

from math import sqrt

def Primes(max):
    a = []
    for i in xrange(1, max + 1):
        prime = True
        for j in xrange(2, int(sqrt(i)) + 1):
            if not i % j:
                prime = False
                break
        if prime:
            a += [i]
    return a


Primes(500000)


C++ (by Anonymous):

#include <vector>

std::vector<int> primes(int max) {
  std::vector<int> a;
  int limit(1);
  for (int i(1); i <= max; ++i) {
    bool isPrime(true);
    int newLimit = limit + 1;
    if (newLimit * newLimit <= i) ++limit;
    for (int j(2); j <= limit; ++j) {
      if (!(i % j)) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) a.push_back(i);
  };
  return a;
}

int main() {
  std::vector<int> v = primes(500000);
}

Name: Anonymous 2007-05-01 21:47 ID:eDA9mLes

>>43
The Python version could be optimized a bit with for/else.

def Primes(max):
        a = []
        for i in xrange(1, max + 1):
                for j in xrange(2, int(sqrt(i)) + 1):
                        if not i % j:
                                break
                else:
                        a += [i]
        return a

Name: Anonymous 2007-05-01 21:58 ID:ySgzKHvm

>>44
Thanks, updated:

PHP 4.3.11: 17.078 s
Perl 5.8.7: 11.453 s
PHP 5.2.2RC2: 7.750 s
Python 2.4.2: 6.313 s
Python 2.4.2 + Psyco: 1.140 s
g++ 3.4.2 MinGW -O0: 0.625 s
g++ 3.4.2 MinGW -O3 -funroll-loops: 0.515 s

Psyco didn't benefit from this; the specialized code must be the same.

Name: Anonymous 2007-05-01 22:48 ID:qbOW1DqZ

Haven't you guys ever heard of this? http://shootout.alioth.debian.org/gp4sandbox/

It covers all that, and a whole lot more. I thought everyone and their dog has seen it.

Name: Anonymous 2007-05-02 1:20 ID:jo+cNYf0

>>45
Weird, for me it's the other way around.

Perl 5.8.8: 13.819s
Python 2.4.3, v1: 7.686s
Python 2.4.3, v2: 7.601s
PHP 5.2.1: 6.572s

Probably has something to do with Lin/Win, CFLAGS, and 64bit.

And:
Psyco only runs on Windows and Linux 32-bit Intel-based machines
So that doesn't really matter for me.

Name: Anonymous 2007-05-02 1:26 ID:AmyrZpU7

Here's a slightly rewritten Perl version. Most of the differences are purely aesthetic, but it gets a decent boost simply from converting the inner for loop to foreach (15s to 9s on my machine):

sub Primes {
    $max = shift;
    @a = ();

    RN: foreach $i (1 .. $max) {
        foreach $j (2 .. sqrt $i) {
            next RN unless ($i % $j);
        }

       push @a, $i;
    }

    @a;
}

Primes(500000);

Name: Anonymous 2007-05-02 16:59 ID:1AFBFp9I

>>45
You're using a release candidate of PHP, but not even the lastest stable Python or Perl?

I'd be interested to see the latest stable of each (Python 2.5.1, Perl 5.8.8, and PHP 5.2.1) compared. If you can't resist using unstable, then use the lastest of each, although I think it's a bad idea.

Name: Anonymous 2007-05-02 18:40 ID:uSeM9WGs

>>49
Yeah, sorry, I'm lazy. I used the Python, Perl and PHP I had right now (on my Windows 2000, 2.4.2, 5.8.7 and 4.3.11), but I also downloaded PHP 5.2 because I was curious about its supposed awesome improvement. I know a more serious benchmark should compare the latest of all.

Anyways, I have to admit PHP has got pretty fast. I'd like to see how it fares against Python for large applications, but it's very hard to compare.

Name: Anonymous 2009-01-14 13:38

JAVA fails

Name: Anonymous 2010-11-15 20:51

Name: Anonymous 2010-12-28 4:25

Name: Sgt.Kabu爎肨kiman鬻阃 2012-05-29 0:44

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List