Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sounds like it would be easier to just use C anyway.


Yes, but C is a much more arcane and complicated language. Case in point: instead of writing a+b in Python, in C you would have to write a+b

(Jokes aside, it would really be more complicated in C if a and b were actually strings or lists.)


> it would really be more complicated in C if a and b were actually strings or lists

You don't event need strings or lists for that. Just imagine bigger numbers for a and b. Arbitrarily long integer addition is not a native language feature in C.

edit: formatting


to be concrete:

    fac = lambda n: 1 if n<=1 else n*fac(n-1)
    a, b = fac(42), fac(69)
    a + b
is 3 lines of python; how many lines of C code would it take to execute?


One: return 1.7112245243e98

Joking aside: these are not catch-all comparisons. Nor is the article. But Python is mucher slower and much safer than C. It's easier to start in Python than in C.


;-P Just to be pedantic, if you're going to all the trouble to give (modulo lack of a repl) a wrong answer fast, might as well do it really quickly:

    return 0;
in the hopes that compiles down to something like:

    xor rax, rax
    ret


Or numbers that add up to over the size limit of what ever byte/int/long type you are using.

There's a surprising amount of depth to adding two numbers.


> much more arcane and complicated

How much more, though? The conventional wisdom here seems to be that it's worth taking the unavoidable performance hit of dynamically typed scripting languages because the productivity boost to programmers balances it out... but I don't believe I've seen that productivity boost measured. Once you know what you're doing in C, you can do that same things you can do in Python. There's some (fascinating) syntactic sugar in there, but Python can easily be just as incomprehensible as C.


You can become productive in python faster than you can in C. My background is the natural sciences and on reason python is used a lot in these fields is it's ease of use for people not coming from a computer science/engineering background.


a+b in Python adds two numbers. a+b in C adds the numbers if their sum is below a certain size, if not then it's undefined behaviour and destroys the security of your entire program.


It still isn't simple

#! /Usr/bin/python

Print(a+b)

V

#include <stdio.h>

Int main (){ Printf("%i", a+b); Return 0; }

And printf is basically a DSL, so it still isn't 'simple' And this is assuming a+b fits into an integer


If you're being silly you don't need a lot of that:

    $ cat tmp.c
    main() {
       printf("%d\n", 3+4);
    }
    $ gcc -w -o tmp.out tmp.c && ./tmp.out
    7
You can even do away with types entirely, as long as you're working with ints:

    $ cat tmp.c
    foo(x) {
       return x+5;
    }
    bar() {
       return 4;
    }
    main() {
       printf("%d\n", foo(bar()));
    }
    $ gcc -w -o tmp.out tmp.c && ./tmp.out
    9
Rarely a good idea, though!


True, but then someone will pop up and announce UB! (This probably isn't ub though).

Anyway, my main point was that c has more boilerplate. It's never 'a+b'.

Second, printf is complicated, that's aimed more at the op though.


If a and b are strings, Python would make "ab".


C++ otoh is actually more arcane and complicated.


There are plenty of AOT compiled languages, C isn't the only option, thankfully.


It's even easier to just buy a desk calculator or even just learn long addition and do it with pencil and paper.


Actually, I generally recommend to not leave easy tasks to the computer. The brain likes to have to do stuff sometimes.


why waste time?


Easier is exactly what that wouldn’t be


Easier for whom?

The whole point of high level languages is that you put in effort upfront to make everyone elses job easier.

By you logic, using machine code directly onto toggle switches is easiest. No assembler to write, no test editor to write.....


Tell that your average data Joe and he will say "But C is a letter, not a programming language".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: