News for hackers. Stuff that matters.
Re:How Many Lines of C It Takes to Execute a and B in Python? by rhabarba on Monday December 11, 2023 @04:59AM (#38599138)
Sounds like it would be easier to just use C anyway.
Re:How Many Lines of C It Takes to Execute a and B in Python? by unnah on Monday December 11, 2023 @05:47AM (#38599393)
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.)

Re:How Many Lines of C It Takes to Execute a and B in Python? by fractalb on Monday December 11, 2023 @06:00AM (#38599474)
> 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

Re:How Many Lines of C It Takes to Execute a and B in Python? by 082349872349872 on Monday December 11, 2023 @07:02AM (#38599849)
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?
Re:How Many Lines of C It Takes to Execute a and B in Python? by tgv on Monday December 11, 2023 @07:10AM (#38599899)
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.

Re:How Many Lines of C It Takes to Execute a and B in Python? by 082349872349872 on Monday December 11, 2023 @07:49AM (#38600179)
;-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
Re:How Many Lines of C It Takes to Execute a and B in Python? by __loam on Monday December 11, 2023 @08:01AM (#38600262)
C++ otoh is actually more arcane and complicated.
Re:How Many Lines of C It Takes to Execute a and B in Python? by benj111 on Monday December 11, 2023 @07:35AM (#38600070)
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

Re:How Many Lines of C It Takes to Execute a and B in Python? by jefftk on Monday December 11, 2023 @09:21AM (#38600846)
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!
Re:How Many Lines of C It Takes to Execute a and B in Python? by benj111 on Monday December 11, 2023 @10:36AM (#38601507)
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.

Re:How Many Lines of C It Takes to Execute a and B in Python? by rhabarba on Monday December 11, 2023 @05:58AM (#38599452)
If a and b are strings, Python would make "ab".
Re:How Many Lines of C It Takes to Execute a and B in Python? by Marazan on Monday December 11, 2023 @05:55AM (#38599440)
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.

Re:How Many Lines of C It Takes to Execute a and B in Python? by commandlinefan on Monday December 11, 2023 @09:52AM (#38601135)
> 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.

Re:How Many Lines of C It Takes to Execute a and B in Python? by someNameIG on Monday December 11, 2023 @01:31PM (#38603472)
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.
Re:How Many Lines of C It Takes to Execute a and B in Python? by lmm on Monday December 11, 2023 @05:45PM (#38606517)
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.
Re:How Many Lines of C It Takes to Execute a and B in Python? by pjmlp on Monday December 11, 2023 @05:51AM (#38599420)
There are plenty of AOT compiled languages, C isn't the only option, thankfully.
Re:How Many Lines of C It Takes to Execute a and B in Python? by klysm on Monday December 11, 2023 @05:25AM (#38599256)
Easier is exactly what that wouldn’t be
Re:How Many Lines of C It Takes to Execute a and B in Python? by globular-toast on Monday December 11, 2023 @05:29AM (#38599288)
It's even easier to just buy a desk calculator or even just learn long addition and do it with pencil and paper.
Re:How Many Lines of C It Takes to Execute a and B in Python? by rhabarba on Monday December 11, 2023 @05:48AM (#38599398)
Actually, I generally recommend to not leave easy tasks to the computer. The brain likes to have to do stuff sometimes.
Re:How Many Lines of C It Takes to Execute a and B in Python? by llamaInSouth on Monday December 11, 2023 @12:24PM (#38602510)
why waste time?
Re:How Many Lines of C It Takes to Execute a and B in Python? by benj111 on Monday December 11, 2023 @05:14AM (#38599205)
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.....

Re:How Many Lines of C It Takes to Execute a and B in Python? by DarkNova6 on Monday December 11, 2023 @08:55AM (#38600641)
Tell that your average data Joe and he will say "But C is a letter, not a programming language".