3 ms·
The C example has three includes, two conditionals, two loops, and one function definition. The python example has a single include, conditional, and loop. For
by belorn 9y ago
The C example has three includes, two conditionals, two loops, and one function definition. The python example has a single include, conditional, and loop.
For readability purpose it is easier to go through each lines of the python program than the OpenBSD C code. Its not massively different, but its distinguishable enough that I would choose the python version if I wanted to maximize readability, minimize syntax requirement and did not want to use shell script.
The Shell function is in my view the superior choice if the audience is a programmer than know the shell script syntax. It is just a single loop and is written in the environment that the program is intended to be used in. The only drawback there is the speed.
- mikeash 9y agoMost of what makes the C program bigger comes from the fact that the C program does more. Your python example doesn't call pledge(). Remove that from the C program and it drops to one include, one conditional, and two loops. Further, counting the two loops against C doesn't make any sense: it's entirely up to the programmer whether to have a conditional containing two loops, or a loop containing a conditional. Both languages could naturally do it either way.
- teamhappy 9y ago> The python example has a single include, conditional, and loop. ... and python. Don't forget to count python.
- BenjiWiebe 9y agoExactly. That's the reason I write stuff in C instead of my favorite interpreted language, Ruby. When you write something in C, that's it. No large interpreter plus runtime needed.