Live data from Hacker News

Ask HN: What are some of the most elegant codebases in your favorite language?

news.ycombinator.com

71–80 of 186 posts

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#71
post #38
post #35

Working with Perl, two things spoiled me for other languages: JSON and DBI/DBD. In Perl, everything serializes to JSON without fuss. It can be "lossy"; objects without an explicit JSON serialization method and coderefs can't be deserialized, but serializations at least have placeholders for them. Compare to Python's json module, which doesn't try very hard to serialize things and throws exceptions every time it runs…

Ruby, being a Perl-inspired language, has `.to_json` built in. You can do ```rb # hashes { foo: 'bar' }.to_json # numbers 28.to_json # anything really ['hello', 42, { lorem: "ipsum" }].to_json ```

That’s simply not true. This method is monkeypatched by json gem

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#72
post #15
post #9

Earlier quoted context omitted.

To me, "anti-pattern" has the same bogus meaning as "clean code"

Although at a high level many of things things are subjective, this take is almost entirely wrong in every dimension. Anti-patterns are things like using a wrong data structure, using the wrong levels of abstractions, tightly coupling components so they are not composable, leaky interfaces, god objects doing too much The strict definitions of many of these can be subjective at the edges, but they all objectively exis…

I'll agree with everything here except the clean code. Clean code is about optimizing human perception and there can't be a standard for that because humans think in a wide variety of ways and it's further impacted by the level of understanding the human already has on the subject matter the code is dealing with. One person's "clean code" can be another person's nightmare.

I'll back this up with the example of Magento 1. It's a PHP e-commerce platform that has (at first glance) some of the cleanest code you'll ever see in PHP. It looked like the entire development team had come from a Java background. Every component was neatly divided into a PHP object with documented private and public methods. There was a clean MVC separation, with lots of shared behavior abstracted into "Helpers", and a Theme system handling the rendering of the front-end. I have no doubt that the authors of Magento prided themselves on how clean their code was. For them, having spent full-time careers structuring all the many features of their platform into these files, it probably did feel like a clean organization. And when I initially reviewed the code to evaluate using Magento, I also thought it was clean and was part of my choice to use it.

The problem was that when you take something as complex as a full-featured e-commerce system and modularize it so thoroughly, you end up with a literal 7000 classes, and it becomes impossible to figure out the sequence of execution of a single page request through that massive tangle. Is it "clean code" if I have to add debugging print statements to 57 source files to figure out the path of execution that renders a single page?

If I had to choose a circle of hell where I would edit Cyrus IMAP (the worst C code ever) for the rest of eternity, or edit Magento for the rest of eternity, I think I would actually choose Cyrus.

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#73
post #51
post #17

Earlier quoted context omitted.

Do you have any F# favorites? People often mention jet.com repos, but I’m interested to hear about others.

Jet.com has a lot of good ones yeah. One I was looking through the other day is a GitHub repo under /ScottArbeit/Grace and it’s an interesting take on version control. It was a pretty cool repo to look through. To make it easier though, remember that F# source code files are all “in order” so you read them from top down, which Github doesn’t currently have functionality for.

For folks coming here later, you can figure out the order that you should view them in by reading into the `.fsproj` file, which will lay out compile units in order.

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#74

Earlier quoted context omitted.

What makes it easy to read and understand though? I am seriously having a hard time figuring this out. People tout Go for this all the time, but I don't know of a single codebase in it that I think fits that description. When I look through them they look convoluted and just sort of messed up. Things like awkward error handling, dealing with null, capitalization for public/private, magic functions, and imports, and m…

I love Go. I think it depends on what trajectory you followed to reach to Go or any other language. For me it was BASIC -> VB -> Java -> Python for some time -> Go How you feel about Go is how I feel about JavaScript

I went Pascal, C, Perl, Python, Go

And I like Typescript to some point.

I do not think they languages are mutually exclusive (on the like scale). But I am just an amateur hobbyist dev.

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#75
post #67

Earlier quoted context omitted.

What makes it easy to read and understand though? I am seriously having a hard time figuring this out. People tout Go for this all the time, but I don't know of a single codebase in it that I think fits that description. When I look through them they look convoluted and just sort of messed up. Things like awkward error handling, dealing with null, capitalization for public/private, magic functions, and imports, and m…

It’s the complete lack of magic. What you see in front of you is pretty much exactly what happens. You don’t have to keep a cathedral of language semantic subtleties in your head when reading someone else’s code.

Pointer vs value receivers and named returns have so many gotchas that it is not even funny. Lack of magic my ass.

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#76
RT-11 on the PDP-11 (all in PDP-11 assembler). Back in the early 80's you could rebuild it in several different ways, depending on whether you wanted it "single job" (as it was back then) or not.

As an example, here's the PDP-11 assembler to convert a binary number to decimal ASCII (no idea who wrote it, but they certainly made every word count):-

  CNV10:  MOV     R0,-(SP)     ;Subroutine to convert Binary # in R0
  1$:     CLR     R0           ;to Decimal ASCII by repetitive
          INC     R0           ;subtraction. The remainder for each
  2$:     SUB     #10.,@SP     ;radix is made into ASCII and pushed
          BGE     1$           ;on the stack, then the routine calls
          ADD     #72,@SP      ;itself. The code at 2$ pops the ASCII
          DEC     R0           ;digits off the stack and into the out-
          BEQ     2$           ;put buffer, eventually returning to
          CALL    CNV10        ;the calling program. This is a VERY
          MOVB    (SP)+,(R1)+  ;useful routine, is short and is
          RETURN               ;memory efficient.
Courtesy bitsavers.org (http://www.bitsavers.org/pdf/dec/pdp11/rt11/v5.6_Aug91/AA-PD...)

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#77
post #10

At the beginning of the year I was rewriting a SPA and looking for ideas on how to structure a web app. One project I looked at was Github Desktop and I think it has very clean code for an app. https://github.com/desktop/desktop

Now if only GitHub desktops actual UI/UX wasn't a poorly thought out mess of anti-patterns and anti-design.

I use it daily and it works great. It doesn't do all that much, but what it does do saves me a bunch of time. I reach for the git CLI when something goes wrong, but that's not often.

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#78
I'd nominate Java itself.

In the decades Java sources have been available, any of the kazillion junior programmers could debug-step into java.* and see exactly what's happening -- progressive disclosure at its finest for building expertise.

Most other languages have a hard boundary, so the roots of language are a matter of conceptual documentation and experience. Java also offers that fly-over knowledge, but when problems arise, programmers love knowing exactly and seeing directly.

Personally, in a pinch I prefer the actual to the elegant.

Re: Ask HN: What are some of the most elegant codebases in your favorite language?

#80
post #78

I'd nominate Java itself. In the decades Java sources have been available, any of the kazillion junior programmers could debug-step into java.* and see exactly what's happening -- progressive disclosure at its finest for building expertise. Most other languages have a hard boundary, so the roots of language are a matter of conceptual documentation and experience. Java also offers that fly-over knowledge, but when pro…

Yes. I have been burned by this in C#, it’s very frustrating.
Post reply on HN