3 ms·
If (false)
- deleted 13y ago[deleted]
- gohwell 13y agoThat's one way to comment out code
- filipedeschamps 13y agoThat's also one way to not use version control.
- dchest 13y agoVersioning doesn't have anything to do with this piece of code.
- _sabe_ 13y agoWhy would you commit this code? If it's a test, put it in a branch and once the problem is solved, merge it in?
- dchest 13y agoHave you read the comment? This disabled part of code is used for communication: "If someone is able to circumvent this problem, please email me". When someone reads the code to discover why it works in a certain way, they'll instantly learn that the developer thought about this, and tried to do something, but discovered that an external bug prevents him from enabling this code. It's also common to include TODO, FIXME, or BUG comments into code. Sure, you can put them into issue tracker, but having them directly in code gives more context.
- dreen 13y agoI think the point is that the developer should stash it or use a branch or something, instead of having code in master that never runs. The technique itself is useful for debugging, but not much else.
- chris_wot 13y agoYeah, but it does tend to highlight to anyone reading the code that this code should work, but to look at the comment before the if statement. I'd very rarely use this sort of thing, but in this case I'd say it's OK.
- mschuster91 13y agoI only delete code I know I'm not going to use later. Refactoring, especially renaming files, WILL make it next to impossible to find "that one bit of code you know that does the trick", because even with a rgrep or git blame it will not turn up. As soon as the commit history is >50 commits, it's also not feasible any more to scroll through hundreds of pages of diffs. Side note: find a way to easily store "intentionally dead" code in a file, in a way that it does not show up in the code, but can be searched at least on the commandline - easy way to get rich. Devs all over the world will love you. (I'd imagine replacing a block of code e.g. with /* REMEMBERME /, git detecting this block (and inserting a / REMEMBER-ID 12345 */ instead), and git supporting a command like "git show-dead file.c" which shows all the dead code, too.)
- spuz 13y agoMaybe you are unaware of git pickaxe. See the -S option of git log: https://www.kernel.org/pub/software/scm/git/docs/git-log.html https://www.kernel.org/pub/software/scm/git/docs/git-log.htm...
- mschuster91 13y agoIndeed I was, yet still this forces me to remember a part of the string of the code I deleted... which may not be the case if the commit was a month or two (or more!) ago. I mostly remember just "ah, this was in class XYZ"... open it, quickly scan the file for the comment blocks and voila, there's my code.
- stinos 13y agoI only delete code I know I'm not going to use later. Refactoring, especially renaming files, WILL make it next to impossible to find ... It won't, if you use proper commit messages. Once you start doing that, you'll soon discover it will make everything much more discoverable. Apart from that, death to dead code! Having worked on a project where about 10 to 20% of the code was effectively dead (either simply unused, commented out, #ifdef'ed away of if( 0 )'d away) I can assure you I never ever want that again, mainly since the dead parts still turn up in every search/grep/find reference.
- yread 13y agoI also hate it when people comment out code without commenting on why is it removed, why doesn't it work, what to do to make it work, who has done it, who is going to make it work and so on...
- lotsofcows 13y agoAnd then the next person looks at the code and thinks why don't they just do x. Then x doesn't work so they delete it again. Then the next person looks at the code...
- quchen 13y ago[-][[This reminds me of Brainfuck, where a similar hack can be used to write comments with arbitrary contents -- even containing "]" if you ba- lance them right.]
- sz4kerto 13y agoThere is nothing to see here, go away please. :) It's just the simplest way of turning a code fragment on/off. Not pretty, but not the end of the world either. :)
- nailer 13y agoSure (if the code shouldn't just be deleted at all and kept in version control), but I'd rather shove the magic constant and it's explanation into a variable at the top of the file: // PHP has a bug that prevents you from creating a byte array via variants PHP_BUG_123_RESOLVED = false;
- xroche 13y agoIn C, at least, compared to the commented out version or removed (when using versionning) variant, the code is still present and builds (and will break upon API change, guaranteeing it to be up-to-date), is present when re-factoring (not necessarily easy with all version control systems), and has no impact over performances (might not be true with PHP). So this can be seen as a feature, actually.
- dz0ny 13y agoPHP will parse whole file, before actually optimizing anything. Thats the only penalty you get.
- dz0ny 13y agoThis will work when there is glitch in the Matrix.
- Tepix 13y agoSo, getRandomInteger() keeps fetching bytes and adding them as 0..255 values until it reaches the desired value? How silly is that? For a random number between 0 and 2147483648 it would require 8388608 random bytes.. omg!
- Robin_Message 13y agoIt's also going to return random numbers with a binomial distribution, which might be surprising since most generators are uniform. How is this "improved security"?
- Tepix 13y agoYep. Just awful...
- deleted 13y ago[deleted]
- chmod775 13y agoThere's 4,284,794 results for "if(false)" on GitHub: https://github.com/search?q=%22if%28false%29%22&type=Code&ref=searchresults https://github.com/search?q=%22if%28false%29%22&type=Code&re...
- dz0ny 13y agoPHP wins
- babawere 13y agoLooking more like a trend ... PHP biggest culprit - PHP 2,333,198 - JavaScript 491,084 - C 306,891 - C++ 198,900 - Java 169,748 - Python 106,708 - HTML 85,903 - Ruby 57,830 - Smalltalk 28,647 - C# 24,813
- bromagosa 13y agoAll Smalltalk ones are valid code that will be executed though. #ifFalse: is a message that is sent to a boolean and takes a closure as an argument.
- davidw 13y agoI think you just found out that PHP is a very widely used programming language. To make a more meaningful comparison, divide by the total lines of code.
- eksith 13y agoIs most of this even necessary? Couldn't you get away with: function IV( $size, $ssl = false ) { if ( $ssl && function_exists( 'openssl_random_pseudo_bytes' ) ) { return openssl_random_pseudo_bytes( $size, true ); } return mcrypt_create_iv( $size, MCRYPT_DEV_URANDOM ); } From the docs: http://it.php.net/manual/en/function.mcrypt-create-iv.php http://it.php.net/manual/en/function.mcrypt-create-iv.php 5.3.0 MCRYPT_DEV_RANDOM and MCRYPT_DEV_URANDOM became available on Windows platforms.
- artumi-richard 13y agoI like it when the expression in the "if" is clear.
- Grue3 13y agoIn Common Lisp there's a special syntax to make the reader ignore an expression, for example #+feature(code here) is executed only if feature is present. It's common to see code commented out with "#+(and)(code here)" or "#-(or)(code here)". In fact there are proponents for either one of these idioms. I guess in Algol-style languages it's rarer to see code commented out like that?
- mbq 13y agoIt is perfectly sane idea for switching code with macros (though for(;0;) is better) and for making compiler do some tests without polluting the code.
- piratebroadcast 13y agoSomeone care to explain this and its implications like I'm 5?
- nzp 13y agoI haven't done enough C to need it, but it's a relatively common C idiom (not sure about PHP though). It's usually used with a goto jump (label inside if (0)) to clean up after an error. That way during normal execution the label code never executes. (I hope I remember this correctly.)