Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

movax posted:

So what's the "right" way to do this?

Well, in this case it looks like it could have been this:

code:
  template <class T> setCheckedFromSettings(const T &control, const Settings &settings) {
    control->setChecked(settings.value(control->accessibleName(), control->isChecked()).toBool());
  }
  ...
  setCheckedFromSettings(this->ui.aCheckBox, settings);
  setCheckedFromSettings(this->ui.bCheckBox, settings);
  setCheckedFromSettings(this->ui.abLinkButton, settings);
Except that instead Ephphatha decided to wank about making the template as general as possible instead of just solving the damned problem. Unfortunately, the C++ metaprogramming community actively promotes this kind of nonsense.

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:
#define setFromSettings(control, prop) \
    control->set##prop(settings.value(control->accessibleName(), control->is##prop()).toBool());
Not an ideal macro — it re-evaluates control three times and implicitly uses settings — but pretty reasonable for local use.

Adbot
ADBOT LOVES YOU

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

Crazy Mike posted:

What is the argument against having scope and datatype in your variable names?
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.

Sedro
Dec 31, 2008

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.)
You can configure Resharper, and maybe Visual Studio, to highlight locals/fields/constants/etc differently. Using special notations for private fields and local variables is bad style; using them in public-facing API is inexcusable.

hobbesmaster
Jan 28, 2008

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.

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

hobbesmaster posted:

Right click, rename.
Which makes the diff in your VCS look like poo poo. Also this is the coding horrors thread so you would have to do that because your co-workers won't and that means git blame will say all errors are your fault.

Bonfire Lit fucked around with this message at 01:31 on Dec 8, 2012

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
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.

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
A quick quiz. Try to answer before looking at the spoilers.

What would you assume this variable would be used for?

php:
<?
$paid;?>
Sometimes Part Attribute ID, sometimes Patient Address ID

What would you assume would be inside this span?

code:
<span id="iplist">
Did you guess ID of Patient list? Because I sure as gently caress didn't.

And finally:

php:
<?
<span class="updflwup"><?php echo $updflwup?></span>
?>
I honestly have no loving clue because there's no comments anywhere in the project which explain what it means.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

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!
-w
:eng101:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Does that work for blame? I use it all the time for git show.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
OK, medical IT will rob you of your sanity. But at least you get paid mad cash right? Right?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Suspicious Dish posted:

Does that work for blame? I use it all the time for git show.
Yes.

ephphatha
Dec 18, 2009




rjmccall posted:

Well, in this case it looks like it could have been this:

code:
  template <class T> setCheckedFromSettings(const T &control, const Settings &settings) {
    control->setChecked(settings.value(control->accessibleName(), control->isChecked()).toBool());
  }
  ...
  setCheckedFromSettings(this->ui.aCheckBox, settings);
  setCheckedFromSettings(this->ui.bCheckBox, settings);
  setCheckedFromSettings(this->ui.abLinkButton, settings);
Except that instead Ephphatha decided to wank about making the template as general as possible instead of just solving the damned problem. Unfortunately, the C++ metaprogramming community actively promotes this kind of nonsense.

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).

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
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:
  setFromSettings(this->ui.aCheckbox);
  setFromSettings(this->ui.bCheckbox);
  setFromSettings(this->ui.cLinkButton);
and so on.

Admiral H. Curtiss
May 11, 2010

I think there are a bunch of people who can create trailing images. I know some who could do this as if they were just going out for a stroll.

I have no idea what this could possibly mean but I love it.

Hughlander
May 11, 2005

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.

Bunny Cuddlin
Dec 12, 2004

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?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

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)

Zamujasa
Oct 27, 2010



Bread Liar

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 :allears:

:justpost:

YOSPOS isn't that bad. Besides, if you aren't following the YOSPOS catte thread then you're inhuman. :colbert:



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.

Zend Framework. Well it's PHP, the documentation for it is terrible, but it kinda works. However the things built onto it in this application makes me want to scream. Inverted responsibilities all over the places. Superclasses that are certainly "super", they contain half the functionality of all the classes derived from them. There is a single class derived from Zend_Db_Table which all of our custom database table classes then derive from in turn, and that intermediate class has all kinds of checks for "what actual class was this method called on", doing various kinds of magic depending on that.
I also just found a magic method pushed away in a corner that contains what seems to be a re-duplication of most of the collecting data for the frontend, except it's in another intermediate class, does everything slightly differently, and uses this pattern:

PHP code:
function getStuff()
{
  $errorReporting = error_reporting();
  error_reporting(0);

  //... entire body of method

  error_reporting($errorReporting);
}
:psypop: :smithicide:

:confused: 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 ( :argh: ) 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 :stonk:

quote:

http://forums.devx.com/showthread.php?156898-On-Error-Resume-Next-for-VB.Net&s=7f41a3e670869604e846a6be02b8f1ac&p=466516#post466516

If you have a load of lines to do this on you might try something like
code:
Dim codeLine as integer = 0
Dim dRes as dialogResult
Do
dRes = dialogResult.None
try
select codeLine
case 0:
DoLine1()
case 1:
DoLine2()
case 3:
DoLine3()
case 4:
Exit Sub
End Select
codeLine += 1
catch ex as exception
dRes = messagebox.show("An error has occured." & ex.message & " Do you wish to retry","Error",MessageBoxButtons.RetryCancel)
Loop while dREs = dialogResult.Retry
If dREs=dialogResult.Cancel then exit sub
It should be simple to change that to Skip/Cancel or Retry/Skip/Cancel if necessary

IMlemon
Dec 29, 2008
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 :downs:

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 :(.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

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).

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Admiral H. Curtiss posted:

I have no idea what this could possibly mean but I love it.
update flow (of) up(?)

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal

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:
void update_the_data();

Not a member function! :v:

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

Amarkov
Jun 21, 2010
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)

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
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. :gonk:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

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."

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. :gonk:

It's just code written by folks that don't understand object oriented programming, that's all.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Whatever, real heads all know OO is "verbose and contrived".

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

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.

hobbesmaster
Jan 28, 2008

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.

Optimus Prime Ribs
Jul 25, 2007

OO can certainly be verbose, but in what way is it contrived?

hobbesmaster
Jan 28, 2008

Optimus Prime Ribs posted:

OO can certainly be verbose, but in what way is it contrived?

Hello world in java comes to mind.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
What part of that is OO's blame?

hobbesmaster
Jan 28, 2008

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.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

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.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
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.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Suspicious Dish posted:

What part of that is OO's blame?

hello world in perl/python:

code:
print "Hello, world!"
You told the computer what to do and it did it, boom, hooray, now on to the next topic!

hello world in c:

code:
#include <stdio.h> // the absence of this won't cause an error on most implementations assuming you haven't played any LD_PRELOAD games

int main()
{
    printf("Hello, world!");
    return 0;
}
Note there is some accidental complexity here from structured programming - I need* to explicitly include a library, i need to know what a function is and what a return value is, but they don't actually help me solve the task at hand. In an intro course, these would be handwaved rather than explained.




hello world in java:
code:
import java.lang.System.out; // the absence of this won't cause an error on most implementations

class HelloWorld
{
    public static void main(String[] args)
    {
        System.out.print("Hello, world!");
    }
}
Now there is more accidental complexity: there are three classes, one of which I must create (and whose name must match its filename, sans extension!), none of which actually do anything for me. I have to use a jerry-rigged member function ("static method") to simulate a normal function (you could also view this as using a class hierarchy as an ersatz namespacing mechanism). In an intro class, none of this poo poo will be explained either, unless one of the students leaves out something they didn't know they needed and it prevents their program from working, at which point it will be explained as a fundamental atom of computer science (rather than what it actually is, a style of programming that is arguably well-suited to certain types of problems).



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

The Gripper
Sep 14, 2004
i am winner
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.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

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.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
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

Amarkov
Jun 21, 2010

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.

Adbot
ADBOT LOVES YOU

Titan Coeus
Jul 30, 2007

check out my horn

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply