edit: I don't see why this is down-voted, the OP asked about examples of high-quality code, structure and design are also a large part of this and it's not hard to find the github-repo for any particular application mentioned in the above book. Furthermore a lot of examples of excellent code are not necessarily easy to approach with the 'open some random files and start reading approach', having a high level overview often helps.
https://talks.golang.org/2015/gofmt-en.slide ("The Cultural Evolution of gofmt) (2015)
"Evolution in programming culture:
-gofmt is significant selling point for Go
-Insight is spreading that uniform "good enough" formatting is hugely beneficial.
-Source code manipulation at AST-level enables a new category of tools.
-Others are taking note: Programming culture is slowly evolving. "
It will zoom out the slides and make them readable. Weird how that is necessary.
But there's some parts in there I certainly wouldn't call elegant. For example, if you trace function calls from http.Get() you end up in a lovely function called doFollowingRedirects()[0] which is where the actual request is made inside of a for {} loop.
Be it efficiency, some stylistic tendency I'm unaware of, or some contrived excuse that doesn't make any sense, at the end of the day I'm not likely to look for a function called doFollowingRedirects when I want to see where the initial (and likely only) request is made.
[0]: https://github.com/golang/go/blob/master/src/net/http/client...
In that context, the function doesn't seem so surprising. If you take a look at the function `Do`[0], you'll notice it calls out to either 'send' or 'doFollowingRedirects' depending on whether it's a request that should 'do, following redirects' or simply 'send a single request'.
Many HTTP libraries I've seen are structured around creating a request object and then handing it to a 'do request' function - the crime here at best seems to be the naming 'doFollowingRedirects', which can be read as 'do the subsequent redirects' which might make it seem odd that the first request was included in the for loop therein.
I consider it well written. I never dive into flask and come out confused or disappointed.
That said, if you want to read elegant code, I'd recommend the stb parser libraries (written in C). They are small self-contained decoders for many common media formats, with excellent documentation:
https://github.com/nothings/stb/blob/master/stb_image.h https://github.com/nothings/stb/blob/master/stb_truetype.h https://github.com/nothings/stb/blob/master/stb_vorbis.c
These libraries are likely insecure, handle many edge-cases incorrectly, implement fewer features, and perform worse than other options. However, they meet your criteria better.
Do you currently use and rely on software which you expect won't be useful to you in ten years time? I can't think of much personally.
(I do use IDA Pro, which has clearly adapted poorly to changing requirements - it still has scars of the 32-bit to 64-bit transition that get in the way of day-to-day usage. I hope there'll be something better in ten years. Of course, I could buy a cheaper, "higher quality" tool instead, but none of them are as powerful or as useful.)
I personally think the variable name length should match the scope size, bu then I'm reasonable like that.
Perfect summation, matches my thoughts.
A tip is to look at the function declaration in the header files. There I, at least, use somewhat longer parameter names for descriptive purposes (along with documentation) but usually use short ones in the function bodies.
So, if your functions are short and to the point (low coupling, high cohesion, in Coding Complete parlance), then I consider short parameter and variable names a good style. But it's just one ingredient in good code.
Unless you're looking at competitive programming, I feel the best programmers make clear code with short names.
Too much of "longer names are better" fetishism adds noise and detracts from overall clarity.
Short variable names work less well when you have more than about 4 of them in the same function/block or there is no common convention suggesting what the variable might be from its name alone.
Short variable names are also not good for globals or struct members, because those names are used across many contexts. Combine this convention with a short local variable name and you end up getting things like:
typedef struct {
int retry_count;
} connection_t;
// If "connection_t" is used widely throughout your codebase,
// you get used to seeing a variable "c" that is a connection.
void func(connection_t *c) {
fprintf(stderr, "Retry count: %d\n", c->retry_count);
}
...which I think is pretty readable.I never seen a code with long local variable names that was not awful.
And it is not about typing. Long names harm reading in the first place.
As long as variable scopes are kept tightly controlled, length of the overall code-base is irrelevant. Avoid "spooky action at a distance" and you never have to care that there's a variable named s instead of string_for_truncation_html_aware 500,000 lines away from the function in front of you.
Read up on good user interface design. One of the key points is that texts should be short and the shape of words easily distinguishable. index1, index2, index3 might be more descriptive than i, j, k but the latter have more unique overall shape which makes it easier to identify for a reader. Likewise CoordinateX, CoordinateY, CoordinateZ is harder to read than x, y, z.
How do you like reading the line below: divideBy(multiply(rocketmass, multiply(rocketvelocity, rocketvelocity), 2)
compared to: (mv^2)/2
Sure the former describes what the individual variables are, but immediately getting an overview or sense of what is being calculated is harder. But using short variable names doesn't mean you can only use short names. You can mix and match to optimize understanding and clarity.
rocketKineticEnergy = (m*v^2)/2
I follow Rob Pike's advice and use long names for global and seldom used variables and functions while I use short names for locally defined variables and functions. I might also use short names for key concepts frequently used. If your key domain is geomtry then nobody will have problems understanding in context what: x, y, w, h, dx, dy etc means. You don't have to write XCoordinate, YCoordinate, Width, Height, DeltaX, DeltaY.... of course you do.
Backbone and the Coffeescript compiler are also good; jashkenas & the contributors did a good job trying to put literary programming techniques to use, IMO.
The Elixir source code is very high quality; same applies to the Ecto library. Elixir code in general, because of the focus on including detailed documentation (including doctests) within the code, tends to be very readable. The way the REPL is set up means the docs for modules or functions can be accessed at any point, so it's good for pragmatic reasons.
Caveat: came from Ruby, so the syntax was very friendly. But I'd say as an aside that it's the first programming language I've experienced, (coming via a helluva lot of functional JS) that's both functional and completely pragmatic in terms of focussing on what's useful and necessary. Really impressive.
Where do you see a loss in quality?
Lodash has plenty of comments (jsdoc, bug fix notes, and implementation explanations). Underscore has stripped many of these leading to devs making the same mistakes or introducing regressions.
Lodash docs are arranged in alphabetic order. Underscore docs aren't and even have thing miscategorized.
C
- REDIS @ https://github.com/antirez/redis
- Postgresql @ http://git.postgresql.org/gitweb/?p=postgresql.git;a=tree;f=src;hb=HEAD
Java - Spring Framework @ https://github.com/spring-projects/spring-framework
- Guava @ https://github.com/google/guava
Javascript - ui-grid @ https://github.com/angular-ui/ui-gridFor high quality JS, I would look to some of the major frameworks out there:
https://github.com/facebook/react
https://github.com/angular/angular.js
https://github.com/angular/angular
There is a lot one can learn about software design by reading the source code of major libraries, and is far more reliable than any third party library in the ecosystem.
To me the Spring Framework represents everything wrong with the Java way of doing things.
This is because Rust as a language has changed a lot, and the compiler still has old code that was written the "old way" and not updated to use better or more idiomatic alternatives (e.g. elision, if let, etc). Servo is in a similar situation. This is slowly improving as we run clippy on Rust and in occasional manual refactorings (for example when sty was renamed to TypeVariants and ty_foo was renamed to TyFoo to be have the correct capitalization -- the old capitalization was years old), but there still is work to do to make it completely idiomatic.
So if you want to learn how to write idiomatic Rust, I would avoid using the Rust repo as a source. Newer repos and new code in the Rust repo is pretty okay, though.
"Each project must be: * Open source (in GitHub). * At least 5,000 lines of code. * At least one year old. * Object-oriented (that's the only thing I understand).
The best projects will feature (more about it): * Strict and visible principles of design. * Continuous delivery. * Traceability of changes. * Self-documented source code. * Strict rules of code formatting.
What doesn't matter: * Popularity. * Programming language. * Buzz and trends. "
In the end there 158 submissions, 12 finalist and 1 winner. Check them out.
> Let's get back to class names. When you add the "-er" suffix to your class name, you're immediately turning it into a dumb imperative executor of your will. You do not allow it to think and improvise. You expect it to do exactly what you want — sort, manage, control, print, write, combine, concatenate, etc.
For the curious, the conundrum can be trivially solved via ```apples.min```, or perhaps ```Collections.min(apples)``` in a noun-biased language.
It's not literally flawless (hard to find conceptual entry points, short on comments), but when you get to the massive piles of one-off special functions needed to simulate all of Pokemon's moves and abilities (e.g. https://github.com/Zarel/Pokemon-Showdown/blob/master/data/a... ) it's all much more succinct than I'd have expected. The file I linked expresses more "business logic" in 3300 lines than is contained in the entire 40kiloline codebases of some of the enterprise monstrosities I've worked on.
Numerous functions missing essential code documentation all spread in a single file, with commented out code committed in git.
#ifdef VXWORKS
It really makes parts of that codebase dreadfully hard to reason with imo, but at the same time, I appreciate you either do exactly what they did, or you don't support the platform.Maybe because it's getting a bad wrap these days with people doing dumb, repetitive things with it. But I've always found the code quality to be very good.
Otherwise it's too subjective.
Deeplearning for Java https://github.com/deeplearning4j/deeplearning4j
Scientific Computing for Java with n-dimensional arrays https://github.com/deeplearning4j/nd4j
The C++ lib that makes it fast https://github.com/deeplearning4j/libnd4j
It feels like a lot of thought was put in to making the code well-documented and easy to follow for people new to the project.
[1] https://github.com/graphql/graphql-js [2] https://facebook.github.io/graphql/
In response, I put the effort in for my smallest project to make it as high quality as possible: https://github.com/daurnimator/fifo.lua
It's probably not much help to you unless you're working with lua; but... you did say any language :)
[1] https://github.com/laravel/framework
[2] https://www.reddit.com/r/laravel/comments/20ovey/just_notice...
They're also awful at managing issues/bugs, where they'll gladly close issues without explanation, or close an issue when a pull request gets submitted, only to reject the pull request and not re-open the issue.
Also, I'm wondering, does your criticism still apply to the latest versions of Laravel or does it stem from frustrations with the pre-5.0 versions? Regarding your comments about the lack of interfaces, it's worth mentioning that at least the core components do have an interface now [2].
[1] https://github.com/laravel/framework/pulls?utf8=%E2%9C%93&q=...
[2] https://laravel.com/docs/master/contracts#contract-reference
Also good is https://github.com/symfony/symfony/tree/master/src/Symfony/C...
They have really clean code, popular packages and are open about their decisions. It is interesting to understand their design thinking.
Great code, docs and support.
https://github.com/deepstreamIO/deepstream.io
And node client
https://github.com/deepstreamIO/deepstream.io-client-js
are examples for a very clean, "no nonsense" style of writing JavaScript
But it has lots of statefulness, some of the state is structured as a finite state machines in ways that are easy to break (similar to the "request" module, also a FSM that is incredible easy to break).
Function parameters are not validated.
Therefore when you implement a state machine in code the consequence is sequential coupling.
Imagine a car class: You have StartCar(), Accelerate(), Break(), StopCar(), SwitchGear(). Can you accelerate with your car turned off? no. Can you stop your car twice? No. So there should be validations in state transitions. Since in this code those are missing, it's possible to arrive to invalid states that can cause undesired behavior.
In the "request" npm module (an ambiguous module name that wastes a lot of my time in a regular basis), you can abort a request that has not started. That causes an exception. It took me a lot of time to find it. It was all because of a broken state machine.
It's one of the highest quality and cleanest PHP codebases I've ever seen.
PS: Please pipe all the unflattering comments about PHP to /dev/null, heard them all before.
UI Framework built with React and SCSS. The components are nicely modularized, have unit tests, and we put a lot of emphasis on code readability, clear names for things, a scalable folder structure, and intuitive interfaces.
https://github.com/bbu/quaint-lang
I think the strengths of the C code are: straightforward algorithms without many nonsensical abstraction layers, consistent and clean formatting, sane usage of the preprocessor.
IMO very well written and very well run project. I follow most issues closely just because the discussions re: code reviews, new features, and community questions.
https://github.com/richeterre/SwiftGoal
ReactiveCocoa 4, Swift 2.2, MVVM architected, full test suite.
I think this is a reasonable way to handle the tons of special cases in nethack's gameplay, but not really "inspiring".
You will hardly find anything even distantly approaching the quality of TeX and Metafont. Not sure if there are mirrors on github, but you can always grab a copy from CTAN.
Language: Ruby Framwork: Rails
In this case, I've never read the sources, so I have no idea if the complaint is valid.
Yeesh. I must either be getting old, or everyone is significantly more busy than I am. I find that I always have time to at least locate any official documentation for the thing that I'm working with.
Whilst it may well well engineered as a project of this size, the code I have seen leaves a lot to be desired.
Cases that spring to mind are the mm code and cgroups where, as an outsider, I got the impression of a large codebase where the patch delta is kept to a minimum -- perhaps so as not to introduce new bugs as features are added. But this doesn't necessarily mean the resulting code has a logical structure or layering; it means deciphering it involves as much studying of the Git history as it does of the (sparsely commented) code on the screen.
In contrast, my experiences in the FreeBSD code have been much better, with less spaghetti and even to the point of maintained man pages for key internal functions.
- Just to use it you can see the documentation on the website[2], which is the first contact normally.
- Then when you try to find the relevant files. They are in github's `src/plugins/addclass`, a name that is common and intuitive [3].
- Not only that, but you also got the documentation in that folder in github thanks to the name `readme.md`.
- When opening it [4], the first thing that you note is that the function has a tiny footprint; 8 lines. A brief explanation of what it does and a line explaining what the not-so-intuitive function `this.eacharg()` means.
- Then we use the native `Element.classList` [5] to add classes. Most people familiar with vanilla javascript know it, but otherwise the name is quite descriptive `el.classList.add(name)`
In contrast, while covering quite few other edge cases and older browsers, check jQuery's `.addClass()` code [6]. Or check Zepto.js' `addClass()` code [7]
[1] http://github.com/umbrellajs/umbrella/
[2] http://umbrellajs.com/documentation#addclass
[3] https://github.com/umbrellajs/umbrella/tree/master/src/plugi...
[4] https://github.com/umbrellajs/umbrella/blob/master/src/plugi...
[5] https://developer.mozilla.org/en/docs/Web/API/Element/classL...
[6] https://github.com/jquery/jquery/blob/305f193aa57014dc7d8fa0...
[7] https://github.com/madrobby/zepto/blob/601372ac4e3f98d502c70...