05 November 2018, 17:58 | #701 | |||
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
Quote:
Quote:
Quote:
Completely agree. |
|||
05 November 2018, 18:02 | #702 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
When reading code with said curlies, you do not know what they mean. However in Basic for example, you immediately see the kind of block.
What does "}" mean ? You don't know without having to look above. What does "END FOR" or "NEXT" mean ? You know immediately. |
05 November 2018, 18:06 | #703 | ||||
Registered User
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 41
Posts: 3,773
|
Quote:
Quote:
Quote:
Quote:
|
||||
05 November 2018, 18:09 | #704 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,711
|
It's true, C often gets really messy if you nest curlies.
Especially if you code like this { } |
05 November 2018, 18:19 | #705 |
Registered User
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 41
Posts: 3,773
|
That's by far my preferred style. I do always make sure there's an empty line before and after though. And with a decent editor (eg vim), the opening/closing braces are highlighted, so you know what belongs to what immediately.
|
05 November 2018, 18:22 | #706 | |
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
Quote:
Ah. I guess I’m totally used to them. This is probably part of the reason a lot of places have a ~30 line code limit on method size in their coding standards. I use astyle to indent things and most modern code editors highlight the other end of the loop. So I just look at the top or bottom of the block to see what’s going on. I’m not fond of END FOR etc. I don’t need the distinction. But if you’re not used to it I guess it’s harder. But it’s something you can get used to. I don’t feel the distinction adds much value. Java, C#, C++ etc all do it the same way more or less. So it’s somewhat of an industry standard. Ish. It did amuse me back in the naughties when developers would go crazy about the curlies as they had to switch from VB6 to C#. I saw some insisting they couldn’t do it. They could. Didn’t take long to get used to it |
|
05 November 2018, 18:27 | #707 | |
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
Quote:
You’re the guy who does that!!! I like my braces with equal indents. Easier to keep track of! Now I just need to track down the guy who doesn’t put curlies around else statements... |
|
05 November 2018, 18:30 | #708 | ||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Quote:
Now perhaps we have different definitions for what's ugly. It could be interesting to compare some coding examples written in different languages. But we're already OT enough. Quote:
Quote:
Quote:
The C++ compiler won't be slower than C compiler if you write C++ like C. Neither will the compiled code. But you cannot say C is nice while in the same time saying C++ is ugly : the syntax is exactly the same ! |
||||
05 November 2018, 18:32 | #709 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,711
|
I'm mostly joking, people can code in whatever style they want. Some of us C programmers are perfectionists and are not having it when we see other coding styles.
@plasmab: I don't put curlies around else statements if both of the conditions are oneliners. F.ex. Code:
if (a) stuff1(); else stuff2(); if (b) { stuff1(); } else { stuff2(); stuff3(); } |
05 November 2018, 18:37 | #710 | |
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
Quote:
I’ve seen someone apply that logic with a Macro that had 4 lines of code in it. The macro wasn’t encapsulated in curlies. The consequences were actually v serious. It was a safety critical application. |
|
05 November 2018, 18:38 | #711 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Quote:
Code:
if (cc) { thing1(); thing2(); } else thing3(); Neither for one-line if, or whatever. Makes it bearable, but i won't say it's good. But, who will find THAT readable ? Code:
} } } } } } } |
|
05 November 2018, 18:45 | #712 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,711
|
Where did you find my code??
Yeah, that is really awful and always a pain to read. @plasmab: Yeah I always use curlies if I use a macro in it, I've done that mistake before and it can make you really confused as to why the code doesn't work as intended. |
05 November 2018, 18:48 | #713 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,630
|
|
05 November 2018, 18:50 | #714 | |
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
Quote:
And it can result in people getting shot. For real. No joke. Don’t ask me to elaborate on that unless you’re handing me a beer in a pub. I curly everything obsessively now. Every macro should have a curly round it unless you have a reason not to. |
|
05 November 2018, 18:55 | #715 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
C has a beautiful simplicity. It's the most "What you see is what you get" programming language (excluding asm for a sec).
You can almost always guess what the compiler will do behind the scenes. I don't think you can do that with other languages. This is not to invalidate other views. I respect other views, I just wanted to add mine. |
05 November 2018, 18:58 | #716 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,711
|
That's not true for modern compilers in high optimization mode with auto-vectorization and what not. If you can still predict what it will output, then you must be from another planet or something.
|
05 November 2018, 19:05 | #717 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
|
05 November 2018, 19:07 | #718 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
|
Quote:
(I have no example, but i heard this can happen.) |
|
05 November 2018, 19:39 | #719 |
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
It’s a fail in many ways. The macro was sh1t. The person using the macro didn’t check (or understand) that it needed curlies. They just equated one line of code with no need for them. They ignored the compiler warning because they didn’t understand it. The person reviewing didn’t spot it. The person testing the change didn’t test it properly. All of this led to a v dangerous real life situation. Really there is no need to not put braces round everything. I wish I could make compilers enforce it. |
06 November 2018, 02:15 | #720 | ||
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,649
|
Quote:
CP/M Quote:
|
||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Any software to see technical OS details? | necronom | support.Other | 3 | 02 April 2016 12:05 |
2-star rarity details? | stet | HOL suggestions and feedback | 0 | 14 December 2015 05:24 |
EAB's FTP details... | Basquemactee1 | project.Amiga File Server | 2 | 30 October 2013 22:54 |
req details for sdl | turrican3 | request.Other | 0 | 20 April 2008 22:06 |
Forum Details | BippyM | request.Other | 0 | 15 May 2006 00:56 |
|
|