4 ms·
I'd make this parse as "if (a) { if (b) { c; d; } }" and leave it at that. One of the reasons for significant indentation is to discourage this kind of code lay
by SupremumLimit 12y ago
I'd make this parse as "if (a) { if (b) { c; d; } }" and leave it at that. One of the reasons for significant indentation is to discourage this kind of code layout because it's hard to read.
- sanxiyn 12y agoOkay, concretely, I'd like to see a translation of this real-world C++ code (taken from V8): #define RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ if (!__allocation__.IsRetry()) { \ __object__ = __allocation__.ToObjectChecked(); \ if (__object__ == (ISOLATE)->heap()->exception()) { RETURN_EMPTY; } \ RETURN_VALUE; \ }
- SupremumLimit 12y agoThis seems to be missing backslashes. I haven't considered how to deal with preprocessor macros, but the if statement converts very simply: if !__allocation__.IsRetry() __object__ = __allocation__.ToObjectChecked() if __object__ == (ISOLATE)->heap()->exception(); RETURN_EMPTY RETURN_VALUE This isn't ambiguous like the example you suggested before.
- sanxiyn 12y agoThat doesn't work, because if statement is inside preprocessor macro and must be in a single line.
- SupremumLimit 12y agoI see what you mean. Yes, the if in a macro is a problem. I haven't addressed macros, that's a whole different can of worms.