|
sizeof
|
# ? Jul 16, 2015 20:01 |
|
|
# ? May 29, 2024 15:36 |
|
Subjunctive posted:sizeof what?
|
# ? Jul 16, 2015 20:07 |
|
Soricidus posted:what? sizeof will look up both types and variables (as an expression), effectively putting them in the same namespace for its evaluation. (I don't recall which takes precedence.)
|
# ? Jul 16, 2015 20:23 |
|
I mean, I can't recall a C program where the author ever did 'struct Foo *myFoo = malloc(sizeof(struct Foo));' anyways. I'm mostly talking about Java/C# devs. And I never bothered to learn C++ but you have to use sizeof(struct Foo) for C so I'm not sure what you mean (unless you typedef it ofc). E: Oh I see, you're saying that since I can do sizeof(int) and int x = 0; sizeof(x). dougdrums fucked around with this message at 20:30 on Jul 16, 2015 |
# ? Jul 16, 2015 20:26 |
|
dougdrums posted:I mean, I can't recall a C program where the author ever did 'struct Foo *myFoo = malloc(sizeof(struct Foo));' anyways. I'm mostly talking about Java/C#. And I never bothered to learn C++ but you have to use sizeof(struct Foo) for C so I'm not sure what you mean (unless you typedef it ofc). I've definitely seen it in C, in macroized allocators for example. And in C++ you don't need the explicit struct, not that typedef of structs is unusual.
|
# ? Jul 16, 2015 20:28 |
|
Subjunctive posted:sizeof will look up both types and variables (as an expression), effectively putting them in the same namespace for its evaluation. (I don't recall which takes precedence.) oh, sure. I thought you were talking about structs, which still have their own namespace when using sizeof in C.
|
# ? Jul 16, 2015 20:45 |
|
Subjunctive posted:sizeof will look up both types and variables (as an expression), effectively putting them in the same namespace for its evaluation. (I don't recall which takes precedence.) There are no special disambiguation rules for sizeof in C, because you can't write sizeof(A) if A is only declared as a struct. C++ mostly doesn't have any ambiguity, because references to types aren't valid expressions by themselves, but functional-style casts (i.e. constructor calls) get resolved in favor of being types if they're truly ambiguous.
|
# ? Jul 16, 2015 22:15 |
|
You can write sizeof(A) for a typedef A. But that's just the usual C typedef ambiguity, usually resolved by doing a lookup during lexing to find the lexically-scoped nearest declaration of A, to decide if it's a type name or a variable name. So there's not an explicit preference between type or variable for sizeof, it's that if you have a name that could resolve to both, one must be shadowing the other. e: and just to address the original discussion, structs are different namespace than variables in C, but not typedefs! (Just another tiny little piece of why C and friends are pretty crummily designed.) crazypenguin fucked around with this message at 22:57 on Jul 16, 2015 |
# ? Jul 16, 2015 22:46 |
|
crazypenguin posted:You can write sizeof(A) for a typedef A. Yes, and a name that is declared as a typedef is not declared solely as a struct/union/enum (if it is at all). The C++ rules are really too complex to talk about as if they were merely an extension of the C namespace concept. Different kinds of lookup consider different but overlapping sets of kinds of declarations (tags, types, templates, values, functions, namespaces...), and there are special rules for hiding certain declarations when other kinds of declarations are found in the same scope (but not if they would be found in an enclosing scope). And that's just the declaration namespacing rules, not the actual order-of-lookup rules, or the rules for how to interpret the declarations you find.
|
# ? Jul 17, 2015 10:03 |
|
Perl code:
|
# ? Jul 20, 2015 10:45 |
|
This was part of a larger function. It's an algorithm to determine how many items are in a block of items. In this case the number of items can only ever be powers of 10 (1, 10, 100, 1000, etc).C# code:
|
# ? Jul 22, 2015 13:10 |
|
PHP's mt_rand(1, PHP_INT_MAX) only generates odd numbers
|
# ? Jul 24, 2015 19:01 |
|
lol because there definitely aren't standard ways to produce out-of-range values from a prng such as by concatenating multiple outputs or whatever. you've gotta just produce one output and scale it, that's the only option
|
# ? Jul 24, 2015 19:03 |
|
|
# ? Jul 24, 2015 19:42 |
|
There are so so many things wrong with that I don't even know where to begin.
|
# ? Jul 24, 2015 19:46 |
|
No fair posting student code
|
# ? Jul 24, 2015 19:49 |
|
That wasn't actually found in a project, right? It's a tutorial example from how to write infinite loops, right? Well I guess it's not technically infinite. It just takes the long way to get where it's going.
|
# ? Jul 24, 2015 19:50 |
|
xzzy posted:That wasn't actually found in a project, right? Assuming it's C or C++, it's undefined behavior, which means the compiler can do whatever it wants.
|
# ? Jul 24, 2015 19:55 |
|
xzzy posted:Well I guess it's not technically infinite. It just takes the long way to get where it's going. If that's C or C++ (and if it isn't what's printf doing there) it's probably infinite - i is signed, and signed integer overflow is undefined, so the loop conditional probably gets omitted come codegen time.
|
# ? Jul 24, 2015 19:55 |
Blotto Skorzany posted:If that's C or C++ (and if it isn't what's printf doing there) Java has a printf method
|
|
# ? Jul 24, 2015 20:08 |
|
ChickenWing posted:Java has a printf method so does bash and PHP. Although PHP would have $ before the variables.
|
# ? Jul 24, 2015 20:10 |
|
Soricidus posted:lol code:
|
# ? Jul 24, 2015 20:12 |
|
code:
|
# ? Jul 24, 2015 20:17 |
|
I think just about everything has a printf, even languages that don't use it as the primary method of output. Or failing that they have sprintf.
|
# ? Jul 24, 2015 20:17 |
|
xzzy posted:I think just about everything has a printf, even languages that don't use it as the primary method of output. c#, python. does javascript even have a formatting function in its standard library?
|
# ? Jul 24, 2015 21:00 |
|
Soricidus posted:c#, python. does javascript even have a formatting function in its standard library?
|
# ? Jul 24, 2015 21:08 |
|
A homemade horror. For background, you can read from this post in the .net thread: http://forums.somethingawful.com/showthread.php?threadid=3644791&pagenumber=85#post448109154 The basic thing is, some genius developer on some far-flung corner of the company decided that our internal graphics search tool should stop being based a a spreadsheet of filenames and tags that we've maintained forever and exported to csv for indexing, and we should instead use the handy "Tags" field that Windows Explorer gives you for .jpg files instead. It's pretty easy to read this information. It's insanely hard to write it. I think this developer knows this, but didn't GAF and asked a bunch of non-technical people do do the bitch work of tagging up 50000+ .jpg files. Since I'm the "fix it with programming guy" one of the called me and asked me if there was a way to automate this. Since it's a one-off and we'll never need to do it again, I just ground out the first thing that worked. Since Windows' API for updating this metadata doesn't exist, 12 hours and 3 third-party libraries later I have this garbage (it worked, I am getting cookies). Comments inline on the grodier stuff C# code:
|
# ? Jul 24, 2015 21:19 |
|
PHP_INT_MAX wasn't added until 5.0.5. I don't see what the horror is here, because it returns boolean false in the above situation and there is a massive warning since the start that it should not be used for anything close to crypto.
|
# ? Jul 24, 2015 21:49 |
|
Speaking of PHP - this: http://stackoverflow.com/questions/31617137/why-chr0x00-is-considered-as-true-in-php made me laugh today
|
# ? Jul 24, 2015 22:20 |
canis minor posted:Speaking of PHP - this: http://stackoverflow.com/questions/31617137/why-chr0x00-is-considered-as-true-in-php made me laugh today I get that PHP is a fractal of horrors but pretty much every "WOW PHP IS BAD" post involves people just refusing to accept the way PHP handles loose comparisons. idiot on stackoverflow posted:if ($test['bit1column']) no no no no no no The mt_rand thing is an actual interesting horror
|
|
# ? Jul 24, 2015 23:50 |
|
In a java web application (spring based), one developer thought that when an administrator updates a user information (including password), that administrator should enter the original password of the user. That is a WTF in and of itself, but it gets better. So, how do we check if the password entered is the same as the one in the database? You wouldn't believe it (comments are mine):Java code:
Java code:
|
# ? Jul 25, 2015 00:28 |
|
Biowarfare posted:PHP_INT_MAX wasn't added until 5.0.5. I don't see what the horror is here, because it returns boolean false in the above situation and there is a massive warning since the start that it should not be used for anything close to crypto. Shouldn't PHP 4.4.0 through 4.4.9 throw the same error, then?
|
# ? Jul 25, 2015 01:34 |
|
HardDisk posted:Shouldn't PHP 4.4.0 through 4.4.9 throw the same error, then? PHP4 went security-only not long after 5.0 was released, and received updates for three years afterward, almost up until 5.3.0 was released. 4.4.0 was released almost exactly a year after 5.0.0, and just a bit before 5.1.0. It seems that they backported the constant for some reason.
|
# ? Jul 25, 2015 06:39 |
|
Volguus posted:So, how do we check if the password entered is the same as the one in the database? You wouldn't believe it (comments are mine): I believe it. The dude doesn't know about this.passwordEncoder and instead writes fairly clear and understandable code to check the password instead. You should have just laughed and said "oh, you don't have to write this, Spring injects a service for us that does this" and CR failed it. Then he would have said "oh cool, that makes things easier" and fixed it. And then you wouldn't have tried to make fun of him on an internet forum for him not knowing literally everything about the massive 500,000 LOC Java Enterprise framework he's using.
|
# ? Jul 25, 2015 06:53 |
|
Suspicious Dish posted:I believe it. The dude doesn't know about this.passwordEncoder and instead writes fairly clear and understandable code to check the password instead. You should have just laughed and said "oh, you don't have to write this, Spring injects a service for us that does this" and CR failed it. Then he would have said "oh cool, that makes things easier" and fixed it. And then you wouldn't have tried to make fun of him on an internet forum for him not knowing literally everything about the massive 500,000 LOC Java Enterprise framework he's using. [edit] Show me on the doll where the code review touched you.
|
# ? Jul 25, 2015 08:47 |
|
this.passwordEncoder is a core concept of Spring?
|
# ? Jul 25, 2015 09:08 |
|
Inversion of control is such a core concept in Spring, that even if passwordEncoder was not yet injected into the class, it still would not be reasonable to write that code.
|
# ? Jul 25, 2015 09:51 |
|
McGlockenshire posted:PHP4 went security-only not long after 5.0 was released, and received updates for three years afterward, almost up until 5.3.0 was released. 4.4.0 was released almost exactly a year after 5.0.0, and just a bit before 5.1.0. It seems that they backported the constant for some reason. Oh, didn't know that.
|
# ? Jul 25, 2015 18:03 |
|
Suspicious Dish posted:I believe it. The dude doesn't know about this.passwordEncoder and instead writes fairly clear and understandable code to check the password instead. You should have just laughed and said "oh, you don't have to write this, Spring injects a service for us that does this" and CR failed it. Then he would have said "oh cool, that makes things easier" and fixed it. And then you wouldn't have tried to make fun of him on an internet forum for him not knowing literally everything about the massive 500,000 LOC Java Enterprise framework he's using. code:
|
# ? Jul 25, 2015 18:15 |
|
|
# ? May 29, 2024 15:36 |
|
can't we just be impressed that this codebase is actually using a non-terrible method for storing passwords in the first place?
|
# ? Jul 25, 2015 18:21 |