r/ProgrammerAnimemes • • May 29 '22

Fixed that certain meme about python

Post image
1.1k Upvotes

59 comments sorted by

View all comments

Show parent comment

4

u/Mast3r_waf1z May 30 '22

At this point why don't you just write C tho?

5

u/[deleted] May 30 '22

[removed] — view removed comment

2

u/Mast3r_waf1z May 30 '22

It's syntax isn't much different from so many other languages though? Most notably just making datatypes optional and replacing curly brackets with indents

2

u/[deleted] May 30 '22

[removed] — view removed comment

5

u/Mast3r_waf1z May 30 '22

Okay but you're just talking about built-in functions that aren't necessarily python specific, if you really needed a sum and range function to be abstracted from your code why not just write your own math library and import that? (I don't wanna Google a ton about libraries in other languages but it probably already exists)

3

u/[deleted] May 30 '22

[removed] — view removed comment

2

u/Mast3r_waf1z May 30 '22

I just gave you an example of what you could do in C if you really needed them abstracted from your own code but it would only really matter if you write bigger programs, you know, you wouldn't write a whole sum function to use it once

1

u/[deleted] May 30 '22

There's also syntactic sugar like list comprehensions, for example to get a list of all integers from 0 to 20 that are evenly divisible by 3:

>>> print([x for x in range(20) if x % 3 == 0])
[0, 3, 6, 9, 12, 15, 18]

Without list comprehensions that would be:

>>> ints = []
>>> for x in range(20):
...     if(x % 3 == 0):
...         ints.append(x)
...
>>> print(ints)
[0, 3, 6, 9, 12, 15, 18]

1

u/Mast3r_waf1z May 30 '22

Sure I know what list comprehension is, for reference i primarily use python myself, but you're just using a built-in function which could have been expressed in a more readable format as you've literally shown yourself

I've had a lot of classmates get very confused by a long comprehension where I've had to rewrite it as a normal for loop to explain it

The nly real advantages I can see from using comprehension is it's speed as I'm pretty sure it is compiled as a single line and that it is easier to pass to numpy

2

u/FierceDeity_ Jun 08 '22

Man that's exactly why I also love Elixir.

1..11 |> Enum.sum |> IO.puts

Putting these operations into a readable order makes it so much nicer to read.

BTW, |> (pipe) literally just takes the return value of an expression and uses it as the first argument to the next function in the pipe

1

u/[deleted] May 31 '22

Because you really should be avoiding C as much as you possibly can unless it's legitimately required by your use-case.

2

u/Mast3r_waf1z May 31 '22

What? Care to elaborate on that? I believe there is a reason why the linux kernel for example isn't written in python despite being possible

1

u/[deleted] Jun 01 '22 edited Jun 01 '22

C is not a good language in a number of ways, many of which are due to performance and resources constraints in the context of its original creation. Its design is not conducive to writing secure or high-reliability software, and any such software written in it is done in spite of its design flaws (and because network effect has made it so that for some platforms proprietary C compilers are the only vendor-provided compilers available at all - so even now you need something that you can at least cross-compile to C to write for them).

Python is an interpreted scripting language, which is generally too slow to reasonably write a useful kernel with (you really want native binaries), it also lacks a certain level of low level access that can be useful in writing an OS. But most importantly, Python lacks a stable standard you can rely on to write your OS, so you're basically relying on some arbitrary canonical implementation that provides you with no long-term guarantees (and it has done many breaking changes in minor version changes, I've had to deal with them at work). Python was [very new](https://en.wikipedia.org/wiki/Python_(programming_language)#History) and unstable when Linux was first created. C++ likewise lacked a standard back then.

Ada. But that would also ignore why C was created to start with.

edit: The importance of that network effect (and thereby portability) is also part of why projects like seL4 bother with writing their microkernel in C despite the fact they really wanted to do it in ML (iirc).