20 ms·
To learn a new language, read its standard library
- oreally 5y agoThis 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.
- luigi23 5y agoThis 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.
- matheusmoreira 5y agoStandard 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?
- powersnail 5y agoThat 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.
- themodelplumber 5y agoBetter 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...
- oreally 5y agoNo, 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.
- themodelplumber 5y agoCherry 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.
- johnnycerberus 5y agoReminds 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.
- Fellshard 5y agoI 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.
- Kranar 5y agoHere is a basic structure implemented in C++: https://github.com/llvm-mirror/libcxx/blob/master/include/vector 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/78d6a7767ed57b50122a161b91f59f19c9bd0d19/include/utility#L297 https://github.com/llvm-mirror/libcxx/blob/78d6a7767ed57b501...
- tsimionescu 5y agoWell, 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.
- Kranar 5y agoNo, 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.
- TexanFeller 5y agolol this advice might not apply as much to Scala. All the CanBuildFrom stuff was overwhelming to look at the first time, and a lot of things in the stdlib are implemented in a way that’s not idiomatic in app-level Scala. They’ve simplified things a bit and made it better since I was baffled by it all long ago though.
- silisili 5y agoWhole heartedly agree. I was big into Go years ago, and some newer guys tried to make it a functional language. When they argued with me, I couldn't say 'its's just not right', but instead pointed them to std library code. Protip: That doesn't change their mind, it just makes them hate Go.
- physicles 5y agoIf it drove them to write in another language, might that be a win? A code base full of non-idiomatic code, where devs think in the style of language A while using language B, isn’t a great place to hang out.
- silisili 5y agoIt absolutely would be, if our entire stack wasn't in Go. One was a JS guru who literally threatened 'I can walk across the street and get another job, you know.' And we let him, and both of us are happier for it. So I do agree, don't join a team writing a language you hate.
- pharmakom 5y agoI think I would have left too. Go has its advantages to be sure, but if you can write highly expressive functional code in a language like JS, Go is like wading through a swamp.
- physicles 5y agoAgreed. We're 100% Go in our back end, and in the process of hiring. We literally wrote in the job posting, "If you don't want to write Go, this job is not for you."
- ronenlh 5y agoWhy 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.
- 7kmph 5y agoMathematica left the chat
- mberning 5y agoAll well and good until you find out half of it is written in C or something like that. I like to go out and find the most starred repos on github or just ask around for a library that people think highly of and read that.
- marginalia_nu 5y agoC itself is actually a pretty good example of where this fails as well. Its standard library is usually more macros than code. It's necessary if you are going to ship portable code that deals with every conceivable architecture and endianness and permutation of toolchain from 1976 until now, but it's not how most C code looks. K&R is a much more meaningful guide than unistd.h.
- bestinterest 5y agoUgh Crystal is so beautiful and sorry to make this typical complaint but I wish the compile time was 1/10th of what it is. The dev cycle loop is just not there for me but the language is incredible.
- trevyn 5y agoDoes Crystal benefit from these new M1 beasts? My Rust compile times became much more pleasant.
- fwip 5y agoLLVM implements fewer optimization passes for ARM, so it's doing less work than compiling for x86.
- yjftsjthsd-h 5y agoDoes that hurt performance of the output?
- cute_boi 5y agoThere is high probability that it can hurt runtime perf. Because less passes means less optimization (in general)
- omaranto 5y agoWell, if it didn't, they could optimize the compiler by removing those optimizations. :)
- makapuf 5y agoThat 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.
- andy_ppp 5y agoElixir’s standard library is incredible and so simple and 99% written in Elixir.
- Waterluvian 5y agoReading the Python stdlib was a brilliant move a peer encouraged me to do. I learned three themes of stuff: 1. A good look at long lasting, durable pure python. 2. A good look at long lasting, durable C implementations of python (dict is the core of Python. Read the source!) 3. A look at a bunch of libraries that basically never get used and a sense of how they compare to popular third party libraries. (Doing this is why I’ll never complain when a language’s stdlib is small. I get it now.)
- er4hn 5y agoI'd love if you could elaborate on your thoughts for 3. Is it a problem of not being feature complete in unpopular parts of the stdlib?
- Waterluvian 5y agoWhat I learned is that once a library is in the stdlib, it's usually stuck being maintained for a long time. And then you've got all these libraries that see no use because they were ill-conceived or better ideas came along. I don't think stdlibs should be barren, but I completely get the ideas of languages like Rust that want to include only the most obvious of candidates and leave the rest for the community to organically evolve.
- int_19h 5y agourllib vs requests is one prominent example
- synergy20 5y agoUntil you realize most of the time the code is loaded with Macros, ifdefs, cross-platform conditions(windows,macos,linux...), hacks for different versions of OSes/dependency/whatever, the real meat is hard to spot on, it's easy to get lost in those noises.
- er4hn 5y agoFunny enough, this was a source of much criticism for OpenSSL as well, at least in the 1.0x series.
- epolanski 5y agoWhat would the JS/TS equivalent?
- bexsella 5y agoMozilla's JS Reference, I'd guess. A genuinely great resource. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Edit: And the Web API reference (which is what I was actually thinking of when I posted): https://developer.mozilla.org/en-US/docs/Web/API https://developer.mozilla.org/en-US/docs/Web/API
- wwweston 5y agoReading these things is good advice! But it's distinct from the advice given in the article, which is about reading libraries close to the heart of the language that are written in that language itself. JS is a bit odd here, possibly for good reasons (ubiquity + dynamic nature of the lang itself might mean runtime considerations override any degree of self-hosting), but it basically means it's not possible for standard definitions of standard library. So the question becomes... what are some masterful libraries written in JS?
- capableweb 5y agoI'll make no comment on how masterful/well written this is, but these are the most used libraries in the JS world by far margin: https://github.com/nodejs/node/tree/master/lib https://github.com/nodejs/node/tree/master/lib
- baby 5y agoDefinitely true for Golang, learned a ton reading its stdlib (and even found a bug this way)
- rectang 5y agoI agree, Golang is a good language for this. Rust, too. The Python standard library is pretty crufty — lots of stylistically dated code. Same with Perl 5, and I would guess other similar languages but I can't speak from direct experience. I bet that's more a function of their age — back in the 1990s maybe it might have been unreservedly good advice to read those standard libraries. I've also learned a lot from writing FFI extensions for languages, which for Rust and Go involves a lot of standard library diving but for languages like Python, Perl 5 and Ruby where the core is mostly written in C, it's a different experience than reading the standard library.
- ramesh31 5y agoThis is what I immediately thought of as well. The Golang stdlib is so good it makes me wonder if the author wrote this with it in mind
- EdSchouten 5y agoI actually partially disagree with this. Sure, for the higher level OS independent packages (e.g. “archive/tar”) this is great. For stuff in the “os” package it’s a different matter. All of that code is a bit messy. Not because the authors did a bad job, but simply because it’s hard to implement the same API on half a dozen operating systems. Then there is the “runtime” package which relies on a lot of global state, and has to work well in cases where heap allocations are not permitted. Sure you’ll learn how the language works, but you shouldn’t draw inspiration from those on how to write your own code.
- nemo1618 5y agoI suspect that the part of the stdlib that deals with the OS and runtime will be fairly messy and un-idiomatic in any language. They are inherently hairy problems.
- askvictor 5y agoI 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.
- marginalia_nu 5y agoI usually prefer working with mature stacks that don't require me to constantly work with flavor of the month frameworks. It's great to broaden your horizons and all, but that is something that needs to be done judiciously and deliberately if it is to actually be of any use.
- askvictor 5y agoMe too, but to get started on a non-trivial project in such a stack is, IMO, the tricky part. It would be nice if I could do everything in the stack(s) I already know, but that's not always possible (e.g. backend vs web vs mobile app vs desktop app).
- trevyn 5y agoRe-implement a toy version of the framework from scratch. :-) Or, try to add a non-trivial feature to the framework.
- cjaybo 5y agoHow do you know what a "toy version of the framework" looks like when you're not experienced with the framework itself? It seems to me like you've already solved the issue of "learning the framework" if your mental model of the framework is that solid.
- sodality2 5y agoKnowing what a framework does (its function) and knowing how to use it (its functions) are two different levels of knowledge. sometimes you can work backwards from knowing what it does to make a very quick-and-dirty implementation.
- munchler 5y agoThis doesn’t seem like a great idea in general, since the standard library is usually low-level code, aggressively optimized for speed, that is not at all typical of applications written in that language.
- dxuh 5y agoTo anyone that considers this approach for learning C++, I would advise strongly against it. Standard library code has to deal with too many cases and tries to be optimal for as many of them as possible. Also the formatting is highly unusual, compared to other C++ code found in the wild.
- dataflow 5y agoYeah... for C++ it's more like s/To learn/To really learn/
- aetherspawn 5y agoUh yeah if you try and read the Haskell standard library, you're screwed. It's list fusion and fancy algorithms to hack asymptotics all the way down.
- cprecioso 5y agoWhat does it mean to “hack asymptotics”?
- zamadatix 5y agoAlgorithm runtime analysis is usually measured with asymptotic estimates (Big O, Little O, Big Theta, etc). In something as commonly and generically used as the standard library of any performance focused language you're liable to find a focus on optimizing these algorithmic performance guarantees for corner cases over optimizing for simple and straightforward code.
- cprecioso 5y agoGot it, thanks!
- eepp 5y agothank you
- jimbob45 5y ago
- cturtle 5y agoI’m using Zig a lot right now, and I have been pleasantly surprised by the standard library. Maybe it’s due to Zig being a very straightforward language, but I find most everything I read in the standard library to make immediate sense. I don’t know about reading std alone to learn Zig though, I used other sources like ziglings and ziglearn which taught me syntax and patterns. Had I started with the standard library I doubt I would have picked up the language as quickly as I have. So having learned Zig I am much more inclined to look at standard libraries for languages I learn in the future, but I don’t think it’s wise to rely only on standard libraries for learning.
- nafizh 5y agoIs there any learning resource for Zig that doesn’t assume you already know C? I couldn’t find any.
- zamadatix 5y agoI'll be honest there aren't really any complete learning resources even for those that do know C. For what there is the language is changing whatever you read in documentation might not be true between stable and master at the moment. The stdlib source is probably the best reference but even reading strictly from that it doesn't mean you'll learn to make code that works it means you'll learn to make code that's correct. There are plenty of known compiler and language issues on GitHub and the self hosted compiler is still being written. At the moment since Zig isn't complete you aren't going to find documentation that is either. Particularly for newcomers.
- cturtle 5y agoZiglings [0] is a series of small problems where you solve bugs in Zig code, and I enjoyed working through them. The readme claims "you are not expected to have any prior experience with... C." When I did ziglings I found the most difficult part was adjusting to the type syntax (which I now love). I admittedly know C very well, but assuming you already know a language with a C-like syntax (C++, Java, JavaScript, C#, Rust, etc.) most things like functions, control flow, variables, statements map to Zig with only small syntactic differences. One thing that may be difficult to learn not knowing C is working with strings, since they are just arrays of bytes. Most other languages have a string type, but Zig is much more like C in that strings are null-terminated fixed-sized arrays of bytes. [0] https://github.com/ratfactor/ziglings https://github.com/ratfactor/ziglings
- en4bz 5y agoIf you've ever tried reading the source for glibc or libstdc++ you know this is terrible advice.
- qwerty456127 5y agoIn the past, people supported pundits who would sit in the monasteries/huts their whole life perfecting their knowledge of scriptures and their skills of explaining them to others (incl. picking the right verse when it's needed and commenting the way helpful to the seeker). Some times I feel like today, besides free software projects, meant to be ran on donations, there should be entire separate projects dedicated to writing really good (also taking usability, eloquence, ease of understanding and practical examples very seriously) documentation for programming languages and libraries.
- deleted 5y ago[deleted]
- girvo 5y agoThis is how I approached learning Nim at the time, and it was quite an excellent approach in my opinion. Even gives you the opportunity to contribute to the language in question, when you inevitably come across something that isn't optimal, a bug, or even something as small as formatting inconsistencies, which is a nice feeling
- math-dev 5y agoI say best way to learn is to start coding and break stuff :-) Also once one gets more experienced, its better to decouple the language from programming concepts like object oriented programming, continuations, avoiding side effects in functional programming, etc. Useful to read books like SICP and algorithm books, then learn multiple languages and you will see they are not that different overall. I recommend learning Lisp or Scheme or related languages because they have a lot of good conceptual resources to learn from. But maybe that’s my background talking, I loved SICP. I learnt SO much from studying Common Lisp in the last year. Of course it helps that it has a great language specification. In terms of choosing a language, standard library matters a lot. Hence the explosion of JS due to NPM and also being in browser. I’m suprised SWIFT is not more popular, given Apple’s place in the ecosystem. I really liked programming in Swift, very enjoyable language. And it has generic functions too!
- Arch-TK 5y agoI'm not sure how many languages this works well for but it certainly doesn't work with C. You won't learn the important distinctions between implementation defined, unspecified and undefined behavior. And reading a C standard library implementation will not really teach you to write normal idiomatic C code. You will also not learn the strict discipline required to avoid doing things unless you absolutely know with certainty that they are either strictly conforming or defined for your particular set of target platforms (usually much harder to answer this second question which is why when writing C you should avoid having to). That being said, for Erlang, I think this is a good idea. I learned a lot when reading the standard library.
- nickdrozd 5y agoEmacs comes with a manual called "An Introduction to Programming in Emacs Lisp". It says: > I hope that you will pick up the habit of browsing through source code. You can learn from it and mine it for ideas. Having GNU Emacs is like having a dragon’s cave of treasures. - https://www.gnu.org/software/emacs/manual/html_node/eintr/On-Reading-this-Text.html https://www.gnu.org/software/emacs/manual/html_node/eintr/On...
- deleted 5y ago[deleted]
- jez 5y agoThe goals of library authors are frequently different from those of application developers. Library authors usually have to consider how to make their code work on more environments, on older language versions, more configurable, handling more edge cases. I think there’s definitely value to reading a language’s standard library, and I’ve also gotten lots of value from even reading the language’s implementation! But I hope people take this advice to start with reading the standard library with a grain of salt: it can be one extra resource for you, and likely to show you new things that weren’t written in docs somewhere, but if it doesn’t click or is proving difficult to understand, that’s fine! In particular, for the “reading code to learn” bit, consider reading an application written in that language (command line tool, web application, etc.) and it might serve as a more reduced intro to the language.
- SavantIdiot 5y agoIMHO, any language worth learning has a large enough user base in both corporate and academic settings and that there are books written on it. That's my criteria. If it doesn't have at least 5 books on Amazon, I'm suspicious of it (and from real publishers, and not publishing mills). There's too much wheel-reinventing happening for me to get excited about new languages. In the last decade I've spent time learning five sufficiently novel languages: Scheme, Ada, Erlang, Rust, and Go. Three of those are from the late 70's. I'm really glad I learned Ada and Rust. I started using Ada for embedded programming, and I'm trying to find more opportunities to use Rust because it so robust. I only studied Erlang, Scheme, and Go because smart people I knew told me I should investigate, but I have not used them.
- rowanG077 5y agoWhat is novel about Go? It just seems like C repacked with a garbage collector and basic concurrent programming support to me. Which both weren't novel even when Go was designed.
- DangitBobby 5y agoIt'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.
- jiggunjer 5y agoJulia makes the same claims
- __turbobrew__ 5y agoGo 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.
- fsnowdin 5y agowhere's the french standard library I can't find it
- MonkeyClub 5y agoIn any French city or town near you.
- mohn 5y agolol, here's what the standards body has published [0]. Version 9 still in dev, with "recent" releases of: 1992 - French v9.a.e 2000 - French v9.e.m 2011 - French v9.m.q Don't be deceived by the dates, though. The project isn't dead. The Larousse and Le Robert forks are actively developed. [0] https://en.wikipedia.org/wiki/Acad%C3%A9mie_Fran%C3%A7aise#Dictionary https://en.wikipedia.org/wiki/Acad%C3%A9mie_Fran%C3%A7aise#D...
- deleted 5y ago[deleted]
- kartayyar 5y agoA different take: read unit tests for the standard library. That shows you call sequences in context, rather than just getting lost in the code.
- savant_penguin 5y agoAny tip where to begin with Julia?
- exdsq 5y agosudo apt-get install python3
- savant_penguin 5y agoI meant actual code from their library So https://github.com/python/cpython/tree/main/Python https://github.com/python/cpython/tree/main/Python
- exdsq 5y agoSorry it was a tongue-in-cheek comment about preferring Python to Julia :)
- adgjlsfhk1 5y agoJulia's standard library is pretty readable. It depends a lot on what type of code you are interested in writing though.
- ChrisRackauckas 5y agohttps://github.com/JuliaLang/julia/tree/master/stdlib https://github.com/JuliaLang/julia/tree/master/stdlib . The matrix factorizations for example are pretty nice reads if you know the subject https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/lu.jl https://github.com/JuliaLang/julia/blob/master/stdlib/Linear...
- ofou 5y agoThe Docs of the standard library of Python equals approx. to a 1000 pages book. [1] I think is a good idea to read them, but I'd like them to be more concise. [1]: https://docs.google.com/spreadsheets/d/1U6_NxSxcFC3FPqtPB8eIm7BFV_bE25cFwLwF0TIsTJU/edit#gid=1659266541 https://docs.google.com/spreadsheets/d/1U6_NxSxcFC3FPqtPB8eI...
- ramesh31 5y ago* Looks around nervously in JavaScript *
- the__alchemist 5y agoThe MDN web docs (https://developer.mozilla.org/en-US/ https://developer.mozilla.org/en-US/) are quite good.
- lngnmn2 5y agoAnd discover that MIT Scheme Erlang, SML, Ocaml and Go are awesome, and others are better not to look.
- shp0ngle 5y agolaughs in C++
- rramadass 5y agoIndeed; In C/C++ land this is rather the norm. I learnt more about C and C++ from studying Plauger's The Standard C Library and Plauger/Stepanov's The C++ Standard Template Library. I also remember learning Object-Oriented Framework design from MFC Internals.
- marsdepinski 5y agoTo learn a language, read and understand its specification. Then learn the tooling and libs that come with the compiler. Then just start reading other people's source from wherever while you write your own stuff. Reading the standard lib is helpful, ad is reading the source of any framework, but you have to know the language spec well for it to make sense.
- slmjkdbtl 5y agoIt's much more productive to just start writing and reference to the spec (if they have any) along the way than start writing after reading the spec.
- aghilmort 5y agothis works really well for certain languages and have done many times over the years, first can actively recall was Turbo Pascal some years ago, which ironically enough, was just tweeting about on Friday along with other just get started thoughts, https://twitter.com/DotDotJames/status/1451656005155176454 https://twitter.com/DotDotJames/status/1451656005155176454
- ridaj 5y agoMaybe 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
- samus 5y agoThis is natural due to the low-level nature of a language implementation. And at some point, what's truly going on is often hidden behing a compiler intrinsic or a foreign function call to the runtime. At the same time, there are going to be parts of the standard library that are less platform-specific and thus more readable, for example the Java Collection Framework.
- andi999 5y agoAgree. I am thinking in C++ you do not want to read the std to learn the language.
- sydthrowaway 5y agoI thought this was about human language :(
- charles_f 5y agoInterestingly, 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 forth. We also built a simple CPU from gates using an electronic simulator. Left me with some confidence that I could do things with a relative confidence. Definitely value in learning the basics.
- amitport 5y agoHave you tried looking at C++ standard library? This and in many other examples, you really shouldn't.
- bmitc 5y agoThere's always someone in software waiting to tell you you're doing it wrong.
- sidedishes 5y agoEven though it's not about human languages, it is funny to think about how you would definitely learn a human language too if you pored through its entire literary canon.
- matheusmoreira 5y agoCompletely 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 APIs people will be using to solve the vast majority of problems. Of particular interest are the APIs used for dealing text and I/O because everything involves them. This is why Scheme is so easy to learn. The language itself can be learned in hours. The standard library is so small it's pretty much useless. Learning Racket on the other hand is much harder. To go even further than standard library, read the language's source code. This is especially relevant for virtualized languages. The implementation reveals how they actually work and enable a much deeper understanding of it.
- ddlutz 5y agoI 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".
- chousuke 5y agoC is hard because despite being a "small" language, it's full of all kinds of unintuitive rules and behaviour for beginners to stumble upon, and the language provides next to no assistance in avoiding the pitfalls. People have to learn C by making potentially dangerous mistakes, hopefully in code where they don't matter.
- hvidgaard 5y agoWhat 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.
- pantalaimon 5y agoI'd recommend then read musl though and not that atrocity that is glibc
- pantulis 5y agoI 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!
- ryloric 5y agoThis has worked pretty well for zig in my case. It's a neat little language that's easy to read and learn from the stdlib.
- dathinab 5y ago> 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.
- vletal 5y agoOr it even uses patterns which would be considered anti patterns outside of it for the sake of optimizations.
- masklinn 5y agoFor 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.
- pharmakom 5y agoSystem.Collections.IEnumerable says hello
- GuB-42 5y agoOptimized 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.
- 5y ago
- rossmohax 5y agoIt can give you some insight into language features, memory model, etc, but it is unlikely to help you "learn" , as in "be effective in using" it. For instance in Scala you'll likely need to know cats-effect or zio ecosystem more than stdlib. Likewise for Rust, where futures and async stack (tokio, asyncstd) are outside stdlib.
- bjarneh 5y ago> The development is possible thanks to the community's effort and the continued support of 84codes, Nikola Motor Company... Nikola Motor - glad to see something good coming out of that scam...
- praveen9920 5y agoI think this applies to lot of frameworks, especially web frameworks. This has been my experience with expressjs and Angular2, Jquery. They may look like they are doing lot of magic but underneath it’s just a simple code, when read it easy to write optimised code.
- 1vuio0pswjnm7 5y ago"The best way to learn a new programming language, just like a human language, is from example." Certainly this is how I learn. Much more immediately useful than voluminous documentation. However I am not sure every language has a standard library. For example, Lua. Also not sure every standard library is a model to follow. For example, where feasible, I try to use and learn from djb's C functions instead of the "C standard library" ones.
- simonebrunozzi 5y agoI'd change the title to "To learn a new programming language..." - we shouldn't assume that "language" implies "programming", at least not in titles.
- evercast 5y agoI 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<T> being used there. Instead, your takeaway might be that it is perfectly fine to return nulls all over the place.
- nico_h 5y agoWhat'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.
- evercast 5y agoI think "Effective Java, 3rd edition" is a good book to have a look at. It is not entirely up to date but covers Java 8 features which are a must. In general, I'd heavily recommend studying the usage of lambdas & streams. And Optional<T>. ;)
- axegon_ 5y ago> You won't see Optional<T> 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.
- flohofwoe 5y agoMy 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 https://github.com/floooh/pacman.zig) and a home computer emulator (https://github.com/floooh/kc85.zig 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.
- MauranKilom 5y agoThe 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 https://github.com/microsoft/STL/blob/main/stl/inc/xtree): using _Scary_val = _Tree_val<conditional_t<_Is_simple_alloc_v<_Alnode>, _Tree_simple_types<value_type>, _Tree_iter_types<value_type, typename _Alty_traits::size_type, typename _Alty_traits::difference_type, typename _Alty_traits::pointer, typename _Alty_traits::const_pointer, value_type&, const value_type&, _Nodeptr>>>; Also, good luck understanding this class member definition. Hope you figured out _Scary_val! _Compressed_pair<key_compare, _Compressed_pair<_Alnode, _Scary_val>> _Mypair; (Hint: Empty base class optimization.)
- feffe 5y agoI don't think the advice applies for C++ either. The last time I worked with a C++ code base I tried to understand some std:: API semantics by reading the code but I failed every single time. I'm not an expert C++ programmer by any means but I think I've passed the novice stage where you try to learn the language. Maybe for C++ constant learning of the base language is needed :-) For Go and C on the other hand I think it works very well since the core languages are so simple it's viable to read others code successfully without being a language expert. I read the Go stdlib code all the time if something is unclear in the documentation (the docs are good but sometimes there are edge cases that are not clearly documented).
- steerablesafe 5y agoFor 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.
- hello4353 5y agoC++ blurs the line b/w language and standard library in some cases. Example initializer list.
- Jeff_Brown 5y agoThe advice still stands in a generalized form: read the "nearest to standard" libraries for that language that were implemented in that language.
- dkersten 5y agoThis doesn’t seem like good advice to me, as others have already said. C++ standard library is written in a heavily templates style most user code isn’t written in. That would be a terrible way to learn. Some of Python’s standard library delegates to C code. Much of Clojures standard library builds the language up from a small set of primitive, sometimes out of macros, and isn’ta good example of how to write good code yourself. The standard libraries tend to be written in a different mindset than idiomatic user code is, as the requirements differ. In my opinion, the best way to learn a language is to implement a non trivial but small project in it.
- Const-me 5y agoThis depends on the language. In C#, standard library is awesome, and indeed a good starting point for people learning the language. On the other end of the spectrum there’re languages like C++ with these horrible templates, or Rust with tons of unsafe code. Adopting patterns or coding style from these standard libraries is not the best idea.
- Kye 5y agoBetter idea: https://learnxinyminutes.com/ https://learnxinyminutes.com/
- jeffrallen 5y agoThe only language where this worked for me was Go.
- straight-shoota 5y agoCrystal core developer here. Happy to see Crystal's stdlib as an example for how you can grasp a language by looking into stdlib code. That's what I like a lot about Crystal. Even its stdlib easily readable. Arguably, this is somewhat deteriorating as algorithms get optimized. Readability and performance being in competition. I agree with some of concerns from many commenters. For many languages, especially those that have been around for a long time it's probably not a good idea to look at the stdlib. C++ or Java, no thanks. But with some languages like Crystal, Golang or Julia, it can be really very helpful to look at the stdlib implementation.
- CRConrad 5y ago> Crystal Sorry, stupid question: Is this derived from the old Crystal Reports, or something completely separate?
- balnaphone 5y agoWith a bit of an imaginative stretch, this advise appears to hold for natural languages, also.
- CRConrad 5y ago"Standard library" is a funny way of putting it; it's usually called a "literary canon"... Oh, that kind of language! (Honest first-split-second reaction.)
- lcrmorin 5y agoI've jsut discovered this approach with python. I usually used google and cookbooks. But I often found myself in position where I tought 'surely there must be a better way to do it'. Reading the standard library really helped me understand how to do some stuff. Best way I found to enforce what I learnt was to rewrite some code with minimal imports.