News for hackers. Stuff that matters.
Re:Learn to Read Code by _asummers on Thursday June 29, 2017 @08:05AM (#14662535)
Related: Dig into your language's source code and code of major libraries! Your standard lib is probably the best examples of idiomatic code and efficient code that you're going to have access to, written by the authors of the language itself. You'll notice bugs, inconsistencies and poor docs which gives you opportunities to contribute upstream, at the same time making you read more and learn how particular features work under the hood, which might give you new perspectives in your own code.

In Java, this might be java.util.Collections package, or java.util.Concurrent. or in C++ that might be Boost. In Elixir, I start with Kernel.ex[0]

https://github.com/elixir-lang/elixir/blob/master/lib/elixir...

Re:Learn to Read Code by quantdev on Thursday June 29, 2017 @08:43AM (#14662768)
I agree with the advice to read your standard library, because I think there's huge value to your general understanding of lower-level concepts and to knowing the available functionality of your language, but I disagree that it is the best example of idiomatic code, necessarily. For example, C++'s STL was written to be portable, efficient, and general beyond all other goals. Modern C++ style and abstractions are nowhere to be found, and if you follow the STL style, you may over-abstract (templatize), use manual memory management, and architect for non-relevant circumstances.
Re:Learn to Read Code by _asummers on Thursday June 29, 2017 @09:06AM (#14662938)
Certainly depends on the language and where in the standard library you are, though you're completely right to always be cognizant that it's all been taken through battles in production at scale and has been optimized accordingly. One could also argue that that kind of code might be idiomatic for that kind of problem (an example of general, portable, and efficient), and a good guideline on how that might be done, though it might not be a super satisfying argument depending on how conservative your definition of "idiomatic" is.
Re:Learn to Read Code by panic on Thursday June 29, 2017 @10:26AM (#14663538)
BTW, if you're going to read a C standard library, skip glibc and go for musl: https://git.musl-libc.org/cgit/musl/tree/src
Re:Learn to Read Code by _asummers on Thursday June 29, 2017 @12:49PM (#14664727)
There was an article last week-ish about reading OpenBSD source daily.

https://news.ycombinator.com/item?id=14521386

Re:Learn to Read Code by woodrowbarlow on Thursday June 29, 2017 @11:32AM (#14664091)
why do you say that?
Re:Learn to Read Code by sigjuice on Thursday June 29, 2017 @12:37PM (#14664630)
Because libcs other than glibc are less bloated and probably easier to read.

  ~ $ cat empty.c
  int main(void) {return 42;}

  ~ $ gcc -static empty.c -O3
  ~ $ strip a.out
  ~ $ size
     text	   data	    bss	    dec	    hex	filename
   677598	   5792	  10464	 693854	  a965e	a.out

  ~ $ diet gcc -static empty.c -O3
  ~ $ strip a.out
  ~ $ size
     text	   data	    bss	    dec	    hex	filename
      901	     32	     76	   1009	    3f1	a.out
Re:Learn to Read Code by posterboy on Thursday June 29, 2017 @07:13PM (#14667577)
It's just not very readable.
Re:Learn to Read Code by sjellis on Friday June 30, 2017 @07:32AM (#14669983)
I would modify this slightly, and suggest finding out who some of the most highly regarded programmers are for your language, and reading their libraries.

Standard libraries are often a very mixed bag of stuff because things are added but rarely taken away. Some it may be very new, and some of it may have been written before the idioms of a language were even finalized, and then frozen by compatibility needs. If you don't already have a strong sense of good style (or what is currently considered good practice for a language) you may find it difficult to identify what is good and what is a relic of history.