Earlier quoted context omitted.
What? Not for me, not with cindent on. It indents each if statement by one level, just like it "should". How would it somehow know to not indent them?
An auto-indenter could easily detect the idiom if hit backspace after the auto-indent it produced after the first 'if'. Once you have your two ifs at the same indent, the indenter can use that info to keep them at the same indentation level. It could even assume you mean (a&&b) vs (!a&&!b) and not the three-way (a&&b), (a&&!b), (!a) when you follow it with an else block (I think that would be the best heuristic) Impl…
Ifs and &&s and Plan 9's Source Code
91–100 of 150 posts
Re: Ifs and &&s and Plan 9's Source Code
#92Earlier quoted context omitted.
Because something you do relatively early in the compiler is throw away all of the structure of the source, including flattening nested expressions into a linear IR. Mapping back to line numbers in the debugger is a bit hacky to begin with, and mapping back in an even more fine-grained way would be more complex still.
Both line and column information are completely carried through the process, and put into debug info, these days. It's not hacky, it's actually completely well structured. Even debugging info for C/C++ macros is there and done properly. None of this is new. DWARF2 (or 3 or 4), the standard debugging format for all non-MS compilers, has been able to do this well since 1993 .
In Clang/LLVM, for example, nodes are annotated with debug information using LLVM's metadata system. However, it is strictly optional for any given transformation to preserve the metadata on IR nodes. So what makes it through after optimizations is kind of a "best effort" affair.
Re: Ifs and &&s and Plan 9's Source Code
#93 #if foo #if bar #send obj:dosomethingRe: Ifs and &&s and Plan 9's Source Code
#94How about using this alternative form: if((b != nil) &&(b->qid.type==a->qid.type) &&(b->qid.path==a->qid.path) &&(b->qid.vers==a->qid.vers) &&(b->dev==a->dev) &&(b->type==a->type)){ fprint(2, "cp: %s and %s are the same file\n", an, bn); ret = 1; } It keeps almost the same visual look and it uses the common convetion, except for the && at the beginning of each line.
if(b != nil){ if(b->qid.type==a->qid.type){ if(b->qid.path==a->qid.path){ if(b->qid.vers==a->qid.vers){ if(b->dev==a->dev){ if(b->type==a->type){ fprint(2, "cp: %s and %s are the same file\n", an, bn); ret = 1; }}}}}} I will never understand the allergy to multiple braces on one line.
Re: Ifs and &&s and Plan 9's Source Code
#95Oh god that code is fucking hideous. If someone who worked with me wrote that I'd talk to them about it and make sure they never did anything like that ever again. From the terrible argument names to the abuse of the single line if syntax (which should never be used anyway, always use curly braces.)
Re: Ifs and &&s and Plan 9's Source Code
#96Earlier quoted context omitted.
Short circuit is guaranteed by the language standard. On top of that, plan9 comes with its own C compiler so the people who wrote this also wrote the compiler used to compile it.
I see, I just have no idea how complete the Plan 9 tools are. Working with in-house domain specific language interpreters or compilers I've twice seen unary minus support missing so I assumed anything was possible when something's not fully commercialized.
http://plan9.bell-labs.com/sys/doc/compiler.html
You can nerdmuse yourself a little by googling why it had a
#pragma hjdicksRe: Ifs and &&s and Plan 9's Source Code
#97Earlier quoted context omitted.
Both line and column information are completely carried through the process, and put into debug info, these days. It's not hacky, it's actually completely well structured. Even debugging info for C/C++ macros is there and done properly. None of this is new. DWARF2 (or 3 or 4), the standard debugging format for all non-MS compilers, has been able to do this well since 1993 .
It's hacky in the sense that it's somewhat ad-hoc the manner in which line/column information makes it through from the source text, through the intermediate representation and optimizations, into the generated code and debug information. In Clang/LLVM, for example, nodes are annotated with debug information using LLVM's metadata system. However, it is strictly optional for any given transformation to preserve the me…
Not all compilers even really degrade. GCC does post-hoc variable tracking (and thus is mostly unaffected by optimization except when values are optiized out completely). For declarations and statements, the info is always on the declaration, so it won't be lost.
Both compiler guarantee that at -O0, all debug info will be kept.
Re: Ifs and &&s and Plan 9's Source Code
#98Earlier quoted context omitted.
I believe that the layout of code is done by humans for humans. An auto code formatter destroys all of that meaning. I blogged about this more here: http://www.databasesandlife.com/do-not-use-automatic-code-re...
Yeah, I saw that. I think it's misguided. The amount of time spent on arguing about style far exceeds the time savings of the changes you propose. People can get used to different formats quite easily, but time spent arguing about and maintaining formats can never be recovered. Also, your formatter looks pretty brain-dead. clang-format formats all of those cases (in C++) as in your green examples with Google style tu…
So I can just run it over my code, no matter what editor I used and the code is fine. No arguing what is right, no thinking about where to put some stupid spaces or how to break a fucking line, just run gofmt, done.
Re: Ifs and &&s and Plan 9's Source Code
#99I use this convention often for loops: for (int x = 0; x The semantics are kind of like using a comprehension.
I abhor deep indents, and when I have deeply nested loops that just serve to trivially enumerate things, in C I sometimes add a helper function for the iteration. e.g. instead of: for(int i=0;i it might become i=j=k=0; while(all_frob_indices(&i,&j,&k)){ .... with all_frob_indices() doing the i++; if(i>N){ i=0; j++ }... This makes code look more similar to e.g. itertools-constructs in python where you can easily make…
Re: Ifs and &&s and Plan 9's Source Code
#100 And[
a,
b
]
You can also rely on the fact that logical expressions are always short-circuited, so False && Print["won't be printed"], doesn't print anything.Finally, you can put a bunch of conditions in a list and do And @@ list.