|
movax posted:So what's the "right" way to do this? Well, in this case it looks like it could have been this: code:
You could make this slightly more general while preserving the simple interface by having a traits class determine the getter or setter to use for a particular control class, but it is probably not worth it compared to just making two or three overloads of the template above. Another alternative would be to use a macro, which is actually a very nice way to avoid a ton of redundancy, and which has the distinct advantage of being able to metaprogram over different members without introducing a visual wasteland of pointer-to-member constants: code:
|
# ? Dec 7, 2012 21:26 |
|
|
# ? May 28, 2024 17:25 |
|
Crazy Mike posted:What is the argument against having scope and datatype in your variable names?
|
# ? Dec 7, 2012 21:47 |
|
Crazy Mike posted:If I have a variable in a method, how can I tell if it belongs to the method or the class if it is not prefixed with a 'l' for local or an 'i' for instance? (Apparently right-click, go to definition isn't the answer.)
|
# ? Dec 7, 2012 22:00 |
|
Isilkor posted:At some point you're going to decide that you need a floating point value (or maybe an arbitrary precision integer) instead of an integer and you'll end up with float mi_whatever. Right click, rename.
|
# ? Dec 7, 2012 22:23 |
|
hobbesmaster posted:Right click, rename. Bonfire Lit fucked around with this message at 01:31 on Dec 8, 2012 |
# ? Dec 8, 2012 01:28 |
|
Talking about coding standards in the context of a hypothetical worrying situation around "git blame" is a terrible idea. What if I change a bit of indentation? Oh no! All of this code block was written by me! If your coworkers can figure out "git blame" but not realize that the commit message (you did make a separate commit when you changed it to a float, right?) says "changed to a floating point type because we need some extra precision", and then do "git blame THAT_COMMIT^ -- ./that/file.c", I'd start hunting for a new job.
|
# ? Dec 8, 2012 01:49 |
|
A quick quiz. Try to answer before looking at the spoilers. What would you assume this variable would be used for? php:<? $paid;?> What would you assume would be inside this span? code:
And finally: php:<? <span class="updflwup"><?php echo $updflwup; ?></span> ?>
|
# ? Dec 8, 2012 02:29 |
|
Suspicious Dish posted:Talking about coding standards in the context of a hypothetical worrying situation around "git blame" is a terrible idea. What if I change a bit of indentation? Oh no! All of this code block was written by me!
|
# ? Dec 8, 2012 02:35 |
|
Does that work for blame? I use it all the time for git show.
|
# ? Dec 8, 2012 03:54 |
|
OK, medical IT will rob you of your sanity. But at least you get paid mad cash right? Right?
|
# ? Dec 8, 2012 04:40 |
|
Suspicious Dish posted:Does that work for blame? I use it all the time for git show.
|
# ? Dec 8, 2012 06:05 |
|
rjmccall posted:Well, in this case it looks like it could have been this: Not at all obvious from the code snippet I pasted but there were a mix of line edits, combo boxes, check boxes, buttons, spinners, and a few font controls. The final value was either a bool, a string, a QFont object, a double, or an int (possibly more). The getters, setters, and typecast all have different signatures depending on the type of control and value. Any attempt at writing a function/macro would've taken more space than just leaving it as is (which I know, because I tried).
|
# ? Dec 8, 2012 10:30 |
|
The big thing I see is that binding which properties to whatever value seems to be something you'd decide on a per-control-type basis, rather than on a per-control one. The easy solution would be I guess to make a bunch of template specializations. Sure the template code would probably look a bit horrible, but the call site would literally just be code:
|
# ? Dec 8, 2012 12:28 |
|
bobthecheese posted:updflwup I have no idea what this could possibly mean but I love it.
|
# ? Dec 8, 2012 13:29 |
|
The horror I've been thinking about lately at work is our git workflow. Tons of repositories on github. 80 or so developers all treating github as the single remote. CI pulls from github. Github has gone down for us 3 times in the past 2 months. What's the solution? Migrate to a gitolite instance on s3, and have CI pull from that. We keep using a distributed source control system as a standard 1 deep hierarchical system. Even just a suggestion I had for setting up a 2nd remote in the office for one internet and/or github goes out was met with blank stares and blinks. I don't expect to have a 15 layer deep Linux kernel hierarchy going on but still.
|
# ? Dec 8, 2012 15:48 |
|
hobbesmaster posted:Right click, rename. Can you name an IDE that can do intelligent whole-project symbol renaming but can't tell you the scope of a variable just as easily?
|
# ? Dec 8, 2012 19:55 |
|
Jabor posted:The easy solution would be I guess to make a bunch of template specializations. Sure the template code would probably look a bit horrible, but the call site would literally just be What's the advantage to doing that, outside of just having a slightly ugly call site? The code just becomes a lot more complex. (Also, if you require template specializations, I don't think you need a template. Just function overrides should work)
|
# ? Dec 8, 2012 20:55 |
|
Jewel posted:I actually really enjoy the atmosphere and posts of yospos (especially that thread, holy poo poo is it great) but I'm afraid I'd be chewed up or something so I never post. Maybe one day YOSPOS isn't that bad. Besides, if you aren't following the YOSPOS catte thread then you're inhuman. nielsm posted:Ugh, I need to vent about this thing I'm working on atm. It's not really an unusual WTF, it's just that I haven't worked on many old projects yet. I looked through our project with grep just to find instances of error_reporting() and the only places it cropped up were in our project's files ( ) and the test cases. I'm not very familiar with it though, maybe it's in another component we're missing? The error_reporting(0) thing I'm very familiar with, though. Copied and pasted into the top of every PHP file my boss writes, complete with his one (useless) function and a few lines mysql_connect (including the inclusion of a file that has nothing but db credentials in it, so yes, every file includes its own copy if mysql_connect). Of course, we also have software written in VB6 and .NET, and ... surprise, my boss just puts On Error Resume Next in everything. No logging of any kind, nothing. Really fun when it suddenly stops working! ...and then I looked up if On Error Resume Next even worked in VB.NET, and quote:http://forums.devx.com/showthread.php?156898-On-Error-Resume-Next-for-VB.Net&s=7f41a3e670869604e846a6be02b8f1ac&p=466516#post466516
|
# ? Dec 8, 2012 22:24 |
|
Some teams in company I work are doing what you could call UI driven development. 1) Create some view, e.g. xxxx summary 2) Create a database table XXXXSUMMARY and fill it with relevant data 3) Write some trivial SQL to populate the view: SELECT * FROM XXXXSUMMARY WHERE WHATEVER. No joins YAY Too bad selecting something more specifc is a huge pain and sometimes outright impossible. And guess what happens when UI changes... We have some guys trying to produce reports and they are some of the angriest developers I have met .
|
# ? Dec 8, 2012 22:47 |
|
Ephphatha posted:Not at all obvious from the code snippet I pasted but there were a mix of line edits, combo boxes, check boxes, buttons, spinners, and a few font controls. The final value was either a bool, a string, a QFont object, a double, or an int (possibly more). The getters, setters, and typecast all have different signatures depending on the type of control and value. Any attempt at writing a function/macro would've taken more space than just leaving it as is (which I know, because I tried). Sure; it's totally reasonable that abstracting this might not be worth the complexity cost. That's potentially true of any abstraction you can name — even splitting a hundred-line function up into several small functions isn't necessarily worth the complexity. If you've only got a dozen or so lines like this, it'd be pretty dumb to add a bunch of metaprogramming just to make those lines look nicer. But if this is something you're doing all over the place, then making a half-dozen one-line functions — one overload per control type — makes it much easier to change things if you suddenly want to save/restore control state differently (e.g. if you needed to not just use accessibleName() as the settings key).
|
# ? Dec 9, 2012 00:23 |
|
Admiral H. Curtiss posted:I have no idea what this could possibly mean but I love it.
|
# ? Dec 9, 2012 03:35 |
|
Admiral H. Curtiss posted:I have no idea what this could possibly mean but I love it. Update follow up (appointment). c++ terror, short and sweet: code:
Not a member function! E: it gets called a billion times because whoever wrote it "doesn't want to pass the data through all the calls" (a comment says this). It has a 330 line switch statement based on program state because the author couldn't be bothered to actually write a proper virtual method for the classes it tries to update. The more I look at the thing the worse it gets. bucketmouse fucked around with this message at 19:17 on Dec 9, 2012 |
# ? Dec 9, 2012 18:08 |
|
Ehh. I can kinda see why you would want that, if you have some kind of global storage that's expensive on a per-write basis. (You know you've seen too much bad code if you try to excuse nullary global functions called update_the_data)
|
# ? Dec 9, 2012 18:21 |
|
Reminds me of a system I had to maintain about ten years ago. It was a Java servlet client/server app that used ObjectInput/OutputStreams to send messages as plain Java objects. Ok, fine, but their message handler was a huge if/else chain that did "if (msg instanceof This) ... else if (msg instanceof That)..." I just don't understand how somebody writes code like that without thinking "Hmm, behavior based on object type, maybe that's what overriding methods is good for." This same app had all of its servlet response pages handled by a single method that just did hundreds of printlns to generate the HTML.
|
# ? Dec 9, 2012 19:44 |
|
Flobbster posted:Reminds me of a system I had to maintain about ten years ago. It was a Java servlet client/server app that used ObjectInput/OutputStreams to send messages as plain Java objects. Ok, fine, but their message handler was a huge if/else chain that did "if (msg instanceof This) ... else if (msg instanceof That)..." I just don't understand how somebody writes code like that without thinking "Hmm, behavior based on object type, maybe that's what overriding methods is good for." It's just code written by folks that don't understand object oriented programming, that's all.
|
# ? Dec 9, 2012 20:30 |
|
Whatever, real heads all know OO is "verbose and contrived".
|
# ? Dec 9, 2012 23:07 |
|
Doc Hawkins posted:Whatever, real heads all know OO is "verbose and contrived". I agree with the argument that OOP is definitely a bit heavy handed. I mean starting students off in Java and immediately getting into exception handling and why writing getters and setters is important is rough, compared to, say, Python, where you can get into the fundamentals of thinking about programming like opening a file and doing some control flow. I don't think I've seen it taken to the point of "disregard data structures" and use arrays indiscriminately and stick to magic tuple-structs for RGB vales.
|
# ? Dec 10, 2012 00:26 |
|
Doc Hawkins posted:Whatever, real heads all know OO is "verbose and contrived". Uh, it certainly can be verbose and contrived which is his argument.
|
# ? Dec 10, 2012 00:29 |
|
OO can certainly be verbose, but in what way is it contrived?
|
# ? Dec 10, 2012 00:33 |
|
Optimus Prime Ribs posted:OO can certainly be verbose, but in what way is it contrived? Hello world in java comes to mind.
|
# ? Dec 10, 2012 00:34 |
|
What part of that is OO's blame?
|
# ? Dec 10, 2012 00:53 |
|
Suspicious Dish posted:What part of that is OO's blame? It isn't; however it is why it's a horrible place to start beginners. This is the author's point.
|
# ? Dec 10, 2012 01:02 |
|
Suspicious Dish posted:What part of that is OO's blame? From the article: quote:It's not that OOP is bad or even flawed. It's that object-oriented programming isn't the fundamental particle of computing that some people want it to be. When blindly applied to problems below an arbitrary complexity threshold, OOP can be verbose and contrived, yet there's often an aesthetic insistence on objects for everything all the way down. That's too bad, because it makes it harder to identify the cases where an object-oriented style truly results in an overall simplicity and ease of understanding.
|
# ? Dec 10, 2012 01:02 |
|
But what part of OO requires that there be no main function? It's there in C++, and it's there in Smalltalk. It seems that it's not OO that's at fault, but the Java language design.
|
# ? Dec 10, 2012 01:07 |
|
Suspicious Dish posted:What part of that is OO's blame? hello world in perl/python: code:
hello world in c: code:
hello world in java: code:
While it can be true that these hurdles pay off (and I don't think anyone here would argue the contrary on every one of the hurdles presented), and it can even be argued that they pay off for any non-trivial program (likely a more controversial contention for at least some of them), it is silly to pretend they don't have any cost at all for even the most trivial programs, or that they are not obstacles in a didactic environment. Blotto Skorzany fucked around with this message at 01:12 on Dec 10, 2012 |
# ? Dec 10, 2012 01:09 |
|
I feel the same about people that learn programming through frameworks like Rails or Django, honestly. It's not that there's anything wrong and in fact they're top-shelf for their purpose (as with OO being a good choice), it's just that you end up teaching/being taught OO via programming rather than programming more generally and then OO where it fits. I can't blame Java for it when people are being taught Java specifically though, since that's just how the language is.
|
# ? Dec 10, 2012 01:14 |
|
The point about there being a general complexity level at which OOP is pointless is generally true though - it's just very obvious in Java because it attempts to force you into it from the start. With the wrong teaching, a new student might think it's unacceptable to start doing Hello World with anything less than creating a Greeting class with a method that accepts a Noun class etc. etc. etc. That's obviously absurd, but I think we can all think of cases where we or someone else has done something similar, particularly if you/they learned to program in the last decade or so.
|
# ? Dec 10, 2012 01:37 |
|
There are Java implementations that require you to import anything in java.lang? e: import java.lang.System.out; isn't even a valid import
|
# ? Dec 10, 2012 01:54 |
|
Aleksei Vasiliev posted:There are Java implementations that require you to import anything in java.lang? IIRC, no; I think it's part of the specification that java.lang.* must be in the namespace by default.
|
# ? Dec 10, 2012 02:02 |
|
|
# ? May 28, 2024 17:25 |
|
Amarkov posted:IIRC, no; I think it's part of the specification that java.lang.* must be in the namespace by default. This is the case. Page 165.
|
# ? Dec 10, 2012 02:07 |