4 ms·
Another "crazy" idea: I'd like the compiler to reformat code to match strict style conventions. Why? Sometimes there's no "right" style. Sometimes novices need
by gwbas1c 5y ago
Another "crazy" idea: I'd like the compiler to reformat code to match strict style conventions.
Why? Sometimes there's no "right" style. Sometimes novices need training wheels. In the long run, style doesn't matter, but in big projects code is easier to read when style is consistent. It's also easier to onboard when code follows industry-standard styles.
Would it be better when a language gently pushes everyone to the same style?
- zamadatix 5y agoIt's definitely been done before, Zig comes to mind immediately but I'm pretty sure it wasn't the first place I've seen it done first party.
- throwaway17_17 5y agoThat’s an idea I’ve been playing around with for my personal language. If I do decide to release it, I have a feeling there will be common style rules that will be required for any ‘library’ code (it would be like if C++ files had to meet google style guides to be posted to some central collection repo). I think the compiler could implement the conversion, but it could require a programmer supplied ‘translation’ file (like including Unicode to ASCII substitutions, or required macro unrolling to some language core set of language features). That would allow for anyone to keep there code formatted in the most logical way for them, but would allow for a common format for distribution. I would also think going the other way, from public style to private should be a possibility. I don’t know if I will ever actually put my personal language out for release, but I’ve had two acquaintances repeatedly tell me (along with several HN commenters) that I really should at least release some blog posts about the language. Currently it is just my daily driver for work related programming and it compiles to C++, C, or JavaScript.
- userbinator 5y agoIn other domains, that is called authoritarianism.
- nostrademons 5y agoThis has been a part of Go culture from the beginning. You avoid style conflicts because you just run everything through 'gofmt' before checking it in. It's slowly catching on in other languages, eg. Clang now has clang-format and IntelliJ can auto-reformat your code according to a rule config you set before each check-in.
- yosito 5y ago> code is easier to read when... This is almost always a subjective opinion. I've worked on many projects where people reformat large portions of the codebase to make it "easier to read", and in the end they waste a bunch of time, make using `git blame` a pain, and subjectively either make no difference in code readability or make the code harder for half the team to read. > I'd like the compiler to reformat code... Why is this the compiler's job? Most people aren't reading code after it's been compiled. In most of the languages I've worked with, this is handled by a formatter + styleguide/config that either runs in the IDE on save or on a git hook, or both.
- gwbas1c 5y ago> Most people aren't reading code after it's been compiled Ever start a new job with a bulk of code you didn't write? Worse, ever take over code written by novices who ignore common conventions? The whole point is to see if having a standard style is easier in the long run.
- yosito 5y agoStill, why would you be reading compiled code?
- sseagull 5y ago> Ever start a new job with a bulk of code you didn't write? Worse, ever take over code written by novices who ignore common conventions? Yes, I have seen lots of this in scientific computing. However, things like too many/not enough spaces, line widths, etc, are never a huge hindrance for me. What does make code "hard to read" are things like bad and inconsistent variable/function/class names, bad inheritance practices, bad file organization, and not adhering to common language idioms. That stuff is rarely, if ever, caught by linters. Great talk by Raymond Hettinger about this: https://www.youtube.com/watch?v=wf-BqAjZb8M https://www.youtube.com/watch?v=wf-BqAjZb8M
- speedgoose 5y agoI have that at work with javascript/typescript and eslint.
- deleted 5y ago[deleted]