|
IMlemon posted:Boolean flags are set or unset in a longass method and are impossible to keep track off. That closeSession method? Did you truncate this or does it really do nothing, thanks to the comments?
|
# ? Jun 13, 2012 17:03 |
|
|
# ? Jun 10, 2024 10:56 |
|
Golbez posted:Did you truncate this or does it really do nothing, thanks to the comments? This is all original code, except I removed the beginning of the first code snippet and changed exception names.
|
# ? Jun 13, 2012 17:08 |
|
Nothin' better than commented-out code. Especially when they use stream comments, so grep gives misleading results!
|
# ? Jun 13, 2012 17:11 |
|
Hammerite posted:When you talk to the database server you are using a particular character set to do so. For example, you might be using UTF-8, which can express a superset of the characters that can be expressed in iso-8859-1 or in iso-8859-15. If I send an INSERT or UPDATE statement that stores a particular string value in a column whose character set is iso-8859-1 (say), the string value needs to contain only valid iso-8859-1 characters. If it contains other characters, it is not a valid string value for that column. That is a "specific requirement of the data", in your words. This is what I mean when I say that the character set of a column is a constraint on that column. It also implies an interpretation of the data stored in the column, as you say. If you try to insert, say, UTF-8 3-byte code points into into an ISO-8859-1(5) column in MySQL, does it error or warn you?
|
# ? Jun 13, 2012 17:11 |
|
Mustach posted:Nothin' better than commented-out code. Especially when they use stream comments, so grep gives misleading results! In my world, having commented out code outside of a dev branch is an automatic code review failure.
|
# ? Jun 13, 2012 17:35 |
|
Ithaqua posted:In my world, having commented out code outside of a dev branch is an automatic code review failure. Something tells me the world that code came from doesn't include code reviews.
|
# ? Jun 13, 2012 17:48 |
|
Ithaqua posted:In my world, having commented out code outside of a dev branch is an automatic code review failure. Out of curiosity, when you say 'code review', is this a human process or something you put through a program or both? I'm the primary of only two devs here so my code review process is rather sparse for his code (making sure nothing kills the site or has SQL injections) and non-existent for mine.
|
# ? Jun 13, 2012 17:52 |
|
Golbez posted:Out of curiosity, when you say 'code review', is this a human process or something you put through a program or both? I'm the primary of only two devs here so my code review process is rather sparse for his code (making sure nothing kills the site or has SQL injections) and non-existent for mine. He meant human. That's generally what the term implies. A program can't discern between instances where it's okay to commment out code (examples of using an API given in comments) and you'd have to make a machine learning algo to discern between code and text anyway... *effort*. It's definitely not a computer.
|
# ? Jun 13, 2012 17:56 |
|
Golbez posted:Out of curiosity, when you say 'code review', is this a human process or something you put through a program or both? I'm the primary of only two devs here so my code review process is rather sparse for his code (making sure nothing kills the site or has SQL injections) and non-existent for mine. It's a human intervention thing. When I worked on a larger team, every 2-week iteration, there would be a person assigned to be the code reviewer. This was to prevent groups of "code review buddies" from forming who would let each others' poo poo slide. Immediately before merging code from their dev branch to the integration branch, they'd schedule a code review session, and the two people would sit down together and go over the code. The goals were: - Ensure that the code meets standards (naming conventions, etc) - Ensure that the code is well-designed - Ensure that the code has appropriate unit test coverage and that all tests pass - Ensure that the code meets all of the acceptance criteria Of course, some people were far stricter than others.
|
# ? Jun 13, 2012 18:03 |
|
Sounds fun. Sounds like something for a larger place than us... I guess I could get him to review my code.
|
# ? Jun 13, 2012 18:11 |
|
Golbez posted:Sounds fun. Sounds like something for a larger place than us... I guess I could get him to review my code. Code reviews are also a great way to pass your wisdom and experience to newer people on the team.
|
# ? Jun 13, 2012 18:31 |
|
Golbez posted:Sounds fun. Sounds like something for a larger place than us... I guess I could get him to review my code. Assuming you are the senior guy, it would absolutely make sense for your co-worker to review your code, if nothing else to read better code than his own. ^ epswing fucked around with this message at 18:36 on Jun 13, 2012 |
# ? Jun 13, 2012 18:31 |
|
Golbez posted:Sounds fun. Sounds like something for a larger place than us... I guess I could get him to review my code. I think code reviews should be done on any team with more than one developer, personally.
|
# ? Jun 13, 2012 18:43 |
|
Ithaqua posted:I think code reviews should be done on any team with more than one developer, personally. A thread for single developers to review each others code. Good idea or bad? Since I'm entirely self taught and haven't worked with any other developers before (besides minor-ish contributions to open source projects where I didn't really work with anyone else, I just fixed stuff and submitted it), I think I'd benefit a lot from code reviews.
|
# ? Jun 13, 2012 18:46 |
|
tef posted:Frankly, beyond percussive maintenance, I am unsure how to transmit this information to you. I suggest a convincing argument. Here is the starting point: a primary key is, by definition, a column or sequence of columns that can be used to uniquely identify rows in the table. I observe that a string can be used to uniquely identify rows in the table. Thus, a string can be used as a primary key. It seems to me that it is at that point up to you to say, "Well yes, but..." and give a reason why strings should not be used in that way even though they can be. It is not up to me to prove that no such reason exists (how would I even go about doing that?). It is up to you to provide one. Munkeymon posted:If you try to insert, say, UTF-8 3-byte code points into into an ISO-8859-1(5) column in MySQL, does it error or warn you? It is surprisingly difficult to find out this information from the MySQL manual, and I gave up trying to find out what the exact behaviour is from the command line because it was too much of a pain in the rear end to work out what was MySQL's behaviour and what was a limitation of the Windows command-line client. I may try to find out later using better tools. The behaviour that I would expect is for it to depend on the sql mode. I would expect it to refuse to perform the insert in strict mode and otherwise to do something like truncate the data or replace the offending character with a '?'.
|
# ? Jun 13, 2012 18:52 |
|
Thermopyle posted:A thread for single developers to review each others code. Good idea or bad? Bad. The spirit would be good, but it's just way too subjective to have it all out in the open like that. A coordinated thread for one-to-one or one-to-many code reviews outside of the forums might not be a bad idea if there was a way to coordinate those reviews.
|
# ? Jun 13, 2012 18:53 |
|
Thermopyle posted:A thread for single developers to review each others code. Good idea or bad? I'd be happy to code-review others' Java code, especially Android, but I'm afraid I can't share most of my own code, seeing as how it's written for my job and thus not shareable. And while I'd want some code review for some Scala stuff I'm doing on my own time, I'm a little hesitant to create a throwaway GitHub account. My main one can connect me to my place of employment, which for now I prefer to keep private. No Safe Word posted:Bad. The spirit would be good, but it's just way too subjective to have it all out in the open like that. A coordinated thread for one-to-one or one-to-many code reviews outside of the forums might not be a bad idea if there was a way to coordinate those reviews. Doctor w-rw-rw- fucked around with this message at 19:02 on Jun 13, 2012 |
# ? Jun 13, 2012 18:56 |
|
Thermopyle posted:A thread for single developers to review each others code. Good idea or bad? I like the idea, although the thread would probably be so fast-moving that it would be difficult to have reasonable discussion. I like No Safe Word's idea -- we could start a code review buddy thread and pair people up.
|
# ? Jun 13, 2012 19:04 |
|
No Safe Word posted:Bad. The spirit would be good, but it's just way too subjective to have it all out in the open like that. A coordinated thread for one-to-one or one-to-many code reviews outside of the forums might not be a bad idea if there was a way to coordinate those reviews. I don't see why subjective=bad idea in this case. If two reviewers have differing opinions on something they can discuss it and maybe one of them ends up learning more about how to do reviews. Breaking things down into individual private pairs means that only one person gets to benefit from the review, while keeping the discussions in-thread would let other people learn what is considered good/bad practice from their example. If some exchange really gets down to a level where it couldn't be considered general interest enough for the thread the people involved could move to PM/emails on their own.
|
# ? Jun 13, 2012 19:14 |
|
PDP-1 posted:I don't see why subjective=bad idea in this case. If two reviewers have differing opinions on something they can discuss it and maybe one of them ends up learning more about how to do reviews. Disagreements about code can be a good way to learn more, since supporting claims must be made to back them up. I agree - the process should be open and discussion would help. If it becomes popular, I can see one thread being too fast-moving to keep up with, but that problem can be dealt with then.
|
# ? Jun 13, 2012 19:28 |
|
PDP-1 posted:I don't see why subjective=bad idea in this case. If two reviewers have differing opinions on something they can discuss it and maybe one of them ends up learning more about how to do reviews. It's not so much the subjectivity that makes it bad it's just that you'd get lots of strong differing opinions and if the goal was for folks to learn, it could be difficult for them to choose and could end up being more destructive than constructive when reviewers start sniping at one another. But, if people disagreeing was that big of a problem these forums wouldn't exist so I guess me just stating that it'd be outright "bad" without qualifying it a bit was overstatement.
|
# ? Jun 13, 2012 19:35 |
|
Mustach posted:Nothin' better than commented-out code. Especially when they use stream comments, so grep gives misleading results! I like deleting commented out code in files that I edit. Usually because whole rows are commented out, my edits don't show up in blame either
|
# ? Jun 13, 2012 19:46 |
|
Munkeymon posted:If you try to insert, say, UTF-8 3-byte code points into into an ISO-8859-1(5) column in MySQL, does it error or warn you? Not to continue the horrible MySQL ranting much longer, but... ISO-8859-$FOO code points are single 8-bit bytes. All 256 combinations of bits are valid characters. UTF-8 is the encoding of a Unicode characters into 8-bit bytes. It happens that any legal UTF-8 encoding is also legal ISO-8859-$FOO. This is why things like Unicode em dashes end up looking like – when displayed in ISO-8859-$FOO. Each of those characters is a legal ISO-8859-$FOO character, even though the sequence of bytes means something different in UTF-8. Given that it would look legal, nothing at all should ever get in the way of you treating a UTF-8 encoded string as if it was ISO-8859-$FOO. This is why it's so important to get it right the first time.
|
# ? Jun 13, 2012 20:08 |
|
It's also why no normal human being would ever call the character set on a column a "constraint". A constraint in database terms implies a requirement that is actually enforced. If you take a stream of multibyte utf8 data and jam it into an ISO-8859-1 column, you end up with one of two things: if the client tried to convert from utf8 to the target character set, you will get dropped characters (the infamous "question marks in my data"). If the client jams the bytes in there as if they were the target encoding, then you get actual garbage from misrepresented bytes (as McGlockenshire describes). It's really hard to imagine a scenario where you'd want anything other than UTF8. You get 8 bits per character for the ASCII range (code points < 128) and proper support for everything else. There is literally no argument for using 7 bit ASCII, and only really bad arguments for using any legacy 8 bit encoding (involving handwaving about 3rd party applications that can't be changed). I can't fathom how you'd construe any of this as being a "constraint" by any sensible definition of that word.
|
# ? Jun 13, 2012 20:29 |
|
npe posted:It's also why no normal human being would ever call the character set on a column a "constraint". A constraint in database terms implies a requirement that is actually enforced. If you take a stream of multibyte utf8 data and jam it into an ISO-8859-1 column, you end up with one of two things: if the client tried to convert from utf8 to the target character set, you will get dropped characters (the infamous "question marks in my data"). If the client jams the bytes in there as if they were the target encoding, then you get actual garbage from misrepresented bytes (as McGlockenshire describes). There is a third possibility that you are not considering: the server tries to convert to the target character set and notices that some of the characters can't be expressed in the target character set, and therefore refuses to do it and returns an error. That's a "requirement that is actually enforced", i.e. a constraint. This is what should happen!
|
# ? Jun 13, 2012 21:47 |
|
Hammerite posted:It is surprisingly difficult to find out this information from the MySQL manual, and I gave up trying to find out what the exact behaviour is from the command line because it was too much of a pain in the rear end to work out what was MySQL's behaviour and what was a limitation of the Windows command-line client. I may try to find out later using better tools. OK, I just tried this out on my web host's PHPMyAdmin. I created this table: SQL code:
SQL code:
SQL code:
code:
EDIT: The forum doesn't let me put the character I actually used in the "code" environment. I used the string 'Ǡ' (LATIN CAPITAL LETTER A WITH DOT ABOVE AND MACRON), not the string 'see below'. Hammerite fucked around with this message at 22:03 on Jun 13, 2012 |
# ? Jun 13, 2012 21:58 |
|
Hammerite posted:OK, I just tried this out on my web host's PHPMyAdmin. I created this table: If errors happen on a database level, I want them to be severe and I want to be notified NOW so I can fix them, and I want to handle errors in my code in the most transparent way possible, i.e. "Did my database gently caress up? Better check my queries." rather than "Did my database gently caress up? Better check my data". It's also easier to debug the program code because the fuckups have a line number, because code is generated so much more rarely than database queries. If I were interviewing a candidate and s/he argued that it's generally not a bad idea to handle encoding conversions at the database level, I would fail said candidate. The worst error you should have with character sets and encoding is a client showing a couple of hosed up characters.
|
# ? Jun 13, 2012 22:23 |
|
Doctor w-rw-rw- posted:Dunno about you, but having both localized apps and dealt with encoding issues, I'd much rather have localization and encoding problems in program code than in database queries, which are often dynamically generated to some degree. Also, altering a table can be much more difficult than pushing new code. I think this is consistent with what I am saying. Of course you should check at the application level that data to be inserted is correct and satisfies constraints. But if the application fails in that regard then what should the database do? It should return an error for the application to deal with, of course.
|
# ? Jun 13, 2012 22:29 |
|
"how to use pointers in Objective c"Objective-C code:
Toady fucked around with this message at 22:47 on Jun 13, 2012 |
# ? Jun 13, 2012 22:45 |
|
Hammerite posted:I think this is consistent with what I am saying. What I mean is, I have trouble seeing why your database would be anything other than UTF8. In virtually all cases, everything you write should speak UTF8, and keep encoding issues as far from the internals of the code as they can reasonably get. Database access counts as one of those internal things. Ideally, exceptions relating to encoding errors between the database and its clients would simply not exist, because they'd both be UTF8. I can't imagine a common case where character sets are a reasonable thing to constrain on the database level.
|
# ? Jun 13, 2012 22:46 |
|
Toady posted:"how to use pointers in Objective c" Without context, that looks like a standard Objective-C variable swap plus a handle, so it can swap something externally. Unconventional, but not *necessarily* horrific. It doesn't look like it should be an instance method, though. EDIT: Nope. I'm wrong. Also post was edited to add context. Been a while since I did any Obj-C. I suppose the variable swap itself does warrant some additional sanity checks, and the ivar vs. property thing is a good point. Still, even stuff like swizzling Apple's own Cocoa classes is done in some iOS apps I've heard of, at least as of two years ago. If you know what you're doing... Doctor w-rw-rw- fucked around with this message at 22:54 on Jun 13, 2012 |
# ? Jun 13, 2012 22:49 |
|
Hammerite posted:But as I said, I don't see the discussion of the merits, or otherwise, of MySQL as being the real focus of discussion here. (Actually of the things being discussed, I find the thing about whether a column character set is a constraint the most interesting, but perhaps I am weird.) I was moved to defend (my perception of) MySQL's acceptable (although it has one or two warts) Unicode support by Zombywuf's barb that UTF-8 "actually works in Postgres". You literally asked for a comparison between Postgres and MySQL and then jumped on everything people said when they compared the two. quote:Well I do think that's the issue you and Zombywuf have with what I'm saying, isn't it? Yes, the only requirement for a primary key is that it is unique for each entry. However, using business data for primary keys is a horrible idea because then you're hardcoded into that particular setup. quote:It is possible to have an integer that is meaningful, and it is possible to have a string that is meaningless. So I think when I said "you don't think PKs should have business meaning", I was not handwaving but getting to the heart of the matter. Yes both of those are possible, however you still haven't provided a good use-case for a meaningful PK, which is apparently the heart of the matter. *See below* quote:The use-case I was referring to is the following (bold not in original): How about this? code:
quote:I guess I was incorrect when I said that you would have to be able to trace it back to another table's primary key. I still don't think your suggestion of a composite key containing a string is a sensible exception to the rule "no meaningful primary keys", if we accept that rule. Essentially because a primary key that consists of a single string column is surely just a special case of "composite primary key that includes a string". You note that the example (last name, first name, dob) is a bad one (on this we both agree), but I am not convinced that there is a class of examples where a reasonable argument could be made for a composite primary key containing a string but the argument would collapse if the scenario were changed to make the string the sole component of the primary key. It's still a horrible idea and not a very valid exception at all (nor was I actually suggesting it as one), I was just trying to see what your reasoning for including a string PK would be. Also: quote:It seems to me that it is at that point up to you to say, "Well yes, but..." and give a reason why strings should not be used in that way even though they can be. It is not up to me to prove that no such reason exists (how would I even go about doing that?). It is up to you to provide one. It actually is up to you to provide a reason for using a string as a primary key that is actually a better alternative to factoring out the business information into a separate column and using a "meaningless" integer PK, since it's honestly against best practice at least 99% of the time.
|
# ? Jun 13, 2012 22:51 |
|
Look Around You posted:You literally asked for a comparison between Postgres and MySQL and then jumped on everything people said when they compared the two. I asked for a comparison that was (among other things) unbiased. I didn't ask for a scattering of snide comments about how this or that totally sucks in MySQL, hurr hurr. Notice how McGlockenshire was critical of MySQL but I didn't jump on anything he said. But in the end you're right, I shouldn't have bothered responding to the barbs since it wasn't really relevant to the topic I was trying to discuss. I guess I'm not going to persuade you on the privilege name thing. It makes perfect sense to me to identify privileges by the names they're referred to in code.
|
# ? Jun 13, 2012 23:30 |
|
Hammerite posted:I guess I'm not going to persuade you on the privilege name thing. It makes perfect sense to me to identify privileges by the names they're referred to in code. Okay I guess, but why does that mean you have to store them in the table in that fashion? Isn't that just bloating your indexes for no reason?
|
# ? Jun 14, 2012 00:06 |
|
Jabor posted:Okay I guess, but why does that mean you have to store them in the table in that fashion? Isn't that just bloating your indexes for no reason? Don't forget making it impossible to auto-incrementing the key. Sure do love writing the code to do that manually if I want to maintain a synthetic key.
|
# ? Jun 14, 2012 00:12 |
|
Hammerite posted:I asked for a comparison that was (among other things) unbiased. "unbiased" just means "has the same bias as mine".
|
# ? Jun 14, 2012 01:11 |
|
Hammerite posted:I asked for a comparison that was (among other things) unbiased. I didn't ask for a scattering of snide comments about how this or that totally sucks in MySQL, hurr hurr. Notice how McGlockenshire was critical of MySQL but I didn't jump on anything he said. if you want to have sql explained to you, you could perhaps start somewhere other than the coding horrors thread.
|
# ? Jun 14, 2012 03:17 |
|
Hammerite posted:I asked for a comparison that was (among other things) unbiased. quote:I guess I'm not going to persuade you on the privilege name thing. It makes perfect sense to me to identify privileges by the names they're referred to in code. Zombywuf fucked around with this message at 14:28 on Jun 14, 2012 |
# ? Jun 14, 2012 14:10 |
|
hieronymus posted:Don't forget making it impossible to auto-incrementing the key. Sure do love writing the code to do that manually if I want to maintain a synthetic key. Huh. You just made me realize I never have to generate my own PKs; I use autoincrements or compound keys exclusively.
|
# ? Jun 14, 2012 14:23 |
|
|
# ? Jun 10, 2024 10:56 |
|
Golbez posted:Huh. You just made me realize I never have to generate my own PKs; I use autoincrements or compound keys exclusively. you aren't a horror. Content: This was code I was asked to critique during an interview. See if you can figure out what it does. php:<? $grandma = 0; for($y="000000", $x="005959"; $y<="230000", $x<="235959";) { $tima[$grandma] = date("ga", strtotime("$y")); $paser = date("ga", strtotime("$y")); $bima[$paser] = 0; $y = $y + 10000;$x = $x + 10000; if(strlen($y) <= "5"){$y = "0$y";}if(strlen($x) <= "5"){$y = "0$x";} $grandma++; } ?> Apparently they'd fired their last "senior developer" a few months before I interviewed, but not before he wrote two functioning products just like that. They didn't even change the variable names - they literally copy & pasted the code straight from their production machine. The new senior developer then proceeded to tell me that the database tables were pretty similar, and to illustrate, showed me the most important table in the database. It contained 55 columns, all of them VARCHAR(45), and the first three that I saw were named "AAAA", "AAAAA", and "AAAAB". And this is what they wanted me to maintain.
|
# ? Jun 14, 2012 14:59 |