Live data from Hacker News

To learn a new language, read its standard library

patshaughnessy.net

161–170 of 243 posts

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

#161
post #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.

Optimized code is not an anti pattern! What is an anti pattern is premature optimization, code you write a certain way because you think it is optimized but because you don't understand the compiler and hardware, it is not.

Optimizations in standard libraries are generally good ones, and reading it can give a good idea of what is or isn't worth it.

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

#162
I do not think an advice like this is applicable to any programming language out there. For example, I find it hard to apply to languages which have long history and change a lot over time, like Python or Java (or C++ as mentioned in other comments). I can easily imagine parts of the standard library being written long time ago, with many modern features not available back then.

For example, I do not think it is possible to learn modern Java by reading Java Collections code. You won't see Optional being used there. Instead, your takeaway might be that it is perfectly fine to return nulls all over the place.

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

#163
post #161
post #139

Earlier quoted context omitted.

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

Optimized code is not an anti pattern! What is an anti pattern is premature optimization, code you write a certain way because you think it is optimized but because you don't understand the compiler and hardware, it is not. Optimizations in standard libraries are generally good ones, and reading it can give a good idea of what is or isn't worth it.

I think the comment simply stated that when learning a language you should focus on idiomatic code and not optimizations. The latter which is probably present and justified in a standard library.

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

#164
My advice would be: to learn a new language, simply start writing some non-trivial projects in it (a few thousand lines of code or so). In some languages (like Python), the standard library is the actually important feature, in other languages (like C), it's better to mostly ignore the stdlib. Example: I started learning Zig by writing a Pacman clone (https://github.com/floooh/pacman.zig) and a home computer emulator (https://github.com/floooh/kc85.zig), the Pacman clone doesn't use any Zig stdlib features at all, and the emulator only minimally for memory allocation, parsing command line args and loading data from files.

Zig's stdlib is much more useful than C's, but it's still entirely possible to write useful programs without it and instead focus on learning Zig's language features first.

But on the other extreme, the whole reason why I learned Python was its "batteries included" standard library.

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

#165
post #158

Completely agree. Once you learn enough languages, it all starts blending together and looking more or less the same. Same control structures, same functions, same structures, same classes, same objects, same lists, same hash tables, same pretty much everything. There's usually a few innovations and peculiarities here and there but it's not that much. The bulk of the language is actually the standard library. The API…

I think the Scheme quote is interesting, because it almost applies to C. Most people consider learning C hard (for example, compared to python), but it is an extremely small language with a "standard library so small it's pretty much useless".

What makes C somewhat hard to learn is pointers and strings. Apart from that it's so small that most fulltime C developers will touch upon the entire language on a regular basis.

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

#166
post #89

This is a classic academia-ish take. Consume a bunch of theory and regurgitate whatever you've read. Better way to learn is making stuff with the language, having actual skin in the game. Only then bounce back to theory on the more nuanced stuff.

Standard libraries are very concrete, not academic at all. Learning the standard library means learning how to open a network connection and making an HTTP request to some server. The language becomes useful and gives results immediately. Theory means stuff like language concurrency models, it becomes important once you start considering how to structure the code at a high level. How do I use this language to handle…

That highly depends on which language and standard library you are talking about.

Reading C++ standard library gives you headache, and doesn't really teach you how to write C++ in a normal application. For a beginner, this is an impossible approach.

Reading Python standard library means reading C half of the time. Useful for some seasoned Python developers, but not for new comers who want to read Python.

At the end of the day, standard libraries aren't written to teach, and some being a good teacher is a coincident. When you are learning a new language, you really have no idea whether the standard library is a good source for beginners.

I'd suggest a less poetic, more pragmatic approach to learning a new language: ask the most active forum of the language, and use the most common learning materials.

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

#167

I do not think an advice like this is applicable to any programming language out there. For example, I find it hard to apply to languages which have long history and change a lot over time, like Python or Java (or C++ as mentioned in other comments). I can easily imagine parts of the standard library being written long time ago, with many modern features not available back then. For example, I do not think it is poss…

What's a good way to learn about the proper way of writing java 11 in 2021 / 2022 ? I'm currently trying to escape writing java 1.5 style code in java 8.

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

#168

I do not think an advice like this is applicable to any programming language out there. For example, I find it hard to apply to languages which have long history and change a lot over time, like Python or Java (or C++ as mentioned in other comments). I can easily imagine parts of the standard library being written long time ago, with many modern features not available back then. For example, I do not think it is poss…

> You won't see Optional being used there.

I think Rust is in a category of it's own, mostly due to circumstances rather than anything: The ecosystem has grown immensely over the past several years and you can find a crate to solve most of your needs. But here is where thing become tricky: more often than not the documentation provided is extremely vague to put it mildly and the examples are a hello world at best. With this in mind, in order to truly use it you have little to no choice but to dig deep into the implementation and at some point reach the standard library.

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

#169

Earlier quoted context omitted.

Better really depends on who you are. Born academics can learn better by reading foundation libraries and principles, and they write articles advising others to do the same :-) What you described as better could be a really good fit for business-first coding opportunists who would get annoyed by perceived inefficiencies and petty politics in academia... The article is a terrific example of basic analysis BTW. This un…

No, even academia and pure theorists could take a fresh perspective with actual skin in the game in making software. > The article is a terrific example of basic analysis BTW. Hahaha. It's some cherry picked examples and you're already claiming it's 'a terrific example of basic analysis'. The hyperbole is real in software.

Reminds me of Nassim Taleb's works. Reading and rereading the standard library is a good way to learn a language or get depth. I don't see how reading an actual implementation can be considered academic, as it is real-life engineering. It is not pseudocode or theory, some algorithms in Java and C++ are using some ugly shortcuts that only an engineer would find interesting while an academic would think it's heresy.

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

#170
post #122

Earlier quoted context omitted.

Hm, by that measure no one would write OOP in C++.

which would be fine because C++ is not an OOP language ?

What do you mean? The entire premise behind the design and creation of the C++ language was to add object oriented features to C.
Post reply on HN