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
Space Kablooey
May 6, 2009


:psyduck: Jesus Christ

Space Kablooey fucked around with this message at 17:39 on Aug 27, 2014

Adbot
ADBOT LOVES YOU

revmoo
May 25, 2006

#basta
I'm currently working on a web app that does reporting. Whoever designed this app created these report 'frameworks' to supposedly make creating new reports easier. It doesn't. They had the stupid loving idea to put each report in its own directory with a javascript file named report.js for each report, and all js files for all reports are always loaded, even if you're not in the reporting section of the site. Each one of these files is an enormous 3k line mess and the original developer REUSED THE SAME FUNCTION NAMES IN EVERY SINGLE FILE. I don't even know how the gently caress this works at all.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

NFX posted:

MenuBar->Visible = (m_ActiveWindow != m_MainWindow) ? false : true;


"Don't worry, the compiler will optimize it!"

The benefit of the doubt here is that this is C++ and one of those operators is overloaded, but I know in my heart that this is a lie.

NFX
Jun 2, 2008

Fun Shoe
It actually is C++ (Borland C++ 5.0!). But there's no operator overloading anywhere near this. Can you even override a comparison operator to return a non-bool?

Edit: Yes, yes you can. And it's probably been done millions of times.

NFX fucked around with this message at 18:52 on Aug 27, 2014

One Eye Open
Sep 19, 2006
Am I awake?

NFX posted:

MenuBar->Visible = (m_ActiveWindow != m_MainWindow) ? false : true;


"Don't worry, the compiler will optimize it!"

I generally believe in the unpopular idea of having "value==true" -like statements for clarity, because, yes, the compiler will optimise it and it aids in skimming, but that is just stupid.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

NFX posted:

Can you even override

With C++, you should can do EVERYANYTHING!

raminasi
Jan 25, 2005

a last drink with no ice

Volmarias posted:

The benefit of the doubt here is that this is C++ and one of those operators is overloaded, but I know in my heart that this is a lie.

That would make it worse though!

ijustam
Jun 20, 2005

revmoo posted:

I'm currently working on a web app that does reporting. Whoever designed this app created these report 'frameworks' to supposedly make creating new reports easier. It doesn't. They had the stupid loving idea to put each report in its own directory with a javascript file named report.js for each report, and all js files for all reports are always loaded, even if you're not in the reporting section of the site. Each one of these files is an enormous 3k line mess and the original developer REUSED THE SAME FUNCTION NAMES IN EVERY SINGLE FILE. I don't even know how the gently caress this works at all.

I have written something almost the same as this when I was a green developer and I apologize. I at least convinced management to let us rewrite it to be more server-side and not depend on 54 script files.

Edit: After re-reading your post it sounds like 100% the same project except my base file was different :)

revmoo
May 25, 2006

#basta

ijustam posted:

Edit: After re-reading your post it sounds like 100% the same project except my base file was different :)

Hah. I actually used a different filename in my post than the real filename.

ohgodwhat
Aug 6, 2005

revmoo posted:

Hah. I actually used a different filename in my post than the real filename.

Sounds like you're working on my monstrosity too! In my defense, my system was meant to allow unsophisticated programmers to get poo poo done quickly, and it did that well (although the code produced by said unsophisticated programmers is of course a horror in itself), but then it morphed into doing things it was never meant to do... I have also convinced my boss to let me redo it.

I guess this is a green developer phenomenon? It seemed so awesome when someone was able to write up really useful poo poo in a couple of hours, but now they're hitting roadblocks.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Everyone's first big project is terrible. (the difference is that good programmers realize it).

TheresaJayne
Jul 1, 2011
I concur, I find even now looking at code from my last job I cringe when i see some of the stuff that was done.

although there are nice things as well. but when a complex system is made by a team of 8 contractors you know you are going to have problems...

Note: I was not a contractor I was in the after spaghetti time, but there were whole areas that no body else would even look at.

Such as Video Capturing on a website using a 3rd party video tool and linking it into an oracle database using ajax....

Hughlander
May 11, 2005

If you don't think the poo poo you did 6 months ago is horrible then you're not growing as a developer or lying to yourself. In either case it is you who are the horror.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Hughlander posted:

If you don't think the poo poo you did 6 hours ago is horrible then you're not growing as a developer or lying to yourself. In either case it is you who are the horror.

Fixed

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Hughlander posted:

If you don't think the poo poo you did 6 months ago is horrible then you're not growing as a developer or lying to yourself. In either case it is you who are the horror.

If you don't think you're a worthless piece of poo poo, you're a worthless piece of poo poo.

Polio Vax Scene
Apr 5, 2009




I was going to say, some of the fixes I've had to do have made me nauseous while I was writing them. Just get it out there and pray I never have to look at it again.

Blue Footed Booby
Oct 4, 2006

got those happy feet

Manslaughter posted:

I was going to say, some of the fixes I've had to do have made me nauseous while I was writing them. Just get it out there and pray I never have to look at it again.

Funny, when I write stuff like that I pray I'll have an opportunity to look at it again before anyone else does.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
code:
// Calculate Tax Rate
// Calculation: totalLessTax / (totalLessTax / TaxAmt).
// Proof:
//    Total: 100, Total + Tax: 105
//    (100 / (100 / 5)) = 5
Substitute any number for 100 in that formula and see what you get. :downs:

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Knyteguy posted:

code:
// Calculate Tax Rate
// Calculation: totalLessTax / (totalLessTax / TaxAmt).
// Proof:
//    Total: 100, Total + Tax: 105
//    (100 / (100 / 5)) = 5
Substitute any number for 100 in that formula and see what you get. :downs:

A tax rate of... 5?

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Whoever wrote that doesn't know what "proof" means.

Edit: Even the "proof" shows that it's wrong: you'd expect .05 from those numbers

MGN001
May 12, 2012

MALE SHOEGAZE posted:

A tax rate of... 5?

No matter what numbers you plug into that, it'll spit out TaxAmt.


What is this even for? When would you need to go from the price and price + tax to the tax rate?

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
I've been at the end (or beginning) of a day writing code and have suddenly found basic arithmetic rules really hard to think about. I've certainly been that stupid.

I've just never written down a proof of my stupidity, at least not without deleting it before commit.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

One of the best things about code review is that it often makes such embarrassment short-lived.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
code:
IDictionary<int, Something> types = ....;

//(No need to sort types.Keys because types IDictionary is an instance of type SortedDictionary)
foreach (var key in types.Keys)
{
  var type = types[key];
  ...
}
gently caress you. Doing it the right way would have cost less effort than typing out that horrible excuse for why you're too cool to sort the data.

The clincher is that types is never a SortedDictionary, it's always a (regular) Dictionary.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

MGN001 posted:

No matter what numbers you plug into that, it'll spit out TaxAmt.


What is this even for? When would you need to go from the price and price + tax to the tax rate?

In this system (pass through seller) there is no tax rate data; vendors send total & line tax amounts over, but not rate. Probably can't go into more because of confidentiality.

code:
// Calculate Tax Rate
// Implied decimal to 3 places (taxRate * 1000) Ex: 7.25 * 1000 = 7250, parsed as 7.250% from CC PROCESSOR
totalLessTax = any2real(this.getNodeElement(itemsElem, "TotalAmt")) - taxAmt;

if (taxAmt != 0 && totalLessTax != 0)
{
    taxRate = taxAmt / totalLessTax;
    taxRate = taxRate * 1000;

    // Since we have an implied decimal we need to get rid of anything still in the decimal range
    taxRateStr = num2str(taxRate, 3,2,0,0);
    if (strFind(taxRateStr, ".", 0, strLen(taxRateStr)))
    {
        taxRateStr = strRem(taxRateStr, ".");
    }
}
else
{
    taxRateStr = "0000";
}
Here's what I ended up fixing it to. I think the implied decimals screwed the person up. I really dislike them myself.

But yea the "proof" had me laughing. :cheers:

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Knyteguy posted:

In this system (pass through seller) there is no tax rate data; vendors send total & line tax amounts over, but not rate. Probably can't go into more because of confidentiality.

code:
// Calculate Tax Rate
// Implied decimal to 3 places (taxRate * 1000) Ex: 7.25 * 1000 = 7250, parsed as 7.250% from CC PROCESSOR
totalLessTax = any2real(this.getNodeElement(itemsElem, "TotalAmt")) - taxAmt;

if (taxAmt != 0 && totalLessTax != 0)
{
    taxRate = taxAmt / totalLessTax;
    taxRate = taxRate * 1000;

    // Since we have an implied decimal we need to get rid of anything still in the decimal range
    taxRateStr = num2str(taxRate, 3,2,0,0);
    if (strFind(taxRateStr, ".", 0, strLen(taxRateStr)))
    {
        taxRateStr = strRem(taxRateStr, ".");
    }
}
else
{
    taxRateStr = "0000";
}
Here's what I ended up fixing it to. I think the implied decimals screwed the person up. I really dislike them myself.

But yea the "proof" had me laughing. :cheers:

Doing string parsing seems really weird to me. Are you in C# doing this? I'm assuming "num2str" is setting the string as Culture Invariant, because if the user uses commas instead of decimals, this won't work.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

Drastic Actions posted:

Doing string parsing seems really weird to me. Are you in C# doing this? I'm assuming "num2str" is setting the string as Culture Invariant, because if the user uses commas instead of decimals, this won't work.

Not C# - it's x++. Syntactically it's very similar, but x++ is more akin to a scripting language.

4th parameter of num2str(...) is which separator to use, so in the code posted it should always be auto based on local currency settings. I went ahead and forced it to be a decimal just in case though to guarantee the data.

Edit: 4th param not 3rd

Knyteguy fucked around with this message at 18:00 on Aug 29, 2014

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Why not just round off taxRate after you multiply it by 100*1000?

HappyHippo fucked around with this message at 18:06 on Aug 29, 2014

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

HappyHippo posted:

Why not just round off taxRate after you multiply it by 100*1000?

Well the num2str() does the rounding to the hundreds decimal place of the already multiplied realnum, and we need it in a string anyway as we insert it to an XML node just a little further down. Maybe I'm missing something though?

Edit: oh the comment kind of sucks. I missed that. I'll refactor that out because I think it causes a little confusion in the wording (remove everything past the decimal place or whatever, which is inaccurate).

Knyteguy fucked around with this message at 18:18 on Aug 29, 2014

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Looks like reals are only accurate to 0.1?!

I'd avoid any decimal notion entirely and work in fixed point integers when handling money. Such as your 1000 up there, though if micro transactions are possible, I might start out at 4 decimals.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Knyteguy posted:

Well the num2str() does the rounding to the hundreds decimal place of the already multiplied realnum, and we need it in a string anyway as we insert it to an XML node just a little further down. Maybe I'm missing something though?

Edit: oh the comment kind of sucks. I missed that. I'll refactor that out because I think it causes a little confusion in the wording (remove everything past the decimal place or whatever, which is inaccurate).

Maybe I'm reading it wrong but it looks like you convert to a string and then strip out the decimal? So why not just times by 100 and convert to string with no decimal places?

shrughes
Oct 11, 2008

(call/cc call/cc)

Learn to comprehend, that's not what it says.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Snapchat A Titty posted:

Looks like reals are only accurate to 0.1?!

I'd avoid any decimal notion entirely and work in fixed point integers when handling money. Such as your 1000 up there, though if micro transactions are possible, I might start out at 4 decimals.

The line "The BCD encoding makes it possible to make exact representations of values that are multiples of 0.1." is misleading, I think they're trying to say that the BCD means it represents decimal values exactly (to 16 digits) unlike floating point which can't represent things like .1 exactly (because that would make for a repeating expansion in base 2).

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

Snapchat A Titty posted:

Looks like reals are only accurate to 0.1?!

I'd avoid any decimal notion entirely and work in fixed point integers when handling money. Such as your 1000 up there, though if micro transactions are possible, I might start out at 4 decimals.

I'll need to look into this, but I'm not seeing the accuracy thing? I think this is represented the same way as SQL represents a real but I could be wrong.

HappyHippo posted:

Maybe I'm reading it wrong but it looks like you convert to a string and then strip out the decimal? So why not just times by 100 and convert to string with no decimal places?

Would have the same effect really. It would just change the call to:
code:
taxRate = taxRate * 1000 * 100;

taxRateStr = num2str(taxRate, 3, 0, DecimalSeparator::Dot, 0);
taxRateStr = strRem(taxRateStr, ".");
Which would also just truncate and round up. I do like the readability more though.

Edit oh I see vv

Knyteguy fucked around with this message at 18:43 on Aug 29, 2014

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
That's what I was thinking. Is the strRem even necessary then?

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

HappyHippo posted:

That's what I was thinking. Is the strRem even necessary then?

No actually. I have to export the project real quick so I'll make that change. It removes the ambiguity. Good idea!

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Yeah, disregard I guess. I just get real nervous when I see non-integers used to represent things where accuracy is super important such as money. I've spent enough time fixing reporting code and checking sales numbers to last a lifetime.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Derail but what does this notation:

] x ; y [

mean in the "Scope of data type" field on that MSDN page? I'm comfortable with mathematical notation for intervals of real numbers but I've never seen a range written in that way before and have no idea what I might google to find out. "Backwards square brackets" produces no obviously useful results.

Sebbe
Feb 29, 2004

Hammerite posted:

Derail but what does this notation:

] x ; y [

mean in the "Scope of data type" field on that MSDN page? I'm comfortable with mathematical notation for intervals of real numbers but I've never seen a range written in that way before and have no idea what I might google to find out. "Backwards square brackets" produces no obviously useful results.

It's a range excluding its endpoints.

Also written as

( x ; y )

by some. (As opposed to [ x ; y ], where x and y are included.)

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Oh, ok. That's strange to me, I've only ever seen intervals written (x, y) or [x, y] or (x, y] or [x, y) (using a comma, not a semicolon, and definitely no weird backwards brackets)

In fact I looked at the Wikipedia page before asking, but I only skimmed it and should clearly have looked more carefully, as it does explain this notation.

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