I don't think there's anything wrong, in principle, with this approach, so long as the simulated rate is calibrated frequently to the actual average donation rate.
Having it all wired up properly would require a whole lot of infrastructure, particularly for donation mechanisms that aren't online and aren't all tied in to a single system.
This is how I do it on my personal website (http://samryan.co.uk/). It makes no sense for me to put together a real automatically updating counter so every couple of days I check the real growth rate and adjust it manually. It obviously looks shady on a politicians website and I think doing it with something like donations where it's tied to a real world action is a bit... silly and they should have disclosed that it was an ESTIMATE however I don't think it is as heinous as other people suggested. It's only an issue if the donations don't exist.
It's a shame, because having an actual working one would be a really cool feature to do technically. But because of how easy to fake, it doesn't look like much. Then again, the more practical side of me says having a working one is a total waste of time 99% of the time. Everything's an estimate in some way.
There doesn't appear to be anything in this code to calibrate to the actual average donation rate. In fact it's not tied to any real amounts or rates at all. It's just a function of the current datetime.
UPDATE: They took the donation page down...
Forbidden
You don't have permission to access /stillneedhelp/
on this server.
Unless they've changed the code, there are some manually adjusted values that estimate the average donation rate based on some magic number they plugged in from their own projections (/propaganda if you think this was intentionally misleading).
If I had to guess, val1 was how many committed donations they had at 11am April 24th and val2 is how much they anticipated raising in the following 13 hours of April 24th. Note that Santorum suspended his campaign April 10th, so it looks like someone probably was updating this manually until the campaign was fully disbanded.
> There doesn't appear to be anything in this code to calibrate to the actual average donation rate. In fact it's not tied to any real amounts or rates at all. It's just a function of the current datetime.
I would assume that while the campaign was active they would periodically adjust the constants to reflect the current average.
My guess is the same barely-competent webmaster who wrote the JS noticed a huge traffic spike in that directory, and disabled the index but not the cause of the spike. But we'll see... (Ed: downvotes make me think you were right. :)
Yeah, I figured that was the real reason, the edit is tongue-in-cheek. But I don't think it's unfounded. Just look at all the comments criticizing the coding! (Particularly in Osiris' thread.) I don't consider myself a master programmer but at least I use 'var' by habit. Now one other objection I considered was the use of "barely-competent" as a term, which seems like a strange one since typically people are either competent or incompetent. But that's not really the whole picture in general and certainly not in coding. I don't just mean the levels of mastery[1], "barely-competent" here is the Just Good Enough (hey, it "works" for its purpose and most people won't know any better if they pay attention at all) and the Just Good Enough is often just fine in practice but it's not the actual goal. The goal is to do better, but if you never want to do better than the Just Good Enough, well, I for one don't want to work with you.
Well, theoretically they could just have a guy manually pushing new rate values to reflect reality.
But that's a big theoretically. This is almost certainly malice.
And it would almost certainly have gone unchecked if the developer had only hidden the BS generator script on the server side.
But as others have pointed out, that's probably asking too much given the state of this code and given that the main page 403's but they left the BS script serving.
You can infer from the Javascript, but it just displays a dollar amount equal to the number of seconds elapsed since a certain time (edit: whoops, see below), according to your computer clock. If you refresh every second it will go up by $1 each time. If you set your clock back a year, the donation meter will read $-17 million.
Edit: Actually, this isn't quite accurate, it's closer to one dollar per two seconds. 1/(vchange*1000) =
1.7976923076923077 seconds to be exact...
What? You mean a politician was using a simulation and presenting it as definitive? I'm shocked I tell you, shocked!
(with apologies to Captain Renault :-)
You could just read the quarterly reports he files with the FEC if you actually wanted to know how much he was bringing in. I suppose you could get him in hot water as an ethics violation for campaign reporting but outrage? A bit over the top I think. There are billboards that had a running total of the California state deficit, does anyone think they were repeatedly reading some sort of get_balance() api at the state treasury and putting it up? No, its a prop, a gimmick, an illustrative tool, and nothing more.
Actually this raises some interesting questions when you think about how the average person is going to think when they see something like this. First impressions to normal people are that they would be real-time given the instantaneous nature of the internet.
Regardless, it's almost certainly false advertising which as you mentioned is ethically questionable especially since this is supposed to be a 'leader' of citizens.
"The right to private variables is not the right to a common good. It’s a me-centered right, that obviously started in the sexual revolution with contraception and obviously quickly evolved to abortion, and now has found its way into the marriage debate. And all those acts that were self-giving acts, self-sacrificing acts, have been polluted by this right to privacy." -- Rick Santorum
I find it most disturbing that they are polluting the global namespace with all those variables and functions. Don't JavaScript developers these days understand how to properly scope their JavaScript?
It's still incredibly error prone and just bad practice. It's a telltale sign of a bad developer because a good dev would instinctively just use var without thinking about it. Good devs may make a mistake here or there but this is clearly well beyond a forgotten var keyword.
I'm just guessing, but the site was probably not developed by a technical team, probably some web shop that specializes more on the design/layout/content side and not on the JS side.
So it's likely it's the work of a non-developer than a bad developer. The net result is the same (bad code) but the distinction is that the code was possibly written by someone who wouldn't even be considered a developer.
But when writing code, how do you know that it's always going to be "single page bound"? YAGNI is frequently useful poison and nothing more. When it's so easy to do it right the first time, why not?
> When it's so easy to do it right the first time, why not?
a) Because it isn't "right" as such. It's just "better" if the code is going to be reused. Which it isn't.
b) The code style serves as documentation. I can clearly read from this code that it's not a reusable component. It is now easier for me to get an idea of how and where this code is being used in the site.
c) Personally, I'm wary of "pre-emptive generalization". Every layer of abstraction makes the code slightly less readable. Also, unless there exists at least two use cases right now, you're not likely to get the reusability right anyway.
Are you really asking why a developer tasked with creating something intentionally deceptive didn't use best practices? I'm thinking not a lot of care or attention to anything was paid that day.
Different kind of ethics:
"It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter." (lost the source of the quote)
To understand how these problems can be addressed, it is instructive to consider an analogy. Imagine, for a moment, that somewhere in the basement of the Pentagon there are two computers. They are identical hardware, and they run identical software; they are as alike as two peas in a pod. On each of them, there is an executable procedure called "DestroyBaghdad". On one of the machines, executing this procedure does nothing. On the other, the effects of executing the procedure are disastrous, at least for the citizens of Iraq. The only difference between the two machines is a single wire coming out of the back of the second machine.[1]
The point, of course, is that nothing inherent to a computational language is dangerous; danger is posed only insofar as the effects of executing statements in a language include "side-effects" in the external world. If all the "wires" connecting a computational language to the outside world are cut, then executing programs in that language is harmless. (An exception to this claim is that such a program can still tie up the CPU, virtual memory, or swap space on a machine by going into an infinite loop; this can be handled via resource limitations.)
[1]It should be noted that no ethically-trained software engineer would ever consent to
write a "DestroyBaghdad" procedure. Basic professional ethics would instead require
him to write a "DestroyCity" procedure, to which "Baghdad" could be given as a
parameter.
Ah, perhaps this is the case. Would have been fun to stumble across a "Help, I'm trapped in a bullshit factory!" comment or something. But that would not help one's career.
8 is the traditional size of tabs though, isn't it? Seems like a reasonable default. That's partially why some teams (mine included) discourages the use of tabs in source code - its appearance varies depending on what's rendering it, affecting code readability.
The defacto standard is to put nothing in an enclosing namespace unless it's needed there. The purpose of functions (especially in a language like JS) is to wrap up everything that's needed to accomplish a given task and leave no mess behind.
Then why oh why are variables global by default? (this is not meant as an attack on your point, I fully agree, I just find this awfully frustrating about JS. Sane languages have scoped by default and a global keyword, not the other way around)
Pretty amusing. Google actually does something similar on the Gmail homepage to indicate the amount of free storage but they're doing an actual estimate using linear interpolation. You can view the source on the gmail home page and look at the updateQuota method.
GMail's meter is fine -- it's displaying the state of a value which Google has decreed will increase at a set rate. Unlike Santorum's donations, it's not an unpredictable measurement.
It finds the closest entry in there to the current value of "new Date().getTime()". Then it just adds (what roughs out to) .000004 for every second's difference between the 0 value and the current getTime() value. So today it reads 10250 MB, which must come from index 2 of that array + enough seconds to add 10 MB and some. Definitely more legit than Santorum's.
The actual subtractions of the current time from the one in the array seem to be more detailed than what's put on the page, which is being rounded. A sample of input for format():
IIRC GMail's meter is updated at a rate which is actually accurate, and is simulated so that the page doesn't need to keep asking google for the capacity.
It fascinates me that Americans might see this as acceptable or even that it is regarded as most likely to be totally legal and hence acceptable in nature. In Australia I would be very confident that this type of falsified campaign disclosure would be illegal or at least fall foul of a whole range of parliamentary and governmental standards.
Honestly in other cases they are. I had personal experience developing tools used for Howard Dean's 2004 primary campaign (as a volunteer not staff) and in that case it was certainly real.
I'd be very, very surprised if the ones used by Ron Paul and Obama weren't real. They have good engineering talent there, and (in the case of Obama at least) good political talent. This runs contrary to both.
Can confirm that the thermometers on Obama fundraising pages (MyBo and others) are real (not simulated and not manipulable). It's a feature of the donation software they use.
Same thing as the Google GMail "space available" counter. As long as you back it up by real numbers and adjust the rate appropriately no harm, no foul.
Though I have no idea how much has truly been donated to Rick Santorum, but I would bet that growing thermometer did help contribute to that. Perception is an incredibly strong tool that can be used to elicit reactions like donating "because everyone else seems to be". Sad that they're using such a tacky tactic.
I think he suspended his campaign. Suspending means that while for all intents and purposed but one, the campaign is ended. The exception is that it allows the candidate to raise money (usually to pay off campaign debt). Ending a campaign means you hold the bag, if you're in the red, as I understand it.
Actually your candidacy is its own separate legal entity, so you're not legally holding the bag. However your reputation is at stake, if you ever want to run for public office in the future, nobody will lend you money if you've proven to be a bad credit risk in the past.
This is awesome. I know of scammy companies that have gone out of their way to use actual live subscriber counts on their sites, yet this idiot uses a fake one.
Having it all wired up properly would require a whole lot of infrastructure, particularly for donation mechanisms that aren't online and aren't all tied in to a single system.