|
Bhaal posted:This isn't code (yet) but our recent new hire recently asked me "what does break do?". Then, after explaining, he followed-up with asking a clarification of how continue works differently than break. I was 4 timezones away on vacation when the interview sprung up, so instead of inconveniencing me for a technical interview while I was away the CTO handled the whole thing. He's already been checking in code on little starter tasks that were just random cleanup bits I haven't gotten around to, and at least from what I've seen it's all pretty much okay, but I just... I just ... Am I just being too inconsiderate or condescending? I've got my share of gaps, too, and certainly had plenty more when I was starting out. Like, I wasn't familiar with what a closure was until I blundered into it about 3 months into my first job doing web development, thinking I found a js bug or something. But this was not having any solid prior experience in js, not, you know, coming out of a ~6 year academic career that focused on languages with closures. And, I mean, BREAK? It just seems so fundamental.
|
# ? Oct 21, 2011 19:57 |
|
|
# ? Jun 1, 2024 14:10 |
|
Some professors really rail on break and continue being evil in the same sense that some people are obsessed with Single Point of Return. It is possible, although unlikely, that he was merely trained around the use of those facilities. WTF is a "Masters in CS with emphasis on java/C#/php", though? If a CS program is defined by the languages you use during coursework you may have a problem. Where I come from, Computer Science is a branch of applied mathematics.
|
# ? Oct 21, 2011 20:01 |
|
Internet Janitor posted:Some professors really rail on break and continue being evil in the same sense that some people are obsessed with Single Point of Return. It is possible, although unlikely, that he was merely trained around the use of those facilities. I guess I can see how he might not be that familiar with break/continue due to the philosophy of his profs, but I mean it would seem pretty bad for someone teaching around a language like java to avoid explaining some pretty important keywords even if they want to attach a rider saying to avoid using them. That, and if were me I'd at least give google a quick spin before asking around. I guess it's a mixture of personality differences. I'll only ask someone after I give a 10-30 minute attempt (depending on what it is) to figure it out on my own, he seems to just spout out questions as soon as he runs into the problem and/or if it just piques his curiosity. He's asked a lot of very strange, random questions, most not dealing with programming stuff but bizarre nonetheless (asked if I own a farm, we live in a huge city). One of my friends is starting to think he's actually this master of deadpan trolling or something.
|
# ? Oct 21, 2011 20:29 |
|
pseudorandom name posted:Don't forget that string literals used to be writable. Was this pre-C89? I was under the impression that a compiler has always been free in a char *foo = "bar"; situation to put foo in the rodata segment or whatever, whereas char foo[] = "bar"; has always required that foo be on the stack.
|
# ? Oct 21, 2011 20:35 |
|
BP posted:It would allow you to modify the memory storing the object, as long as you can reverse the changes, rather than making a copy of the memory and mutating the copy. This could lead to some memory savings in some cases. Makes sense and all but from a practical stand-point I just don't get why someone would want to write their code that way. Whenever I use const it's for things which I know will never change (e.g. if I wanted to store pi in a variable for some reason). Oh well. People will always be doin' dumb things. vv
|
# ? Oct 21, 2011 21:13 |
|
Otto Skorzeny posted:Was this pre-C89? I was under the impression that a compiler has always been free in a char *foo = "bar"; situation to put foo in the rodata segment or whatever, whereas char foo[] = "bar"; has always required that foo be on the stack. Modification of string literals is still undefined in the current spec. Older compilers used to stick them in the .data section.
|
# ? Oct 21, 2011 21:34 |
|
BP posted:It would allow you to modify the memory storing the object, as long as you can reverse the changes, rather than making a copy of the memory and mutating the copy. This could lead to some memory savings in some cases. But clearly, if those circumstances aren't present at the exact moment that I'm writing some code, they're not worth taking into consideration.
|
# ? Oct 21, 2011 21:41 |
|
Bhaal posted:So as an update he just double checked again today to cofirm that break would infact break him out of a loop (I think he was unclear on whether it would continue execution or act like return or something), with a followup question about what if you're in TWO loops? Masters in CS with emphasis on java/c#/php. How. HOW? I don't understand why he didn't just run the code and see what it did instead of playing 20 questions with you.
|
# ? Oct 21, 2011 23:07 |
|
Can we say with confidence that the real horror is the usage of notoriously tricky and subtle languages like C and C++ in 2011?
|
# ? Oct 21, 2011 23:14 |
|
SlightlyMadman posted:But clearly, if those circumstances aren't present at the exact moment that I'm writing some code, they're not worth taking into consideration. There is, in fact, plenty of code which manipulates objects which are guaranteed to be (1) dynamically allocated and (2) accessed only by a single thread. Often both of those constraints are close to inherent to the domain. Again, I think this sort of code is very dangerous, particularly with string data, and it's poor style in the sense that it's a potentially-unexpected constraint on the calling code. But if you accept that the caller and callee are already tightly coupled, and your domain has made the above constraints tenable, then I would argue it's not a completely unreasonable interpretation of the const contract.
|
# ? Oct 21, 2011 23:19 |
|
BonzoESC posted:Can we say with confidence that the real horror is the usage of notoriously tricky and subtle languages like C and C++ in 2011? Still waiting on that blockbuster game written in Haskell.
|
# ? Oct 21, 2011 23:38 |
|
BonzoESC posted:Can we say with confidence that the real horror is the usage of notoriously tricky and subtle languages like C and C++ in 2011? There are analogies in any language with mutable state. I can certainly have (say) a List in Java which I pass down the stack with the informal understanding that the callee won't add anything to it. Under such an understanding, it's a point of interpretation whether that means "don't modify it at all" or "you can modify it as long as you undo those changes before you return", and there can be good reasons to do either. The biggest difference is that C and C++ actually let you formalize (and therefore type-check) the mutability contract, which makes this point of interpretation kindof a question about the language.
|
# ? Oct 21, 2011 23:41 |
|
const does not in any way imply thread-safety. Even with the "const means don't mutate the data in any way" interpretation, a const method could still do something like call strtok. In some cases the restore-to-original view of const is even required for thread safety, as it's rather hard to lock a mutex owned by an object without any mutation.
|
# ? Oct 21, 2011 23:42 |
|
Zombywuf posted:Still waiting on that blockbuster game written in Haskell. or h.264 encoder (where this code was taken from)
|
# ? Oct 22, 2011 00:08 |
|
Plorkyeran posted:const does not in any way imply thread-safety. Even with the "const means don't mutate the data in any way" interpretation, a const method could still do something like call strtok. In some cases the restore-to-original view of const is even required for thread safety, as it's rather hard to lock a mutex owned by an object without any mutation. Well you could use mutable or you could use volatile http://drdobbs.com/184403766.
|
# ? Oct 22, 2011 00:12 |
|
Spotted in some high-priced “expert”‘s code by a guy I talk to on IRC:code:
|
# ? Oct 22, 2011 01:32 |
|
Here's sample of some image processing code we have at work. Absolutely unmaintainable. I think this was basically copied from paper verbatim, converting things like H2 into hh. Luckily almost all these algorithms are static.code:
|
# ? Oct 22, 2011 01:33 |
|
Saw something along these lines today:code:
I'm not even going to bother mentioning it to anyone else on the team, or that we could catch poo poo like that really easily by unit testing. They've broken my spirit. I will be the sole person on the team who cares about writing testable, tested code. Then I will find a new job in 6 months. New Yorp New Yorp fucked around with this message at 02:14 on Oct 22, 2011 |
# ? Oct 22, 2011 02:09 |
|
The programmer just wanted to make sure that string literal fell out of scope after the assignment, that's all.
|
# ? Oct 22, 2011 02:15 |
|
Ithaqua posted:Saw something along these lines today: Seems like you caught that poo poo pretty easily by code reviewing. Why add the extra step of unit testing?
|
# ? Oct 22, 2011 02:16 |
|
Captain Cappy posted:Seems like you caught that poo poo pretty easily by code reviewing. Why add the extra step of unit testing? Because if the original developer had written unit tests, he would've known immediately that there was a problem and it wouldn't have required a second set of eyes to catch. My viewpoint is that code reviews should be for sanity-checking business rules and architectural decisions, not finding bugs.
|
# ? Oct 22, 2011 02:22 |
|
Ithaqua posted:My viewpoint is that code reviews should be for sanity-checking business rules and architectural decisions, not finding bugs. Why? It seemed to work pretty quickly to find that bug you just posted. Also are you sure he would have known the error immediately, considering he's the one who made it in the first place?
|
# ? Oct 22, 2011 02:29 |
|
Captain Cappy posted:Why? It seemed to work pretty quickly to find that bug you just posted. Also are you sure he would have known the error immediately, considering he's the one who made it in the first place? what are you saying? if he wrote proper unit tests he would know that his code wasn't functioning the way he meant it to be.
|
# ? Oct 22, 2011 02:32 |
|
Captain Cappy posted:Why? It seemed to work pretty quickly to find that bug you just posted. Also are you sure he would have known the error immediately, considering he's the one who made it in the first place? I'm not saying you won't find bugs in a code review, but I never sit down to do a code review with the intent of finding bugs. I've found bad architectures, missing requirements, completely mis-implemented requirements, solutions that can't possibly scale, correct solutions implemented in mind-bogglingly stupid ways, solutions containing unnecessarily copy-and-pasted code, but very rarely any "i forgot an else statement " bugs. A good unit test suite would catch something like that because there would be an explicit test case for both scenarios (e.g. "When_Somebool_Is_True_Then_S_Is_Foo" and "When_Somebool_Is_False_Then_S_Is_Bar" or "When_Somebool_Is_False_Then_S_Is_Not_Foo"). Of course, that's assuming the test is important enough to be written in the first place. In this case, it doesn't look like it was important.
|
# ? Oct 22, 2011 02:39 |
|
TasteMyHouse posted:what are you saying? if he wrote proper unit tests he would know that his code wasn't functioning the way he meant it to be. How do you know he didn't mean to do it that way
|
# ? Oct 22, 2011 02:43 |
|
rjmccall posted:The strchr signature is a wart that is basically required by a lack of expressivity in the C type system. code:
|
# ? Oct 22, 2011 02:51 |
|
I meant that the return type really ought to be const-qualified if and only if the first argument is. Given that that's not expressible in the type system, I tend to side with the committee that it's better to lose const-safety than to make a *very* common task in C string processing this awkward. ETA: but you're right that that's a legal workaround
|
# ? Oct 22, 2011 03:09 |
|
newlib is Satan's own library. I present as evidence that while sin() is in math.h, it is not in libm.a.
|
# ? Oct 22, 2011 03:30 |
|
MononcQc posted:Spotted in some high-priced “expert”‘s code by a guy I talk to on IRC: Whether this is bad or not would seem to depend on whether there are any other statements before the next case.
|
# ? Oct 22, 2011 04:25 |
|
Hammerite posted:Whether this is bad or not would seem to depend on whether there are any other statements before the next case. That and whether the language supports statements between fallthroughs. It's been awhile, but I seem to recall code:
code:
|
# ? Oct 22, 2011 05:14 |
|
OriginalPseudonym posted:That and whether the language supports statements between fallthroughs. It's been awhile, but I seem to recall It is C#, and it hasn't been fixed. However, you can accomplish the fall through by using a goto with the name of one of the other labels in the switch.
|
# ? Oct 22, 2011 05:34 |
|
Considering that the behavior was an intentional design decision, there's nothing to fix.
|
# ? Oct 22, 2011 06:06 |
|
Zhentar posted:Considering that the behavior was an intentional design decision, there's nothing to fix. Sure there is, that thing is just a wart rather than a bug
|
# ? Oct 22, 2011 06:38 |
|
Zhentar posted:Considering that the behavior was an intentional design decision, there's nothing to fix. I admit to curiousity as to why that would be something to intentionally put in. Otto Skorzeny posted:Sure there is, that thing is just a wart rather than a bug I believe the technical term is "feature"
|
# ? Oct 22, 2011 07:40 |
|
There no possibility that you'll forget a break and accidentally have a fallthrough in C#. Yes, that's literally the reason.
|
# ? Oct 22, 2011 07:42 |
|
That's not the only scenario it's there to prevent, but yes, it's only done that way to avoid accidentally screwing up (and, with goto case, to make your intent explicit). The reasoning being that intentional fallthrough is the uncommon case. As a side bonus, it prevents people who are cool with fallthrough but think goto case is an abomination because it starts with goto from trying to be too clever for their own good.
|
# ? Oct 22, 2011 08:03 |
|
Zhentar posted:That's not the only scenario it's there to prevent, but yes, it's only done that way to avoid accidentally screwing up (and, with goto case, to make your intent explicit). The reasoning being that intentional fallthrough is the uncommon case. To be frank, C# was taught as my college's preferred programming language, and none of the professors taught, mentioned, or used goto. (Neither did the textbooks they used.) It wasn't until this thread, years after the fact, that I found out C# even has goto. So yeah, I assume they all fell into the "goto is a four-letter word" category.
|
# ? Oct 22, 2011 08:17 |
|
OriginalPseudonym posted:To be frank, C# was taught as my college's preferred programming language, and none of the professors taught, mentioned, or used goto. (Neither did the textbooks they used.) It wasn't until this thread, years after the fact, that I found out C# even has goto. It's more like they don't want all the stupid scrubs writing goto statements instead of learning to use while loops and for loops.
|
# ? Oct 22, 2011 08:43 |
|
shrughes posted:It's more like they don't want all the stupid scrubs writing goto statements instead of learning to use while loops and for loops. You would think about the time they're teaching the class about delegates, they might mention at some point "Oh yeah by the way..."
|
# ? Oct 22, 2011 09:08 |
|
|
# ? Jun 1, 2024 14:10 |
|
Zhentar posted:That's not the only scenario it's there to prevent, but yes, it's only done that way to avoid accidentally screwing up (and, with goto case, to make your intent explicit). The reasoning being that intentional fallthrough is the uncommon case. I never understood why the language (or other C-derived languages, for that matter) don't make fall-through legal in switch statements, but require that the last statement in each case be "break", "return", or "continue" - the latter specifying a fallthrough. If anything else is encountered it would be a syntax error. The only downside would be that: code:
|
# ? Oct 22, 2011 09:22 |