3 ms·
I take the author's point, but I still prefer languages that can be parsed in a single pass. Most commonly, this means it is written in a top down style where e
by norir 2y ago
I take the author's point, but I still prefer languages that can be parsed in a single pass. Most commonly, this means it is written in a top down style where every reference is defined somewhere above the usage. It then naturally falls out that programs can be easily read bottom to top and the presentation will make sense.
You can put one intro comment at the top that tells the reader to go to the bottom and read from there. The actual main method code is almost always the most important and reliable information anyway.
In vim, I can open the file 'G' to the bottom, scroll up to the main function and start reading. Any def I want to look up I can select and find with '?'. The main catch is you need qualified imports rather than c style to make this work the best.
Writing in this style, I find that I don't need files. Everything I need for a module is already in a single file. I don't even need lsp since I personally don't ever use autocomplete in any context, programming or otherwise, and search is trivial when all defs are in a predictable order in a single file.
Now if I were writing a book, rather than a program, I would probably use a different format. Generally though, I think we should let programs be programs and books be books.
- packetlost 2y agoI get that this is a matter of personal style, but when scanning a program that means you start from the most specific (ie. lowest in the call stack) layer of abstraction, which is IMO not the most intuitive way to reason about an application. You can always read in reverse order, but again, that's the opposite of what I would intuitively consider.
- norir 2y agoIt doesn't matter if it is intuitive or not if it is consistent. It will become intuitive once you have worked in this style for at most a few days.
- deleted 2y ago[deleted]
- cxr 2y ago> this means it is written in a top down style where every reference is defined somewhere above the usage. It then naturally falls out that programs can be easily read bottom to top So not top-down[1] then, but the opposite. 1. <https://www.teamten.com/lawrence/programming/write-code-top-down.html https://www.teamten.com/lawrence/programming/write-code-top-...>
- norir 2y agoRegardless of semantics, I mean that a compiler will read the code from the top to the bottom and when it encounters a reference, it either must have already been defined or it doesn't exist and the compiler should error out. This is orthogonal to top down in the way that your link suggests.
- deleted 2y ago[deleted]