Hacker News new | ask | show | jobs
by oreally 1699 days ago
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.

4 comments

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 X requests concurrently, hopefully in parallel?
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.

I don't think this is a good read. A standard library is very concrete - it's the core of the language in action, and the shape that its code takes will likely be repeated regularly in 3rd party code written in that language. There's nothing academic or abstract about it.

EDIT: As others note, a good chunk of a stdlib may involve system interop that isn't representative, so that tempers my comment with regards to whether that code is idiomatic. But my case still stands regarding concrete vs. abstract.

Here is a basic structure implemented in C++:

https://github.com/llvm-mirror/libcxx/blob/master/include/ve...

I would not recommend anyone ever look through that as a way to learn C++. Heck just something as basic as a struct that stores two member variables is a 200 line of code horror show in C++:

https://github.com/llvm-mirror/libcxx/blob/78d6a7767ed57b501...

Here is a basic struct that stores two members in C++:

struct foo { int a; int b; };

That's all. The thing you refer to is not a 'basic struct', it's complex standard library component.

Yes, in C++, a pair of member variables is a complex conponent. That is my point.
No, in C++, a pair of member variables is what I wrote.

C++ has enough complexity already, there's no need for you to add additional false claims. The thing you pointed to is the standard library version of std::pair, written to be as platform-independent, performant and correct as possible. But if, as a programmer, you need a 'simple struct with two elements', as you described it, you just define a struct and add the two elements, and that's it. Or you just declare it as std::pair<int, int>.

Your statement that declaring a struct with two members in C++ takes 200 lines is just completely false.

You are completely ignoring the context of this discussion to make an irrelevant point and doing it in a way that ironically supports my position.

If one wishes to learn how to represent a pair of values in a generic, cross platform and efficient manner, one should NOT consult the standard library to learn such a thing precisely because the standard library includes incredibly irrelevant and archaic details that are entirely unneeded to understand how to idiomatically represent a pair of values.

Your claim that the standard library is written to be cross platform couldn't be further from the truth. The standard library is written to work with a specific compiler, and often times only with a specific version of a compiler on a specific platform. While it's possible to use libstdc++ with clang, it's not possible to use libc++ with GCC. Furthermore no compiler other than MSVC fully supports MSSTL.

The idea that the C++ standard library is a good way to understand in concrete and idiomatic terms how to represent a generic pair of values is simply bad advice.

If you wish to counter that position then you are welcome to do so, but so far you are arguing something entirely different from the actual topic at hand. The argument I'm making isn't that you need 200 lines of code to represent a pair of values, it's that if you tried to understand how to represent a pair of values by consulting the standard library, you'd need to sift through 200 lines of code because the standard library is written in an incredibly complex manner that is entirely unnecessary in order to learn or understand idiomatic C++.

In short, the statement " To learn a new language, read its standard library", is bad advice for someone who is new to learning C++.

Well, that's still instructive about how library code that aims to be efficient and portable has to look in C++. It's not representative of most application / business layer code, and it's definitely not good learning material.

But, if choosing C++, at some point you will have to write code like that as a project matures and must target different compiler versions and platforms.

No, at no point should you use the standard library to understand how to write C++ code. The standard library has a specific clause in the C++ standard that exempts it from rules about undefined behavior. For example, that link I pasted to implement a std::vector is not something that is permissible to use by non-standard library code, it is full of undefined behavior that is permissible for use by the standard library but not permissible for use by ordinary code.

To the extent that one can learn how to write cross-platform efficient and generic C++ code, there is always a better example to learn from than the standard library.

This is a classic hacker/builder take. Start scratching your own itch and make many apps. /s

To be frank I have the same mindset, but it's good to read other people takes on it. Some prefer to have basic knowledge and feel great anxiety when they're jumping to code without any foundation.

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 underappreciated skill can be a huge blindspot for opportunists...

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.
Cherry picking is 100% compatible with analysis, which is closed subjective logic, not open opportunistic logic. Plus I don't think the author is exactly trying to go head to head with your personal favorite method. Could be wrong though.