Live data from Hacker News

To learn a new language, read its standard library

patshaughnessy.net

131–140 of 243 posts

Re: To learn a new language, read its standard library

#131

Earlier quoted context omitted.

Well, if it didn't, they could optimize the compiler by removing those optimizations. :)

That was(is?) the benchmark for gcc optimizations: it has to pay for itself on the compiler: if the resulting compiler code is faster but the added compilation time is even greater, it s not worth it.

I think I first heard of this criterion being used by Niklaus Wirth for Pascal and Oberon compilers.

Re: To learn a new language, read its standard library

#133

Earlier quoted context omitted.

Does that hurt performance of the output?

Well, if it didn't, they could optimize the compiler by removing those optimizations. :)

I think it's pretty clear the GP was asking if the optimizations implemented for x86 that aren't implemented for aarch64 would actually improve performance of generated aarch64 code. It's a question about CPU architecture/microarchitecture. That's a different question as to if the optimizations improve performance of generated x86 code.

For instance, I imagine the x86_64 register allocation does some variant on graph coloring for register allocation, with an additional pass to assign lettered registers (rax, rbx, etc.) to the most heavily used registers, since using higher numbered registers requires a REX prefix byte. In addition, many instructions have more compact encodings when eax/rax is the destination register. At a minimum, excess REX prefixes take up instruction cache space. There's no parallel for aarch64, so there's no sense in implementing logic to try and make sure the low-numbered aarch64 registers are used more. (Though, on 32-bit ARM with Thumb/Thumb2, only a subset of registers are available, so there is a similar optimization for 32-bit ARM targets that support Thumb/Thumb2 when optimizing for space.)

I imagine there are better examples, but my point is that some optimizations are useless on some architectures.

Re: To learn a new language, read its standard library

#135
post #94

Maybe this works for the language that the author is talking about, but in the cases that I'm familiar with, the standard library code does not give a good idea of what "normal" application code looks like. For example it's often got a bunch of platform-specific logic or low level optimizations that, as an application author, you probably want the standard lib to abstract away from you

Agree. I am thinking in C++ you do not want to read the std to learn the language.

Re: To learn a new language, read its standard library

#136

I had a friend who said he enjoyed reading the PickAxe Book ("Programming Ruby") from end to end each year . That includes the whole Ruby stdlib!

I still love Ruby, whereas I have only learned how to be a good colleague with PHP, Java, and JS.

Re: To learn a new language, read its standard library

#137

Earlier quoted context omitted.

Why is that wrong? A language can be multi-paradigm while the “official” documents are written in a specific style. Like human languages, they evolve with their use (or fork into another language completely), while the high literature is the last one to change. Together with that, I agree that one should read the high literature before inventing a new writing style.

> read the high literature The elite language in Rome was Greek.

> The elite language in Rome was Greek.

gee, they didn't have go?

Sure that empire was doomed.

Re: To learn a new language, read its standard library

#138
> To learn a new language, read its standard libraryTo learn a new language, read its standard library

Yes, but also no.

The standard library is often more complex and uses more advanced features then you often need for most projects. I.e. collections in std are supper general purpose, but if you need to write a collection it's normally specific to the purpose you need it for.

I.e. std is the "most" general purpose library you normally find so even if it's written with "KISS" in mind it's still often not so simple.

Then it sometimes uses unstable language features you normally can't use (as it's often made "in sync" with the language) and/or optimizations which in most other cases would count as "pre-mature" optimizations.

Through without a question you can learn a lot there, you just should be aware of the points above.

Re: To learn a new language, read its standard library

#139

> To learn a new language, read its standard libraryTo learn a new language, read its standard library Yes, but also no. The standard library is often more complex and uses more advanced features then you often need for most projects. I.e. collections in std are supper general purpose, but if you need to write a collection it's normally specific to the purpose you need it for. I.e. std is the "most" general purpose l…

Or it even uses patterns which would be considered anti patterns outside of it for the sake of optimizations.

Re: To learn a new language, read its standard library

#140

Earlier quoted context omitted.

It's just a little bit more work to write a non-trivial program in Go than in a scripting language such as Python, so if you need/want the good tooling and you need/want the significant speed improvement, it could be a good choice.

Go doesn’t have the libraries of python however. In certain computing domains you would first have to spend 10 years rewriting the python frameworks in golang before you could even be on parity with python. I am most familiar with scientific computing and GIS applications — python is miles ahead of golang in ecosystem support in those domains.

Naive question, can't you just call Python code from Go? I don't see the problem besides that performance of the Python libs wouldn't be as good as if they were written in Go.
Post reply on HN