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
Melted_Igloo
Nov 26, 2007

"" posted:

stuff about embedded system

I forgot whats also funny
Trying to optimize an embedded system dear god..

Running a profiler might show 70% of the time the program is in the "wait" function
As in 70% of the time it was doing absolutely nothing

Why you might say? Good question...

Adbot
ADBOT LOVES YOU

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Melted_Igloo posted:

Running a profiler might show 70% of the time the program is in the "wait" function
As in 70% of the time it was doing absolutely nothing

Why you might say? Good question...

Do you mean a function that just runs the processor at full blast doing nothing? Because there is nothing wrong with idling.

Melted_Igloo
Nov 26, 2007

Wheany posted:

Do you mean a function that just runs the processor at full blast doing nothing? Because there is nothing wrong with idling.

Well when you have data backed up in one processor and not getting sent to another processor (talking about an embedded system) then yes idling is sort of bad

Actually - Any real-time system, idling is bad, because it should be doing something like making sure the system is still running and not crashing spectacularly
although windows is pretty good at hiding all the background stuff going on I give it that, its actually pretty awesome how Windows works

Melted_Igloo fucked around with this message at 17:06 on May 17, 2011

feedmegin
Jul 30, 2008

Ryouga Inverse posted:

This sounds great until you realize that it means you have to install Qt 3 and 4 side by side on any machine that you want to run Qt apps for an arbitrary amount of time, because there's always that one rear end in a top hat who wrote his poo poo for Qt 3 and then had the audacity to die or something.

I mean, there are arguments to be made for both, but you certainly can't change your API every time you have a whim, and in some cases (like the Internet) you can't ever break backward compatibility. And the problem is that those cases look exactly like the best-case success story that you only dream of.

Qt is also good at not changing its API on a whim. Within a major version number, it remains forward compatible at a binary level (code compiled for Qt 4.2 will run with Qt 4.7). They only break things every few years with a new major version number. For open-source C++ libraries, that's pretty rare.

I personally can't think of any Qt 3 apps still sitting around that I run, but I can imagine the scenario cropping up. That's life, basically, there's not a good alternative to having both sets of libraries sitting around.

ColdPie
Jun 9, 2006

Jonnty posted:

At the very worst, it's just old code that hasn't been taken out (I assume), but it doesn't sound like it's causing any active harm? I'd hardly call that a horror, just a bit overcautious. Unless it's checking for something that needn't be checked the first place.

Well, unless Opera releases a version 50, at which point that code will enable the Opera 5 (now 80 years old) hacks.

Doing stuff based on browser version strings is pretty much inexcusable.

NotShadowStar
Sep 20, 2000
Unfortunately because the DOM is such a hosed up mess, trying to figure out what browser you're on is the best you're going to get in a lot of cases to see if the browser supports what you're trying to do.

It would be great if the DOM had a 'supported' namespace so we could do 'if (browser.supported.elements.video)' but that's too much to handle for the W3C. So we have to do hosed up poo poo like if (document.createElement('video').canPlayType). Sometimes that doesn't even work (IE) so we have to do poo poo like Is it IE? Okay what version of IE?

pseudorandom name
May 6, 2007

Even if there was a way to ask if the browser supports a feature, you'd still have to sniff the browser version to workaround the inevitable browser bugs.

OddObserver
Apr 3, 2009

NotShadowStar posted:

It would be great if the DOM had a 'supported' namespace so we could do 'if (browser.supported.elements.video)' but that's too much to handle for the W3C.
It does. document.implementation.hasFeature. The actual feature granularity kinda sucks, though.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

OddObserver posted:

It does. document.implementation.hasFeature. The actual feature granularity kinda sucks, though.

This is actually really frustrating when looking online to find the best way to detect a certain kind of browser. "Best practice" has taken over the web and virtually every site you find says "oh don't do browser detection, do feature detection".

Which is great if what you're trying to detect is whether a feature is supported or not. But despite the fact that we're in two-thousand-loving-eleven there are still behavioral differences between browsers that don't have anything to do with a DOM or script feature.

It's obnoxious that web dev conventional wisdom has decided these cases no longer crop up anymore.

Profane Obituary!
May 19, 2009

This Motherfucker is Dead

NotShadowStar posted:

Unfortunately because the DOM is such a hosed up mess, trying to figure out what browser you're on is the best you're going to get in a lot of cases to see if the browser supports what you're trying to do.

It would be great if the DOM had a 'supported' namespace so we could do 'if (browser.supported.elements.video)' but that's too much to handle for the W3C. So we have to do hosed up poo poo like if (document.createElement('video').canPlayType). Sometimes that doesn't even work (IE) so we have to do poo poo like Is it IE? Okay what version of IE?



http://www.modernizr.com/

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Monkeyseesaw posted:

Which is great if what you're trying to detect is whether a feature is supported or not. But despite the fact that we're in two-thousand-loving-eleven there are still behavioral differences between browsers that don't have anything to do with a DOM or script feature.

Sorry, I'm new to this: can you give an example?

e: VVV :catstare:

Doc Hawkins fucked around with this message at 04:17 on May 18, 2011

pseudorandom name
May 6, 2007

Because it is fresh in my mind, here's a discussion of keyboard input across the different browsers: http://unixpapa.com/js/key.html

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

Doc Hawkins posted:

Sorry, I'm new to this: can you give an example?

Go try to implement the auto-expanding textboxes in Facebook, where the text can be round-tripped (typed->saved to disk->displayed all the same). You'll run into enough that you don't want to play anymore before you get one browser done.

If you do manage to get one done, go paste a Word doc into it. WHAT THE gently caress :argh: (I know that's the way it's supposed to work ... now ... but man that poo poo was infuriating, because I was writing it for people who were going to do exactly that.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Another input related one is Firefox notoriously caches input fields across multiple POSTs. This can be a huge pain in the rear end if, for example, dropdown selections determine a number of other JS-enhanced elements on the page and the drat events don't fire on reload in Firefox because the input fields are already "selected".

The workaround isn't difficult but it's a case where no "if (window.blah)" can solve the problem.

I've run into others involving subtleties in how some browsers fire off dependent HTTP requests when a user is navigating away from the current page; some browsers simply skip the request if it determines the response won't be useful. If you're trying to implement an internal JS analytics package that relies on sending that request it puts a rather sizable hole in your data aggregation and the only way to account for it is old-fashioned browser-sniffing :argh:

Dr Monkeysee fucked around with this message at 05:54 on May 18, 2011

Surface
May 5, 2007
<3 boomstick

Monkeyseesaw posted:

Another input related one is Firefox notoriously caches input fields across multiple POSTs. This can be a huge pain in the rear end if, for example, dropdown selections determine a number of other JS-enhanced elements on the page and the drat events don't fire on reload in Firefox because the input fields are already "selected".

The workaround isn't difficult but it's a case where no "if (window.blah)" can solve the problem.

I've run into others involving subtleties in how some browsers fire off dependent HTTP requests when a user is navigating away from the current page; some browsers simply skip the request if it determines the response won't be useful. If you're trying to implement an internal JS analytics package that relies on sending that request it puts a rather sizable hole in your data aggregation and the only way to account for it is old-fashioned browser-sniffing :argh:

This causes real issues in many places of Django's admin interface.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
A couple of points: Browser sniffing can help in doing workarounds for specific browsers for certain feaures. That is something we have to live with at the moment.

What you should never use it for is blocking access to your site or placing a "gently caress you" banner on top of every page on your site (like Picasa does for Opera)

My second point is: Opera has always been a marginal desktop browser, at least globally, meaning only "enthusiasts" (nerds) have installed it. So, from the 2% market share that all Opera versions have cumulatively, probably 80% are a reasonably current. (Numbers pulled out of my rear end, natch)

So if you want to pretend that you support Opera, why would you check for Opera 5, and only Opera 5? It is literally over 10 years old and there are like 4 installations of it in existence on Windows 98 computers rotting on some attics somewhere.

e: Opera's rendering engine has changed once since then (in 2003) and its JavaScript engine has changed twice. It's literally a different browser. So loving angry about Opera.

Wheany fucked around with this message at 07:29 on May 18, 2011

Zombywuf
Mar 29, 2008

Monkeyseesaw posted:

I've run into others involving subtleties in how some browsers fire off dependent HTTP requests when a user is navigating away from the current page; some browsers simply skip the request if it determines the response won't be useful. If you're trying to implement an internal JS analytics package that relies on sending that request it puts a rather sizable hole in your data aggregation and the only way to account for it is old-fashioned browser-sniffing :argh:

I assume you've tried:
code:
Cache-Control: no-store, no-cache, max-age=0, must-revalidate
?

Sign
Jul 18, 2003

Jonnty posted:

So...the horror is that your app is too portable?

In 2006 I had to make part of a web app work with IE 3. It only killed me a little on the inside.

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


ColdPie posted:

Well, unless Opera releases a version 50, at which point that code will enable the Opera 5 (now 80 years old) hacks.

Doing stuff based on browser version strings is pretty much inexcusable.

That Opera "fix" is the real coding horror here.

SirViver
Oct 22, 2008
Gotta submit my own horror of shame
code:
[C#]
public void Import(int number)
{
    if (number.ToString().Length > 10)
    {
        //Error...
    }
    //...
}
Yeah I don't know how I expected this to work either :downs:


E: The real horror, however, is the web service receiving the import data having only a single method with a single string field as parameter. Containing an XML document, of course :downsgun:
(But at least it wasn't me who designed this turd.)

SirViver fucked around with this message at 16:28 on May 18, 2011

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

HatfulOfHollow posted:

That Opera "fix" is the real coding horror here.

I prefer Opera's user agent to this:

quote:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13

That is the user agent of Mozilla-AppleWebKit-KHTML-Gecko-Chrome-Safari.

Just throw Internet Explorer and Trident in there for maximum compatibility.

Fiend
Dec 2, 2001
I found a home for you, date printer!

code:
static string printDay()
{
    DateTime Today = DateTime.Now;
    // format as "07.APR.2007" 
    String printedDay = GetDay(Today.Day) + "." + GetMonth(Today.Month) + "." + Today.Year;
    return printedDay;
}

static string GetMonth(int monthNumber)
{
    string retVal = string.Empty;
    switch (monthNumber)
    {
        case 2: retVal = "FEB"; break;
        case 3: retVal = "MAR"; break;
        case 4: retVal = "APR"; break;
        case 5: retVal = "MAY"; break;
        case 6: retVal = "JUN"; break;
        case 7: retVal = "JUL"; break;
        case 8: retVal = "AUG"; break;
        case 9: retVal = "SEP"; break;
        case 10: retVal = "OCT"; break;
        case 11: retVal = "NOV"; break;
        case 12: retVal = "DEC"; break;
    }
    return retVal;
}

static string GetDay(int dayNumber)
{
    if (dayNumber.ToString().Length == 1)
    {
        return "0" + dayNumber.ToString();
    }
    else
    {
        return dayNumber.ToString();
    }
}
Senior Software "Architect"; Lacks basic knowledge of format strings & January; Explains this was ported over from the code base they used when they taught themself VBScript.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I never liked January much, so I applaud that date printer for it's bold step.

Sedro
Dec 31, 2008

Fiend posted:

code:
static string GetMonth(int monthNumber)
{
    string retVal = string.Empty;
    switch (monthNumber)
    {
        case 2: retVal = "FEB"; break;
        case 3: retVal = "MAR"; break;
        case 4: retVal = "APR"; break;
        case 5: retVal = "MAY"; break;
        case 6: retVal = "JUN"; break;
        case 7: retVal = "JUL"; break;
        case 8: retVal = "AUG"; break;
        case 9: retVal = "SEP"; break;
        case 10: retVal = "OCT"; break;
        case 11: retVal = "NOV"; break;
        case 12: retVal = "DEC"; break;
    }
    return retVal;
}

Why do people do this? What's wrong with:
code:
static string GetMonth(int monthNumber)
{
    switch (monthNumber)
    {
        case 2: return "FEB";
        case 3: return "MAR";
        ...
        default: return string.Empty;
    }
}

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
That has multiple exit points and everything must be SESE because structured programming will save us from the horrors of goto.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I know nothing about Java so don't yell at me if the syntax is off, but surely this is better?

code:
static string GetMonth (int monthNumber) {
    string[] months = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                        "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
                        };
    return (monthNumber < 1 || monthNumber > 12) ? "" : months[monthNumber - 1];
}

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
It's usually hazardous to try to "Fix" horrors in these threads.

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Hammerite posted:

I know nothing about Java so don't yell at me if the syntax is off, but surely this is better?

The right thing to do is use your language's preferred date/calendar library for things like this, if possible, rather than do it yourself at all.

Fiend
Dec 2, 2001

Hammerite posted:

I know nothing about Java so don't yell at me if the syntax is off, but surely this is better?

code:
static string GetMonth (int monthNumber) {
    string[] months = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                        "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
                        };
    return (monthNumber < 1 || monthNumber > 12) ? "" : months[monthNumber - 1];
}

Find/Replace 'printDay()' with 'DateTime.Now.ToString("dd.MMM.yyyy").ToUpper()'

OddObserver
Apr 3, 2009

Wheany posted:

I prefer Opera's user agent to this:


That is the user agent of Mozilla-AppleWebKit-KHTML-Gecko-Chrome-Safari.

Just throw Internet Explorer and Trident in there for maximum compatibility.

And if you do navigator.appName, you'll get 'Netscape'.

POKEMAN SAM
Jul 8, 2004

OddObserver posted:

And if you do navigator.appName, you'll get 'Netscape'.

Haha, that's like the cherry on top :D

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Fiend posted:

Find/Replace 'printDay()' with 'DateTime.Now.ToString("dd.MMM.yyyy").ToUpper()'

Well, "lines of code written per day" obviously isn't a performance metric where you work! That other guy is like 40x more productive than you.

Chakron
Mar 11, 2009

Hammerite posted:

I know nothing about Java so don't yell at me if the syntax is off, but surely this is better?

code:
static string GetMonth (int monthNumber) {
    string[] months = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                        "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
                        };
    return (monthNumber < 1 || monthNumber > 12) ? "" : months[monthNumber - 1];
}

Replace every month with January and I think you've got it!

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Hammerite posted:

I know nothing about Java so don't yell at me if the syntax is off, but surely this is better?

code:
static string GetMonth (int monthNumber) {
    string[] months = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                        "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
                        };
    return (monthNumber < 1 || monthNumber > 12) ? "" : months[monthNumber - 1];
}
can i yell at you because it isn't Java?
If somebody wants to yell at me, I'm guessing it's C#. I don't know anything about it thought because my .NET frameworks always commit suicide.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Zombywuf posted:

I assume you've tried:
code:
Cache-Control: no-store, no-cache, max-age=0, must-revalidate
?

We tried everything we could possibly think of. We also confirmed it was an issue in other analytics packages (including Google Analytics, who actually warn in their documentation not to rely on this specific kind of event). It's not standard HTTP behavior, the request just never fires. Given the edge-case nature of it my guess is it's some weird "optimization" in the request/response loop someone decided was a good idea at some point.

Wheany posted:

So if you want to pretend that you support Opera, why would you check for Opera 5, and only Opera 5? It is literally over 10 years old and there are like 4 installations of it in existence on Windows 98 computers rotting on some attics somewhere.

What's particularly funny about this is Opera is literally the easiest browser to detect: if (window.opera).

Though I don't know if this property was available 10 years ago.

Dr Monkeysee fucked around with this message at 07:10 on May 19, 2011

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Monkeyseesaw posted:

What's particularly funny about this is Opera is literally the easiest browser to detect: if (window.opera).

Though I don't know if this property was available 10 years ago.
Amusingly it was added in Opera 5.

enthe0s
Oct 24, 2010

In another few hours, the sun will rise!

Sedro posted:

Why do people do this? What's wrong with:
code:
static string GetMonth(int monthNumber)
{
    switch (monthNumber)
    {
        case 2: return "FEB";
        case 3: return "MAR";
        ...
        default: return string.Empty;
    }
}

I'm only into my 3rd year of programming, but my college teaches us to not use multiple return statements and instead create a single variable at the top and return it at the end. Why exactly, I'm not sure, but I hear it's good form.

Brecht
Nov 7, 2009

enthe0s posted:

I'm only into my 3rd year of programming, but my college teaches us to not use multiple return statements and instead create a single variable at the top and return it at the end. Why exactly, I'm not sure, but I hear it's good form.
Depends entirely on the function. Single-entry single-exit has its place, but it's not "every place".

Opinion Haver
Apr 9, 2007

enthe0s posted:

I'm only into my 3rd year of programming, but my college teaches us to not use multiple return statements and instead create a single variable at the top and return it at the end. Why exactly, I'm not sure, but I hear it's good form.

It's only good form in cases where it improves readability. In cases like that, it's just stupid.

Adbot
ADBOT LOVES YOU

Incoherence
May 22, 2004

POYO AND TEAR

enthe0s posted:

I'm only into my 3rd year of programming, but my college teaches us to not use multiple return statements and instead create a single variable at the top and return it at the end. Why exactly, I'm not sure, but I hear it's good form.
As usual, this is sort of a good idea in theory (it keeps you from forgetting to clean up after yourself before returning in languages/situations where that matters, at the possible cost of making your logic harder to follow), but eventually everyone just sort of forgets the tradeoff part of it and it gets upgraded into a Law of Programming.

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