Poll | |
---|---|
What is your opinion on the Horstmann style? | |
that's absolutely disgusting | |
Meh, it's all right | |
that's amazing | |
Already use it | |
7 users have voted so far |
Duck Penis |
Posted on 19-02-28, 23:49
|
Stirrer of Shit
Post: #50 of 717 Since: 01-26-19 Last post: 1763 days Last view: 1761 days |
So there's a somewhat obscure brace style, called the Horstmann.
I really like it. It saves space, making things more readable, and it also lines up the braces. I can't see any downsides, except for losing the "documentation space" you have with the Allman style, where each brace gets its own line like this:
I've been using it for a fair amount of time (with Allman for functions), and the only downside I can see is that not much software supports it. So why isn't it more popular? When I show people it, the reactions are either "that's absolutely disgusting, never show me it again," or "that's amazing, why haven't I heard of this before?". But nobody seems to be able to explain why they hate it, other than that it's unfamiliar. There was a certain photograph about which you had a hallucination. You believed that you had actually held it in your hands. It was a photograph something like this. |
Kawaoneechan |
Posted on 19-03-01, 01:02
|
12 herbs and spices!
Post: #149 of 599 Since: 10-29-18 Last post: 195 days Last view: 4 hours |
Not a bad style. Probably wouldn't use it but it beats the one with the half-indented braces. |
nyanpasu64 |
Posted on 19-03-01, 09:55 (revision 1)
|
Post: #25 of 77
Since: 10-31-18 Last post: 1189 days Last view: 1116 days |
You lose the ability to use a text editor or IDE to comment out the first line (or swap the first line in an indented block with other lines). https://github.com/ambv/black places trailing commas after each line in a function call or list literal, to explicitly make swapping/commenting elements easy. I noticed that ruamel.yaml's YAML formatting also makes it hard to comment-out or reorder the first line: State 1:
Diff 2: Newline before [maps within lists]. (Neither PyCharm nor ruamel.yaml does this)
Diff 3: indenting lists within maps. (PyCharm does this, ruamel.yaml does not)
- All the above parse to the same tree... I think YAML is too permissive. - There is no "standard" formatting style. I think State 1 confuses people unfamiliar with YAML (like myself at first). - ruamel.yaml uses State 1. - The YAML 1.2 spec uses Option 3 completely. https://yaml.org/spec/1.2/spec.html#id2760193 - Pycharm does 3 but not 2 (but it's completely configurable). - I dislike the first 2 are dumb because you have a Dict[List[Dict]] but the innermost dict is only indented 1 level. i had a longer post written, but it was off-topic (reflecting on YAML's wonky syntax). New thread maybe? |
CaptainJistuce |
Posted on 19-03-01, 10:33
|
Custom title here
Post: #283 of 1164 Since: 10-30-18 Last post: 63 days Last view: 9 hours |
Posted by sureanem Because code formatting comes down to personal preference, and people are using whatever style they're comfortable with already. (I happen to think naming styles is kind of silly. And naming them after specific people is incredibly vain, given most of them have been organically developed numerous times.) --- In UTF-16, where available. --- |
tomman |
Posted on 19-03-01, 11:44 (revision 1)
|
Dinosaur
Post: #176 of 1315 Since: 10-30-18 Last post: 58 days Last view: 18 hours |
I've never liked opening braces just before sentences. And I'm on the opinion that the closing brace should go alone on its own line. I'll stick to the good ol' "explain what you're about to do", that is, the opening brace on the same line as the structure declaration:
EXCEPTION: Constant arrays - those are always a one-liner (if possible):
Licensed Pirate® since 2006, 100% Buttcoin™-free, enemy of All Things JavaScript™ |
creaothceann |
Posted on 19-03-01, 13:46
|
Post: #81 of 456 Since: 10-29-18 Last post: 44 days Last view: 1 day |
Posted by tomman EXCEPTION: 2D data:
My current setup: Super Famicom ("2/1/3" SNS-CPU-1CHIP-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10 |
CaptainJistuce |
Posted on 19-03-01, 14:11
|
Custom title here
Post: #284 of 1164 Since: 10-30-18 Last post: 63 days Last view: 9 hours |
EXCEPTION: segmentation fault --- In UTF-16, where available. --- |
Duck Penis |
Posted on 19-03-01, 14:16
|
Stirrer of Shit
Post: #56 of 717 Since: 01-26-19 Last post: 1763 days Last view: 1761 days |
Posted by tomman How do you find out which block is which if the braces don't line up? With multiple levels of nesting, that gets ugly fast. There was a certain photograph about which you had a hallucination. You believed that you had actually held it in your hands. It was a photograph something like this. |
Duck Penis |
Posted on 19-03-01, 16:39
|
Stirrer of Shit
Post: #57 of 717 Since: 01-26-19 Last post: 1763 days Last view: 1761 days |
Posted by jimbo1qaz No, only the latter.
becomes
There was a certain photograph about which you had a hallucination. You believed that you had actually held it in your hands. It was a photograph something like this. |
tomman |
Posted on 19-03-01, 20:47
|
Dinosaur
Post: #179 of 1315 Since: 10-30-18 Last post: 58 days Last view: 18 hours |
Posted by sureanem It's called "use a competent editor/IDE that can highlight matching braces". This sadly excludes most (if not all?) CLI-based editors and Notepad, but that's fine as I don't use those for coding. Licensed Pirate® since 2006, 100% Buttcoin™-free, enemy of All Things JavaScript™ |
Screwtape |
Posted on 19-03-01, 22:56
|
Full mod
Post: #141 of 443 Since: 10-30-18 Last post: 1101 days Last view: 172 days |
Posted by sureanem Indenting, obviously:
If you tell me you can look up from "}" to find the aligned "{", but can't look up from "}" to find any other aligned text, I'm going to be very doubtful. THAT SAID, much like "which font is the most readable", the biggest factor of all is what you're already used to. If you've spent twenty years finding blocks by looking for isolated "{" and "}" characters while ignoring all the text between them, finding blocks by any other pattern is going to be more effort and feel "wrong". One of the happiest discoveries I've made while learning Rust is the rustfmt command for automatically formatting code. While automatic formatting can never be quite as nice as manual formatting, it's great to be able to type in any old thing, hit "save" and watch it magically become neat and tidy. Less dramatically but more significantly, I don't waste ten minutes trying to reformat something "just right" because it'll snap right back afterwards. Of course, it helps that the Standard Rust Style is pretty close to my preferred style anyway, but if more people used auto-formatting there'd be fewer threads like this one. ;) The ending of the words is ALMSIVI. |
wareya |
Posted on 19-03-01, 22:58
|
Post: #50 of 100 Since: 10-30-18 Last post: 1782 days Last view: 1347 days |
The standard rust style is wrong because it doesn't use allman braces. Fight me. |
Kawaoneechan |
Posted on 19-03-01, 23:11
|
Rated M for Monkey
Post: #151 of 599 Since: 10-29-18 Last post: 195 days Last view: 4 hours |
Autoformat is great and I have it set up how I like in VS10. |
Duck Penis |
Posted on 19-03-02, 00:00
|
Stirrer of Shit
Post: #60 of 717 Since: 01-26-19 Last post: 1763 days Last view: 1761 days |
Posted by tomman Vim supports it, and presumably emacs too. Which CLI-based editors don't, you mean? The fact that you can't do it visually has always been a huge issue for me, that you actually have to move the cursor over there to check. Posted by Screwtape How do you mean? It's true that in trivial examples like this, it's possible. But if you have more difficult examples, then matching them becomes considerably harder:
Especially if the blocks are twice as long.
Fair enough. In practice, I'd reckon the smallest legible font (contingent on eyesight and dpi) is usually the most readable one. I suppose you eventually could get used to the 3x5 fonts though, even if your eyesight isn't good enough, by recognizing the patterns.
Would there? We'd still be discussing to what to set our autoformatters to, no? Case in point: Posted by wareya I use vim, which does have functionality like this (although I rarely use it, since I can't figure out how to configure it), yet I still make threads like this ;) There was a certain photograph about which you had a hallucination. You believed that you had actually held it in your hands. It was a photograph something like this. |
Screwtape |
Posted on 19-03-02, 01:00 (revision 1)
|
Full mod
Post: #142 of 443 Since: 10-30-18 Last post: 1101 days Last view: 172 days |
> Vim supports it, and presumably emacs too. Which CLI-based editors don't, you mean? nano doesn't highlight matching brackets, although it does have a "jump to matching bracket" command. I know this because I was going to reply to tomman with something like "even nano highlights matching brackets!" and then decided to actually fact-check myself. > How do you mean? It's true that in trivial examples like this, it's possible. But if you have more difficult examples, then matching them becomes considerably harder This is the thing I was talking about, where we're looking at the same examples and seeing different things. I look at your examples and see something like: ...and yeah, I can quite clearly see the edges of blocks just by looking at the shape of the left-hand margin. It gets more difficult to guess which line corresponds to a given closing-bracket with a bucket-shaped structure, where you have deeply-nested blocks and then many lines at the deepest level: ...especially if the inner-most block is taller than the screen height. Still, that's going to be taxing for *any* kind of visual recogition, since it's harder to extrapolate accurately the further you go.> We'd still be discussing to what to set our autoformatters to, no? Autoformatters aren't infinitely configurable, so the discussion only has to cover the available options, not every possible variation. Also, autoformatters have defaults, so one specific configuration is vastly easier to set up and maintain, and every alternative has additional costs. Most people get a lot less invested in their formatting choices when they have to spend an afternoon wrestling with config choices or trying to talk the maintainer into accepting their patches. The ending of the words is ALMSIVI. |
neologix |
Posted on 19-03-02, 06:19
|
Post: #28 of 49 Since: 10-29-18 Last post: 1901 days Last view: 1786 days |
As usual, JavaScript is the odd one out but for a really stupid reason this time (instead of just a regular stupid). Put the { on the same line as the (...) or risk potential automatic semicolon insertion. Same for . and any other operators with right-hand sides like + . |
Kawaoneechan |
Posted on 19-03-02, 11:45
|
Does not care, will put on the maid outfit
Post: #154 of 599 Since: 10-29-18 Last post: 195 days Last view: 4 hours |
tomman |
Posted on 19-03-02, 12:15
|
Dinosaur
Post: #183 of 1315 Since: 10-30-18 Last post: 58 days Last view: 18 hours |
Posted by Screwtape Thanks for clearing things up. That shows how much I deal with CLI editors, AKA "nothing" - I only use nano for quick edits and little else, but it's interesting to know that it can actually deal with bracket navigation. Anyway, my point still stands: if you're writing some code and your editor doesn't support any kind of bracket highlighting/navigation, you should really switch to a better editor. Licensed Pirate® since 2006, 100% Buttcoin™-free, enemy of All Things JavaScript™ |