5 ms·
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 w
by unnah 3y ago
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.)
- Marazan 3y agoOr 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.
- rhabarba 3y agoIf a and b are strings, Python would make "ab".
- fractalb 3y ago> 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
- 082349872349872 3y agoto 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?
- tgv 3y agoOne: 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.
- 082349872349872 3y ago;-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
- benj111 3y agoIt 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
- jefftk 3y agoIf 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!
- benj111 3y agoTrue, 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.
- __loam 3y agoC++ otoh is actually more arcane and complicated.
- commandlinefan 3y ago> 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.
- someNameIG 3y agoYou 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.
- lmm 3y agoa+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.