|
fwiw in gcc: http://gcc.gnu.org/gcc-4.7/changes.htmlquote:A string length optimization pass has been added. It attempts to track string lengths and optimize various standard C string functions like strlen, strchr, strcpy, strcat, stpcpy and their _FORTIFY_SOURCE counterparts into faster alternatives. This pass is enabled by default at -O2 or above, unless optimizing for size, and can be disabled by the -fno-optimize-strlen option. The pass can e.g. optimize vvvv sorry, that wasn't supposed to be a coding horror but to tie into the discussion on the last page whether redundant calls to strlen are sometimes optimized away. Vanadium fucked around with this message at 09:26 on Nov 7, 2012 |
# ? Nov 7, 2012 06:51 |
|
|
# ? May 25, 2024 11:40 |
|
Vanadium posted:fwiw in gcc: http://gcc.gnu.org/gcc-4.7/changes.html What am I missing here exactly? At first I though that p wasn't NULL-terminated, but then I saw that 2 bytes were copied from "/" to p. Edit: ^^^Gotcha. Edit: VVV Yeah I know, I just couldn't find any flaws except for potential lack of NULL-termination. Deffon fucked around with this message at 12:10 on Nov 7, 2012 |
# ? Nov 7, 2012 09:02 |
|
Deffon posted:What am I missing here exactly? At first I though that p wasn't NULL-terminated, but then I saw that 2 bytes were copied from "/" to p. "/" is a string with two bytes, a '/' and a null. Copying those two bytes null-terminates p. It doesn't matter that the first memcpy doesn't null-terminate, because it's immediately followed by one that does.
|
# ? Nov 7, 2012 09:09 |
Dicky B posted:I came across this switch statement indentation style earlier today: It's horrible, but at least it's consistent. Inconsistent formatting is the worst thing ever.
|
|
# ? Nov 7, 2012 12:10 |
|
How do you scale an 8-bit hex value to a percentage in JavaScript? With a lookup table, of course! gently caress ETC. code:
|
# ? Nov 7, 2012 16:51 |
|
That's a little bit amazing. The lookup table is obviously generated, so why go to all the trouble of not just using the formula outright?
|
# ? Nov 7, 2012 17:24 |
|
The Gripper posted:That's a little bit amazing. The lookup table is obviously generated, so why go to all the trouble of not just using the formula outright? Premature optimization?
|
# ? Nov 7, 2012 17:48 |
|
To be fair, this is from a company that primarily did embedded systems at the time, so maybe they were working with chips that would do lookups faster than 16-bit integer math before being asked to write a web interface for said embedded system (and repeating old habits.) Dimming and power control should not be this complicated. I should not have to reverse engineer their web interface just to make it work in a browser newer than IE 6. At least the university is paying me to do it. corgski fucked around with this message at 21:43 on Nov 7, 2012 |
# ? Nov 7, 2012 18:03 |
|
code:
|
# ? Nov 8, 2012 15:51 |
|
There probably was, but it really was temporary.
|
# ? Nov 8, 2012 16:56 |
|
A A 2 3 5 8 K posted:
Looking through some more BossCode™ today. Some obscure feature isn't working. It's getting into our system somehow, with code that flows like this ( ) code:
The rest of the code is even worse. The format we get data in is either plain text ("AAA BB CCCCC D<sep>"), or plain text followed by a binary chunk ("AAA BB FFFFF EE <binary data here><sep>"). BossCode™ solution: Run the whole thing through binhex()! Don't forget to also use hexadecimal when looking for data -- "53484954" is a lot better than binhex("poo poo"), and don't worry about starting halfway into a hexadecimal value. There's a huge mess of code that literally splits the file into chunks by doing strpos($d, "20"), $d2 = substr(...), strpos($d2, "20"), $d3 = substr(...), strpos($d3, "20") .... for what could have been accomplished with a simple explode(" ", $d, 5). I tried to rewrite (and fix all the bugs in) this and got decently far in two days, but apparently that was too long for my boss, who needed it now now now now now. So his lovely, broken version that he cobbled together over three weeks is what's running now. And we get to support it, of course. This is like some sick joke.
|
# ? Nov 8, 2012 18:00 |
|
A A 2 3 5 8 K posted:
It's like that old pigs with numbers on them urban legend, but with hacks. Now you'll never know if you found all the hacks.
|
# ? Nov 8, 2012 18:06 |
Label your hacks 1, 2, and 4, and commit them to svn...
|
|
# ? Nov 8, 2012 18:16 |
|
Imagine three hacks on the edge of a cliff...
|
# ? Nov 8, 2012 21:11 |
|
PHP works the same way.
|
# ? Nov 8, 2012 23:24 |
|
Johnny FiveMySQLescapestrings?
|
# ? Nov 8, 2012 23:53 |
|
Ithaqua posted:If they're using Visual Studio, here's a hint: I'm (sorta kinda) coaching a first year programming course and it just boggles the mind that some students wont hit hit alt+shift+f after they are done writing the code. Some seem even downright offended when I gently suggest they do that before showing anything to me.
|
# ? Nov 14, 2012 08:18 |
|
uncleTomOfFinland posted:I'm (sorta kinda) coaching a first year programming course and it just boggles the mind that some students wont hit hit alt+shift+f after they are done writing the code. Some seem even downright offended when I gently suggest they do that before showing anything to me. That switch statement above looks like someone's had an extra brace in there and instead of removing it they just added matching braces and it's hosed the formatting up as a result. But document-wide indenting like that? That's the work of a crazy person.
|
# ? Nov 14, 2012 10:42 |
|
uncleTomOfFinland posted:I'm (sorta kinda) coaching a first year programming course and it just boggles the mind that some students wont hit hit alt+shift+f after they are done writing the code. Some seem even downright offended when I gently suggest they do that before showing anything to me. This can be annoying when your formatting causes version control integration problems. The solution, of course, is to get the entire team on the same formatting scheme, but this is a holy war level of issue with some people.
|
# ? Nov 14, 2012 15:05 |
SQL syntax. ALTER TABLE foo ALTER COLUMN ... ALTER TABLE foo CHANGE COLUMN ... ALTER TABLE foo MODIFY COLUMN ... These are used for different things. Why. (Haven't checked with other DBMS, but MySQL has ALTER COLUMN for changing the default value and nothing else. CHANGE COLUMN is used for renaming and rearranging columns. MODIFY COLUMN changes the data type and a few other things.)
|
|
# ? Nov 14, 2012 16:44 |
|
baquerd posted:This can be annoying when your formatting causes version control integration problems. The solution, of course, is to get the entire team on the same formatting scheme, but this is a holy war level of issue with some people. You need a better merge tool. Perforces merge tool can ignore all whitspace changes which is pretty nice
|
# ? Nov 14, 2012 17:16 |
|
Not exactly a horror, but really funny, this has been in the Android 4.2 source codecode:
|
# ? Nov 14, 2012 17:21 |
|
Frozen-Solid posted:Not exactly a horror, but really funny, this has been in the Android 4.2 source code Could this be related to that Niantic poo poo?
|
# ? Nov 14, 2012 21:52 |
|
Bunny Cuddlin posted:Could this be related to that Niantic poo poo? Probably this
|
# ? Nov 14, 2012 21:54 |
|
Hard NOP Life posted:You need a better merge tool. Perforces merge tool can ignore all whitspace changes which is pretty nice Yeah, SVN 1.6 doesn't do that.
|
# ? Nov 15, 2012 00:20 |
|
baquerd posted:Yeah, SVN 1.6 doesn't do that. You can download the p4 merge tool from their site. Though you agree that you have a license to use it before you can download it. I use it at work for git since one of our projects does use p4!
|
# ? Nov 15, 2012 04:51 |
|
Hughlander posted:You can download the p4 merge tool from their site. Though you agree that you have a license to use it before you can download it. I use it at work for git since one of our projects does use p4! I know you're talking about a merge tool and not the VCS's merge command itself, but with Git you can use git merge -Xignore-space-change (or ignore-space-at-eol, or ignore-all-space) on recursive merges, which often resolves the merge in this kind of situation without requiring painstaking manual intervention or a special merge tool.
|
# ? Nov 15, 2012 13:37 |
|
Or get everyone to use a whitespace trimmer setting/plugin in their editor.
|
# ? Nov 15, 2012 18:40 |
|
what about when I rewrite a file from Windows-1252 to UTF-8 and commit it and now it's 100% changed
|
# ? Nov 15, 2012 19:17 |
|
congratulations, all of the bugs in that file are now your fault
|
# ? Nov 15, 2012 21:54 |
|
Aleksei Vasiliev posted:what about when I rewrite a file from Windows-1252 to UTF-8 and commit it and now it's 100% changed Are you saying you have non-latin characters in your source code?
|
# ? Nov 15, 2012 22:14 |
|
When I'm implementing algorithms from a scientific paper I often have comments that use unicode symbols to show the notation used in the paper, and I use unicode characters in format strings in prettyprinting routines for essentially the same reason- unicode escapes are awful to read. I think both cases are reasonable justifications for non-latin characters in source files.
|
# ? Nov 15, 2012 22:18 |
|
Hughlander posted:You can download the p4 merge tool from their site. Though you agree that you have a license to use it before you can download it. I use it at work for git since one of our projects does use p4! I don't personally have a problem merging (the built-in IntelliJ merge tool is pretty good 99% of the time), but our integration guy and a dinosaur are going to use the built in SVN merge and it's a royal pain to resolve all the poo poo you can sometimes cause with that and autoformat. I had a knock down drag out argument with the dinosaur the other week where he was convinced that auto formatting will sometimes break code and it's a risk management thing, and that to use anything other than the built in merge tool is just begging to break the whole repo... somehow. That's kind of a coding horror. So is having an integration guy that's not a developer and knows nothing about the code and therefore doesn't have the capacity to make decisions on merge conflicts.
|
# ? Nov 15, 2012 23:22 |
|
Internet Janitor posted:When I'm implementing algorithms from a scientific paper I often have comments that use unicode symbols to show the notation used in the paper, and I use unicode characters in format strings in prettyprinting routines for essentially the same reason- unicode escapes are awful to read. I think both cases are reasonable justifications for non-latin characters in source files. Inline latex and only read the doxygen output.
|
# ? Nov 15, 2012 23:37 |
|
This has probably been linked at some point in the past, but this exists: http://hatepaste.com/
|
# ? Nov 16, 2012 00:19 |
|
yaoi prophet posted:Are you saying you have non-latin characters in your source code? Why not call a ∑ a ∑?
|
# ? Nov 16, 2012 01:12 |
|
Toady posted:This has probably been linked at some point in the past, but this exists: http://hatepaste.com/ http://hatepaste.com/paste/811902ee lol so witty
|
# ? Nov 16, 2012 02:03 |
|
Doc Hawkins posted:Why not call a ∑ a ∑? I might be old-fashioned, but in my opinion the only places non-ASCII characters should appear in source code is inside of comments or string literals. vvv Again, just write lambda or something, I don't see the problem. About the anglocentricism I'll just note that as long as we're using languages with English-language keywords there's no way around that anyway, which you'll note is also not a problem. Programming languages are formal languages defined on their own terms, after all, and a limited alphabet to derive valid and, most importantly, unambiguous sentences from is a helpful feature to have. Strictly speaking, though, I'm not opposed in principle to a language using a well-defined, limited set of symbols outside of the ASCII range, in particular for use as keyword tokens for things like λ, ≠, ≤, ∑, ∧, ∊ and so on. But just permitting any arbitrary character out of the entire Unicode range to be used in identifiers or whatnot seems excessive to me, and just opens the door to all kinds of confusion and silliness like variables with names like i vs. í vs. і vs. ı vs. ι. To which you might say, well, if someone does something like that it's their own fault but then again there's really no need for the added complexity to make that even possible in the first place, and any programming language you might look at will pretty much have to have a well-defined and limited subset of valid, permitted characters to be used in identifiers anyway. PrBacterio fucked around with this message at 02:58 on Nov 16, 2012 |
# ? Nov 16, 2012 02:27 |
|
Honestly, I find code a lot easier to read when I can indicate a lambda with λ instead of \ or whatever. "Ascii-only" also seems pretty anglocentric, not everyone likes to contort their natural language into a bastardized 7-bit representation just to give something a name.
|
# ? Nov 16, 2012 02:37 |
|
|
# ? May 25, 2024 11:40 |
|
PrBacterio posted:Well, just call it sigma then? Oh, you're clearly not the target market for some of the operator craziness Scala can let you get into. Dick on Java Posse was talking a while back about how's he's consulting for a company with a lot of math-focused people. Apparently the idea that they can just type "x ∆ y" or "∑ (0 to 10)( x => x*x)" really gets them hard. Edit: Those are some pretty simple examples that just happen to be more clear if you're used to thinking in deltas and whatnot. Scala can also become a real, real horror with this poo poo. When adding ★ as an operator starts to feel sane, it's time to step back. You're just creating a horror at that point. ultramiraculous fucked around with this message at 02:52 on Nov 16, 2012 |
# ? Nov 16, 2012 02:42 |