|
Has anybody ever made that mistake more than once? Maybe if they code with their eyes closed. If a conditional has no braces, it executes at most one line. It's an easy rule to learn. If you happen to add another line to a single-line if-statement then the error is right under your nose, because the problem area is at most three adjacent lines long. The above code sticks out like a sore thumb to me.
|
# ? Mar 25, 2012 00:16 |
|
|
# ? May 15, 2024 23:05 |
|
Optimus Prime Ribs posted:Everyone has their preferred way to write code. If you don't follow the company standards for style you're not getting through the code-review. May as well get used to it in college.
|
# ? Mar 25, 2012 00:16 |
|
Instead of thinking of the braces as belonging to the if statement, think of them as denoting a single compound statement (because that's what they do, in the grammar). A branch of an if-statement always contains a single statement, but that single statement may be a compound statement. It's not that hard to get used to verifying that the statement after an 'if' is of the correct form. On the other hand, if the code style that you have to follow specifies that you need to use single-statement blocks, then that trumps all the other reasons you can think of for not doing it.
|
# ? Mar 25, 2012 01:42 |
|
Volte posted:Instead of thinking of the braces as belonging to the if statement, think of them as denoting a single compound statement (because that's what they do, in the grammar). A branch of an if-statement always contains a single statement, but that single statement may be a compound statement. It's not that hard to get used to verifying that the statement after an 'if' is of the correct form. code:
|
# ? Mar 25, 2012 01:48 |
|
That's almost cute, in a pathetic sort of way.
|
# ? Mar 25, 2012 04:34 |
|
Haystack posted:That's almost cute, in a pathetic sort of way. That's wh...
|
# ? Mar 25, 2012 05:00 |
|
In a game engine I am using for a class, I found this shining gem:code:
In this engine's defense, it is actually really good, but how the gently caress does that one slip on by. EDIT: Apparently it didn't and my team just never merged in the changelist with the fix The Glumslinger fucked around with this message at 08:20 on Mar 25, 2012 |
# ? Mar 25, 2012 06:57 |
|
Look Around You posted://PHP junk code I'm more than a few pages late, and I'm not sure if you're being ironic but I think it's so popular because there's a low barrier to entry (it's pretty much universally supported at every web host) and the syntax is relatively easy to learn. This is excellent for commercial developers, and amateur coders alike; it runs everywhere! There are also no includes, namespaces, classes, functions, etc. to get started either, so again it looks like a friendly language to learn for beginners. It also sort of was/is a natural next-step after learning html. The discussion in this thread made me rethink using PHP for my future projects after seeing some of the things that PHP does like accepting concatenated variables (wtf?) so I might be looking into Ruby, or Mono + ASP for my dynamic web pages. Anyway has PHP always been this terrible, or is this just a result of bloat over time? Knyteguy fucked around with this message at 10:25 on Mar 25, 2012 |
# ? Mar 25, 2012 10:22 |
|
Not to get all Bret Victor up in here, but seriously why is it still necessary to even discuss brace-style & indentation? Code is easily tokenizable; after all that is a criteria for compilation (and if it isn't tokenizable, modern compilers can usually figure out the syntax errors or make and educated guess - for display only mind you). Why doesn't every IDE just represent - by default - the code in whatever format the user likes? We don't need to actually look at the raw txt unless something is seriously broke. Make that the fallback; show the token stream indented as the user prefers by default. Make indentation a as low level as choosing whether line endings are \n or whatever else. Carthag Tuek fucked around with this message at 11:03 on Mar 25, 2012 |
# ? Mar 25, 2012 10:54 |
|
Carthag posted:Not to get all Bret Victor up in here, but seriously why is it still necessary to even discuss brace-style & indentation? It's a topic everyone can have an opinion on. In the sense that there is no understanding or insight required to participate. the colour of the bike shed should be chartreuse
|
# ? Mar 25, 2012 11:04 |
|
tef posted:It's a topic everyone can have an opinion on. In the sense that there is no understanding or insight required to participate. That's exactly my point though, it's not important for the end result, and it's not important to you how I like to format my code. We should both just set up our dev environment to display the code how we like it and the underlying representation can be whatever (as long as its readable). This way, if you like 8-space tabs and GNU-style braces, and I like 2-space tabs and banner braces, we can both do our own thing, and not care at all what the other does. Also it makes diffs more readable.
|
# ? Mar 25, 2012 11:10 |
|
In short: Neither of us care, so hide the crap from us.
|
# ? Mar 25, 2012 11:14 |
|
Knyteguy posted:I'm more than a few pages late, and I'm not sure if you're being ironic but I think it's so popular because there's a low barrier to entry (it's pretty much universally supported at every web host) and the syntax is relatively easy to learn. This is excellent for commercial developers, and amateur coders alike; it runs everywhere! Oh I know why it's popular. The low barrier for entry is actually part of the problem with PHP though. From what I've seen, a lot of the culture relies on cut-and-paste coding with little to no understanding of what it's actually doing or of the underlying mechanics. Php coding style and common practices are pretty horrible too. It's commonly accepted to fully intersperse logic with presentation (that is, putting actual code that does stuff on data in the same files that output HTML), which is a pretty terrible practice. Oh, and php just removed register_globals and magic quotes in this release. They also released it with 90 test failures (and 44 expected ones), some of which actually segfault, which will (probably) bring down your entire instance of PHP (and thus your site).
|
# ? Mar 25, 2012 13:16 |
|
Carthag posted:In short: Neither of us care, so hide the crap from us. This entire thread is bike shedding. This is exactly where the crap should be.
|
# ? Mar 25, 2012 14:21 |
|
tef posted:This entire thread is bike shedding. This is exactly where the crap should be. Bubblesort in production is special case of bikeshedding.
|
# ? Mar 25, 2012 18:17 |
|
Hughlander posted:If you don't follow the company standards for style you're not getting through the code-review. May as well get used to it in college. Keep two autoformatting profiles, one to put code to a sane and sensible (i.e. what you like) format, one to put code to whatever crazy haphazard methods are used by the group.
|
# ? Mar 25, 2012 21:05 |
|
I have a personal style, but I can read and write multiple styles without caring either way, certainly not enough to spend time maintaining multiple code formatting profiles. If you're so used to your personal style that you have issues when reading or writing other common styles, you should consider exposing yourself to more external code. You should also experiment with other programming languages so that you're not attached to the syntax of your pet language. The algorithms and data structures are what matter.
|
# ? Mar 25, 2012 22:28 |
|
Toady posted:I have a personal style, but I can read and write multiple styles without caring either way, certainly not enough to spend time maintaining multiple code formatting profiles. The only times I'm actually annoyed at people for forcing styles on me is when it's really frustrating to apply or contrived to the point of being detrimental. I worked with a guy that somehow got it passed as a company policy that any temporary variables used in counters had to be reused and defined at the top of every function. So every piece of code was like: code:
I've also worked with someone that required all variables go out of scope at the very last point they're used, and at the end of a function no variables or objects that aren't the return value/arguments were allowed to be in scope, so things ended up as: code:
This also wasn't just someones personal preference, it was applied during code reviews and some people actually had code retroactively rejected when the policy culprit happened to notice it later. Edit; you may have guessed, I work and have worked in some of the worst imaginable software dev houses. The Gripper fucked around with this message at 00:56 on Mar 26, 2012 |
# ? Mar 26, 2012 00:53 |
|
Those are arguably uncommon styles (I hope).
|
# ? Mar 26, 2012 01:01 |
|
Toady posted:Those are arguably uncommon styles (I hope).
|
# ? Mar 26, 2012 01:07 |
|
I'm genuinely curious about the rationale behind those policies. The "at the end of a function no variables or objects that aren't the return value/arguments were allowed to be in scope" policy sounds like a hilarious misunderstanding of the language and/or the result of a hilarious battle with some lovely compiler.
|
# ? Mar 26, 2012 01:20 |
|
I can imagine someone wanting that in C++ due to destructors "interfering" with the control flow. The generalization would be "break, continue, goto, and return should never have to run any destructors before reaching their destination." It's then easier to apply that rule to all locals instead of making it only apply to types with nontrivial destructors. I mean, I think that would be a deeply problematic sign of a programmer who refuses to accept the C++ "say what you mean and learn to use a debugger" philosophy, but tons of those people exist. I have no idea what you'd want this rule in a language without destructors, unless, yeah, it's the legacy of some awesome compiler bug. rjmccall fucked around with this message at 02:06 on Mar 26, 2012 |
# ? Mar 26, 2012 02:04 |
|
pokeyman posted:I'm genuinely curious about the rationale behind those policies. The "at the end of a function no variables or objects that aren't the return value/arguments were allowed to be in scope" policy sounds like a hilarious misunderstanding of the language and/or the result of a hilarious battle with some lovely compiler. The Gripper fucked around with this message at 02:55 on Mar 26, 2012 |
# ? Mar 26, 2012 02:49 |
|
Over 1200 lines of this on a site I'm supposed to transfer to new hosting. I shouldn't have ever looked at the code and just moved it.code:
|
# ? Mar 26, 2012 16:23 |
|
I wonder what would happen if somebody invented a What You See is What You Get tool for C or Java or something.
|
# ? Mar 26, 2012 16:28 |
|
Suspicious Dish posted:I wonder what would happen if somebody invented a What You See is What You Get tool for C or Java or something. Netbeans has a drag and drop editor for working with Swing and it creates some horrible looking java code but the IDE does it's best to keep it hidden from the developer. IIRC, generated code is auto collapsed in the class and read-only.
|
# ? Mar 26, 2012 17:28 |
|
Visual Studio's autogenerated code from the GUI designer is verbose, but usually perfectly readable (although it's hidden away in a separate file so you usually don't have to look at it).
|
# ? Mar 26, 2012 18:10 |
|
biochemist posted:Over 1200 lines of this on a site I'm supposed to transfer to new hosting. I shouldn't have ever looked at the code and just moved it. Yay, McAlister's
|
# ? Mar 26, 2012 19:05 |
|
lamentable dustman posted:Netbeans has a drag and drop editor for working with Swing and it creates some horrible looking java code but the IDE does it's best to keep it hidden from the developer. IIRC, generated code is auto collapsed in the class and read-only. Plorkyeran posted:Visual Studio's autogenerated code from the GUI designer is verbose, but usually perfectly readable (although it's hidden away in a separate file so you usually don't have to look at it). Yeah, arguably that's data with a mustache on. I was thinking of code with logic and that sort of fun stuff. Something like this.
|
# ? Mar 26, 2012 19:17 |
|
Suspicious Dish posted:Yeah, arguably that's data with a mustache on. The interface builder in XCode doesn't even generate code, it just serializes the objects you set up, so it literally is data. You can set up stuff in code too, but usually there's no need unless you have some complex stuff going on. Suspicious Dish posted:I was thinking of code with logic and that sort of fun stuff. Something like this. Just had a look, it looks like if you try to do anything more advanced than very very simple stuff, it'll turn into a world of poo poo in 5 seconds.
|
# ? Mar 26, 2012 19:42 |
|
This entire post: http://blog.feabhas.com/2012/03/on-the-evolution-of-programming-style/
|
# ? Mar 26, 2012 20:02 |
|
I'm disappointed he didn't wrap it in a lambda and pass it to std::async().
|
# ? Mar 26, 2012 20:28 |
|
Is this where we rewrite it to not suck while making embarrassing mistakes?code:
|
# ? Mar 26, 2012 21:06 |
|
Edit: nevermind
HappyHippo fucked around with this message at 21:49 on Mar 26, 2012 |
# ? Mar 26, 2012 21:46 |
|
Suspicious Dish posted:Yeah, arguably that's data with a mustache on. I was thinking of code with logic and that sort of fun stuff. Something like this. There's Labview, which is about as horrible as it seems. The total number of man-hours wasted by mechanical and industrial engineers dragging teensy little lines around on a screen would probably put a man on Mars.
|
# ? Mar 27, 2012 00:17 |
|
I've never seen a drag and drop programming language that doesn't turn into a bundle of poo poo almost immediately when doing anything non-trivial. See SSIS for a prime example.
|
# ? Mar 27, 2012 00:20 |
|
I took an electronic arts class in college in which in which I did my final project in Max/MSP and I blew my instructor's mind by actually skeleton-ing out the program before diving in and stringing connections around willy-nilly the way musicians using Max always do.
|
# ? Mar 27, 2012 00:32 |
|
evensevenone posted:There's Labview, which is about as horrible as it seems. The total number of man-hours wasted by mechanical and industrial engineers dragging teensy little lines around on a screen would probably put a man on Mars. LabView is a compound horror in that it doesn't just produce an unmaintainable mess of rainbow colored spaghetti code, it produces an unmaintainable mess of rainbow colored spaghetti coded that is very likely in control of a large dangerous hunk of machinery. Fun LabView Stuff: 1) A LabView VI code block can operate either like an object with it's own state, or as some kind of globally public method with stored state that can be modified by anyone calling the code. There's no visual indication of which mode the VI is in, and the mode is set by a checkbox in an obscure settings panel. An accumulator VI that sums up all of the data sent into it over time may behave very oddly if it's used in two places. 2) Speaking of state - shift registers, if not initialized on first use, can store their values between different executions of the code so long as you don't shut down the IDE between runs. The bug you have now may be due to something you did the last time you ran the code. 3) Some LabView hardware controllers spin up their own internal threads, and if you put two such controllers in the same program they'll deadlock each other a lot. LabView can detect deadlocks and silently spins up new threads so your program doesn't crash (or even generate an error message), but then it leaves the old deadlocked threads in place. You know you've hit this problem when your system slows to a crawl after five minutes and the system monitor shows 8,624 active threads. 4) LabView's motor controllers can operate in two regimes of stability: (1) If you want a motor to turn clockwise, power up the coils that turn it clockwise. This is the sane mode. (2) Power up both the coils that turn the motor clockwise and counter-clockwise to 100% so the opposing torques hold the shaft in place. If you want to turn clockwise, power down the counter-clockwise coils to 90% so the clockwise coils begin to win. This is the "Hey do you smell that hot electronics smell? *touches motor and burns off outer skin layer*" mode.
|
# ? Mar 27, 2012 01:44 |
|
Labview sounds like a really good idea the more distance I get between it and myself, thanks for reminding me the execution isn't quite up to scratch.
|
# ? Mar 27, 2012 01:50 |
|
|
# ? May 15, 2024 23:05 |
|
The idea of controlling industrial machinery on anything but a PLC sounds insane. PLC programming is a horror of it's own, but not in a "this is dangerous" sort of way.
|
# ? Mar 27, 2012 02:25 |