Live data from Hacker News

How many lines of C it takes to execute a + b in Python

codeconfessions.substack.com

121–130 of 224 posts

Re: How many lines of C it takes to execute a + b in Python

#121
post #113

Earlier quoted context omitted.

In my eyes, "good software" does not necessarily just mean something that accomplishes its goals. You can set a goal of being bad, and that's kind of what CPython is doing. Of course, "good" and "bad" are relative. If you don't care about performance then there's nothing wrong with CPython.

I agree with that estimate, I think it was really the idea of Python to be less than "good" by design. I mean one doesn't need more than: >>> exit Use exit() or Ctrl-D (i.e. EOF) to exit to see. They have that special handling, but they still don't want to let you out, because... IMO, they just want to be annoying. When a solution could be something like: Note: exit() is needed in scripts. In this prompt Ctrl-D (i.e.…

There has been discussion of this change a few times, e.g. https://bugs.python.org/issue44603

I generally agree with your overall sentiment, but I think it's important to note that the behavior is _not_ special handling; it's just the normal `repr` behavior at the REPL, where `exit` is an object like any other, and `repr(exit)` is that message.

Re: How many lines of C it takes to execute a + b in Python

#122

Earlier quoted context omitted.

The semantic issues of making a performant Python language implementation are more or less exactly the same as for JS and Lua, optimizing Ruby seems to possibly have even more "magic" that needs patching but we've seen the Shopify team get cracking on that (it includes MaximeCB that did HiggsJS). PyPy is in many aspects to be rated as a research project that tried a novel approach to reduce the workload compared to t…

Unfortunately Python's innard is much more complicated than most expectations. You have named JS and Lua, but those languages never have "magic" methods---JS instead has prototypes and more recently proxies, while Lua has metatables. Ordinary objects aren't magic in this sense, and conversely magical objects are generally deliberate choices in those languages. But Python's magic `__dunder__` methods are everywhere in…

In the late 1990s and early 200xs, there were a lot of claims that there was no such thing as a "slow language", that all languages can be run as quickly as C if you just built a sufficiently smart compiler and/or runtime.

I haven't heard anyone make this claim in a while. The inability to speed up Python beyond a certain point despite a lot of clever approaches taken was probably a good chunk of the reason, the remainder being the wall that JS has hit despite the huge effort poured into it where it is still quite distinctly slower than C.

If I were designing a language to be slow, but not like stupidly slow just to qualify as an esolang, but where the slowness still contributed to things I could call "features" with a straight face, it would be hard to beat Python. I suppose I could try to mix in more of a TCL-style "everything is a string" and "accidentally" build some features on it that bust the string caching, but that's about all I can think of at this point.

Re: How many lines of C it takes to execute a + b in Python

#123
post #17

Earlier quoted context omitted.

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.)

> 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…

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 + b in Python

#124
post #4

A while back someone posted their patch to cpython where they replaced the hash function with a fast one and claimed this dramatically sped up the whole Python runtime. They claimed that the hash function was used constantly —e.g. 11 times in print("hello world")—because it's used to look up object properties. Apparently the default implementation is not optimized for performance but for security, just in case the so…

So your solution to if statements is to add more if statements?

Re: How many lines of C it takes to execute a + b in Python

#125
post #113

Earlier quoted context omitted.

I agree with that estimate, I think it was really the idea of Python to be less than "good" by design. I mean one doesn't need more than: >>> exit Use exit() or Ctrl-D (i.e. EOF) to exit to see. They have that special handling, but they still don't want to let you out, because... IMO, they just want to be annoying. When a solution could be something like: Note: exit() is needed in scripts. In this prompt Ctrl-D (i.e.…

Yeah, that message is a pet peeve of mine. Like, you know what I'm trying to do.

It sort of doesn't! It's just doing exactly the same thing it would do with any other identifier: it's printing its `repr`. Try `repr(exit)`!

Re: How many lines of C it takes to execute a + b in Python

#126

Earlier quoted context omitted.

The semantic issues of making a performant Python language implementation are more or less exactly the same as for JS and Lua, optimizing Ruby seems to possibly have even more "magic" that needs patching but we've seen the Shopify team get cracking on that (it includes MaximeCB that did HiggsJS). PyPy is in many aspects to be rated as a research project that tried a novel approach to reduce the workload compared to t…

Unfortunately Python's innard is much more complicated than most expectations. You have named JS and Lua, but those languages never have "magic" methods---JS instead has prototypes and more recently proxies, while Lua has metatables. Ordinary objects aren't magic in this sense, and conversely magical objects are generally deliberate choices in those languages. But Python's magic `__dunder__` methods are everywhere in…

Lua has metamethods: https://www.lua.org/manual/5.3/manual.html#2.4

Re: How many lines of C it takes to execute a + b in Python

#127
post #51

It seems like it doesn't answer it's own question, so I'll pose another. The entire Lua core is 15kLoC. Is that more than or less than what's needed for python's "a + b", assuming a and b are defined. I'm genuinely curious.

Yes, it's a very tootsie-roll-center kind of answer, but it's clearly more than a few. To answer your question, 15kLoC is more than enough to implement dynamic dispatch and the PyObject base struct, along with the special method logic for __add__ on any python object type.. but still a lot less than what's needed for all the special method types and a lot of boilerplate for the C-compatible interface around those met…

I wonder what percent of this audience got the tootsie-roll reference. Does anyone under 40 know it?

Re: How many lines of C it takes to execute a + b in Python

#129

Earlier quoted context omitted.

This may be a somewhat uninformed opinion, but I think CPython is just straight up not particularly good software. There are a million and one optimizations that other major scripting runtimes (V8, LuaJIT, PyPy, Ruby YJit etc.) have had for years that CPython is lacking. This is by design though. CPython has never been focused on performance, that's why it's not even JIT. It optimizes for simplicity and easy interope…

It's great software for the use case that Python is intended for . Python is supposed to be glue code. You embed a scripting runtime in your application, do all the heavy lifting in C, but configure your building blocks in Python so that you can easily reconfigure them as needs change. NumPy, SciPy, TensorFlow, PyTorch, JAX, Pandas, Pillow, lxml, cjson, PyCapnP, Tornado, fast-avro, etc. all get it right. They are wra…

I've been playing around with HTMX with Django, and it seems simple enough for server side rendering. It works well with the Django templating system.

I feel like as an industry we should step back and take a serious look at front end frameworks from first principles. One aspect that's clear to me, is that we should make modifications to HTML to support HTMX like transactions.

Re: How many lines of C it takes to execute a + b in Python

#130

Earlier quoted context omitted.

Pop-up windows that take focus over other running applications are a whole another ball game, dude. In-app popups are a pattern that may or may not be annoying, like most things used well or badly. This case seems pretty innocuous to me.

No, they are always annoying. I'm here to read an article, the only thing this pop-up window does is get in my way.

[deleted]
Post reply on HN