Live data from Hacker News

To learn a new language, read its standard library

patshaughnessy.net

171–180 of 243 posts

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

#171

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…

> To go even further than standard library, read the language's source code. This is especially relevant for virtualized languages.

Yes, reading hundreds of thousands LoCs written in C/C++ is totally viable method of learning languages. ;)

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

#172
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.

A library like Java Collections API sometimes uses optimizations involving bitshift etc which is too confusing for most application level code. So your comment that it's not an anti-pattern to do such things in application code is something I have to disagree with.

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

#173

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.

I'm a big believer in 'when in Rome', not just in languages but life. If you don't like language X, don't take a job writing language X.

I agree 100%. And don't complain about it and try to make it into language 'Y' by duct taping types on to it.

Oh, and Python 3 should've been a new language.

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

#174
post #170

Earlier quoted context omitted.

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.

https://arne-mertz.de/2015/07/c-is-not-an-object-oriented-la...

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

#175
The advice really only applies for very specific definitions of "learn".

Let me cite a single line from the MSVC implementation of the C++ standard library (https://github.com/microsoft/STL/blob/main/stl/inc/xtree):

    using _Scary_val = _Tree_val, _Tree_simple_types,
        _Tree_iter_types>>;
Also, good luck understanding this class member definition. Hope you figured out _Scary_val!

  _Compressed_pair> _Mypair;
(Hint: Empty base class optimization.)

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

#176

Earlier quoted context omitted.

I'm a big believer in 'when in Rome', not just in languages but life. If you don't like language X, don't take a job writing language X.

On the other hand, sometimes it really makes sense to strike out and define a new, higher standard for code style and paradigm in a given language, or at least to improve somewhat on the style and paradigm that's handed to you. JavaScript used to be a messy language "not fit for professional use" (see popular JS books from the year 2000 :shudder:), but it turns out most of the problem was how people were using it. JS…

JavaScript was never a messy language, it was the different browsers that created a horrible situation for using JavaScript in web pages.

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

#177
For C++ many standard library functions can't be implemented in standard C++. And it not only shows some very obvious compiler built-ins in the library, but the library can depend on behavior guaranteed by the compiler which is otherwise undefined by the standard. Therefore it's not always wise to learn techniques from the standard library, as it can depend on implementation defined behavior, and this dependence can be subtle too.

Not too long ago it was impossible to implement std::vector in standard C++, as constructing objects next to each other formally did not create an array. Therefore pointer arithmetic on the resulting pointers were undefined behavior, as pointer arithmetic is only defined within an array.

This was fixed by the array being implicitly created in certain circumstances.

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

#178

Earlier quoted context omitted.

I'm a big believer in 'when in Rome', not just in languages but life. If you don't like language X, don't take a job writing language X.

On the other hand, sometimes it really makes sense to strike out and define a new, higher standard for code style and paradigm in a given language, or at least to improve somewhat on the style and paradigm that's handed to you. JavaScript used to be a messy language "not fit for professional use" (see popular JS books from the year 2000 :shudder:), but it turns out most of the problem was how people were using it. JS…

JavaScript today wouldn't be recognizable to a JavaScript developer 6 years ago, especially when using class syntax, destructing, and async/await, among many other syntax additions.

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

#179

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…

Out of curiosity, Blending together, even different paradigms, like APL, or Haskell?

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

#180
post #116

I find languages are pretty easy to pick up after the first few. What seems to be the barrier nowadays is frameworks. How do people go about learning a new framework? Obviously most of them have an intro project to follow on with, but they tend to be pretty simplistic, and once that's done, getting to the complicated bits that you actually want to implement seem to be the barrier.

/me trying to learn OCaml after learning a bunch of other languages. Disagrees.

In my experience, one of the hard part when learning OCaml is that you can write your own code without modules, but to use someone else's code, you have to know how they work.
Post reply on HN