Live data from Hacker News

To learn a new language, read its standard library

patshaughnessy.net

221–230 of 243 posts

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

#221
post #210

Earlier quoted context omitted.

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 th…

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++.

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

#222
post #206

Earlier quoted context omitted.

Actually it was very messy. People were encouraged to use it as a write-only imperative scripting language. People thought VBScript was more powerful. JavaScript was like that attention-seeking red-headed stepchild that you see at family reunions. There's a good reason Douglas Crockford re-introduced JavaScript as "the wwwrld's most misunderstood programming language." He saw beauty within that others didn't.

That's something I don't really understand. The language is a garbage-collected C-like. If you don't abuse objects/this/.call, plain Javascript is very readable. What made it a "write-only imperative scripting language"?

If you look at the "JavaScripts" that were floating around at the time (try looking up dynamicdrive.com from around the year 2003) I think you'll understand what I mean.

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

#223
post #119

Earlier quoted context omitted.

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

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.

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

#224

Interestingly, my engineering school adopted the opposite approach on practical teaching: the first couple of month after the preparatory years were all about re-building all the C stdlib, networking layer, then building your own shell, then building your own assembler and corresponding vm (it was an assembler for a quartet based system for whatever reason), then compiler for a random language in c++ (tiger) and so f…

By random language do you mean probabilistic? That sounds pretty advanced, actually.

No I mean teenager random, as in a language that no one ever heard about (tiger) which I believe is mostly there to learn about compilers

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

#225
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".

I'd recommend then read musl though and not that atrocity that is glibc

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

#226
post #217
post #208

Earlier quoted context omitted.

Most of the time memory unsafety isn't a feature people want or need.

There's a significant niche for such features, we're dozens . That's the reason why people like stuff like Zig. Pointer arithmetic isn't just dangerous, it's cool too.

I'm not saying that memory unsafety is useless or even undesirable, I think the "problem" is that it's the default in "current popular and actually used high-performance languages", which means that stuff that needs to be fast and secure (like web browsers) have a hard time.

Maybe my "most of the time" was too strong and I ignored big domains that I don't know. But for the part that I relatively know (web stuff mostly), safety and speed together matters a lot. The thing is, since unsafety tends to be viral (an unsafe part of your stack can compromise everything), people get very paranoid about "unsafe languages".

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

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

For older languages, it’s also pretty common for some of the stdlib’s corners to be very dusty with API design, naming conventions, and coding patterns considered at best way outdated .

System.Collections.IEnumerable says hello

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

#228
post #189

Earlier quoted context omitted.

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.

Very well put. (And if the standard library doesn't represent idiomatic use of the language, that's a red flag).

Take Scala collections. These are written using builders and if-else checks of emptiness which are definitely not idiomatic. Authors of the std-lib did them for you so you do not have to. That is not a red flag.

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

#229
post #188

Earlier quoted context omitted.

You seem to be implying that it is desirable to employ programmers who would get confused over bitshifting and lack the ability to figure it out.

It's the norm to work together with people with varying skill level. Weather people have the skill to figure it out also doesn't matter as they normally don't have time to figure it out. And even experienced programmers can get confused about bit hacks, sure temporary but that already a step price to pay which is seldomly worth it. It always comes with the risk of accidentally introduce a bug, even if your team only…

I'd go even further. As long as you want to communicate your ideas via code it does not matter whether you work with juniors or seniors. You want to limit the cognitive strain caused by unnecessarily complicated code.

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

#230
post #188

Earlier quoted context omitted.

You seem to be implying that it is desirable to employ programmers who would get confused over bitshifting and lack the ability to figure it out.

It's the norm to work together with people with varying skill level. Weather people have the skill to figure it out also doesn't matter as they normally don't have time to figure it out. And even experienced programmers can get confused about bit hacks, sure temporary but that already a step price to pay which is seldomly worth it. It always comes with the risk of accidentally introduce a bug, even if your team only…

I am against the idea of holding back for newbies.

If you think bit hacks are bug prone, needlessly complex, and not worth it, don't use them. But if your only argument is "junior may not understand", then no.

Newbies need to learn, if they always face newbie friendly code, they will be newbies forever. So yes, it takes time understanding a new technique, but it is an investment.

Later, when not-junior-anymore has to decide on an implementation, he then can chose the most appropriate among the many he saw, including bit hacks. It doesn't mean bit hacks are the best, or that he will use them, but because of his experience, he will make a more informed decision.

Note that I assumed code intended for professional developers. The situation is different if you are targeting non-specialists (ex: macros for end users) or if you are making example code.

Post reply on HN