Live data from Hacker News

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

codeconfessions.substack.com

81–90 of 224 posts

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

#81

Earlier quoted context omitted.

My uBO didn't catch them for the record. I just added the following rule to be sure: substack.com##[class^="frontend-components-SubscribePrompt-"]

Thanks for that filter. I was trying to make one on my own, but couldn't quickly figure out the documentation. How did you learn making these?

If you have no knowledge you can still make use of element picker in the context menu. In this case though the problematic element will have a generated class name like `frontend-components-SubscribePrompt-`, so I resorted to the CSS syntax (`##`). There are a lot, a freaking lot of them [1] but the CSS syntax alone can achieve a lot.

[1] https://github.com/gorhill/uBlock/wiki/Static-filter-syntax

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

#82
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 methods.

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

#83
post #63
post #42

Earlier quoted context omitted.

It still isn't simple #! /Usr/bin/python Print(a+b) V #include 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

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!

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

#84
post #61

[flagged]

Isn't that just the Substack default? so much better than Medium's or others, at least it closes. Besides, Substack is one of the more writer-friendly platforms re: take-home-pay and no ads, so maybe reconsider?

At risk of being condescending, 50% of the platform's job is also being reader-friendly. If it can't achieve that, then it's not very well-designed. Some people have said it has a nicer nag than Medium, though surely we can do much better and have no nagging when you're in the middle of reading an in-depth technical article?

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

#85

Earlier quoted context omitted.

Sometimes it seems like they do need to be opposed. For the writer to get paid, the reader needs to be asked to pay, or exploited quietly. I don’t know a way out :(

It's not about what, it's about when though — like the GP, I got a pop-up fairly immediately before I'd engaged in the article so I just closed the tab. The best time to engage me is after I've enjoyed the article and hopefully interested to hear more from the writer rather than immediately landing on the page. It's the equivalent to sales staff jumping on customers in shops the minute they walk in the door — "can I…

"I would rather not read this article than have to click a button" is an interesting level of entitlement. Hope you never had your fingers stained by the ink when reading the newspaper, you probably would have sued the New York Times.

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

#87
post #61

[flagged]

As disrespectful and annoying as it is, don't sites do this because it's a net gain in conversions for them? I think we're a minority here. At scale, do not the masses submit to these popups and end up converting into sales?

To echo another person in the thread, surely the best time to engage someone is at the end, when they've finished reading a (hopefully) substantive article, and want to stay engaged with the writer. Not after a few paragraphs.

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

#88
post #61

[flagged]

As disrespectful and annoying as it is, don't sites do this because it's a net gain in conversions for them? I think we're a minority here. At scale, do not the masses submit to these popups and end up converting into sales?

You’re partly right. If anyone signs up at all, then it’s a net gain in ‘conversions’. But it’s not a majority at scale, and it doesn’t have to be anywhere close in order to work. Typically only a small minority of visitors convert to being email subscribers, and then only a small minority of those email subscribers convert into paying customers. It’s not uncommon for the paying customers at the bottom of the funnel to be in the single-digit percent of visitors, or less, and the people annoyed by popups who leave to be the overwhelming majority.

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

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

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…

Recent CPython development has been towards optimizations and addressing use cases that benefit from optimizations, some coming from the faster CPython initiative. You might just get your JIT[1].

At the same time, I also agree with your sentiment.

[1] https://github.com/faster-cpython/ideas/wiki/Workflow-for-3....

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

#90

Earlier quoted context omitted.

https://www.reddit.com/r/Python/comments/mgi4op/comment/gswg... I’d use “thoroughly disproven” rather than “disputed”. I’m sure the hash function can be changed, but as various comments noted: - the benchmark was nonsensical - cpython caches string hashes, and “symbols” are interned, so outside of dynamic attribute access from dynamically constructed strings each hash for attribute purposes or namespace lookup is com…

Rust is doing something even more subtle here than just making the hash function a container property. There are two inter-related Rust traits, Hash is a trait which types implement to explain abstractly how to hash that type, but it's written in terms of a Hasher trait so you can drop in a different function with the same API. The Rust standard library provides a derive macro for Hash, so most people can just gestur…

We can get into the weeds about the details, but what I'm talking about is mostly that in Python (and in most languages really, AFAIK Ruby, Java, or C# are the same to list just a few) objects have to return the hash itself, so the hash function is fixed by the type.

In Rust, the Hash trait is only used to feed data to a hasher such that the type can decide what should be hashed. The creation of the hasher is done by the collection, and thus provides better opportunities / flexibility in customising the hash function.

Post reply on HN