4 ms·
I find NetSurf's source code beautiful and quite easy to read and follow, and straightforward. I am impressed. It's like the pure version of "makes sense". It's
by jraph 6y ago
I find NetSurf's source code beautiful and quite easy to read and follow, and straightforward. I am impressed. It's like the pure version of "makes sense". It's also split into independent libraries that can be used outside of NetSurf, which make them useful on their own, and NetSurf very modular. If I had to implement something that requires a feature implemented in a browser, I'd seriously consider one of them. Especially their CSS parser and engine.
I really recommand to have a look at the code.
- userbinator 6y agoTo be honest, I wouldn't exactly call this "beautiful"... https://source.netsurf-browser.org/libdom.git/tree/src/core/document.c#n117 https://source.netsurf-browser.org/libdom.git/tree/src/core/... https://source.netsurf-browser.org/libdom.git/tree/src/core/implementation.c#n62 https://source.netsurf-browser.org/libdom.git/tree/src/core/... https://source.netsurf-browser.org/libcss.git/tree/src/parse/parse.c#n416 https://source.netsurf-browser.org/libcss.git/tree/src/parse... Looks like the authors have a severe case of goto-phobia that causes a quadratic explosion of copy-pasted code in the error-return paths. Some of the files also feel like they have been translated into C from C++ or some other OO language by some automated tool, resulting in some very long "namespaced"-looking identifiers. Then again, I don't think Firefox or WebKit code is that much better either, so my impression of this codebase is neither great nor horrible. As "beautiful" is subjective, to give a reference for what I'd consider beautiful, look at BSD or early UNIX.
- tomcam 6y agoI also find the code to be clear and easy to read. Looking at the samples you provided, I feel like I could step right in and work on this project with minimal cognitive load. I actually like the style.
- Hello71 6y agothere are other "C++ programmer trying to write C" anti-patterns, such as typedefed structs and one "class" per file, leading to terrible performance without LTO. stuff like https://source.netsurf-browser.org/libdom.git/tree/src/core/cdatasection.c https://source.netsurf-browser.org/libdom.git/tree/src/core/... has more signs of excessive C++ love: "vtable", "protected", etc. I don't know that these things are inherently bad, but they certainly don't exist in C.
- userbinator 6y ago...and despite that, it still manages to feel faster than the mainstream browsers, which says just how much extra overhead those have, and that there is still "more room at the bottom" to trim this one down some more too.
- ajxs 6y agoI agree with the above sentiment regarding the 'gotophobia'. Still, at a glance it looks like a codebase where lots of care and diligence has been taken in documentation and code presentation.
- Thorham 6y agoThat first one is madness! That's not even goto-phobia, that's just not knowing what arrays and loops are. The third one is true goto-phobia of course. Crazy how people can't see the mess they make by avoiding goto for the sake of avoiding goto.
- catsarebetter 6y agoTaking a look, it's been a while since I've heard someone speak that highly about any source code, I admit that alone makes me very intrigued
- jraph 6y agoI don't see many people speaking about code they find good. I'd appreciate this. Pointing out bad code is usual, but good ones? My comment may seem exagerated but that retranscribes very well how I felt when I discovered this code. Often, I'm overwhelmed by the code tree of medium to big-sized projects, with many abstractions and complicated folder structures. This is a browser and yet it was easy to figure out where to find the parts I was interested in and to understand what the code did. Now, one can always find problems and discuss about the lack of gotos or arrays, but if as a complete outsider I can navigate and understand the code, and even feel that I could hack it quite easily with no documentation, something must be right with it. I'm not in any way connected to the project, I don't even use this browser (sadly, it is too impractical).