h a l f b a k e r y"Not baked goods, Professor; baked bads!" -- The Tick
add, search, annotate, link, view, overview, recent, by name, best, random
news, help, about, links, report a problem
browse anonymously,
or get an account
and write.
register,
|
|
|
Imagine you're writing a bit of computer
code and you have tell pause for a
second.
Now, is it pause(1) or pause(1000) --
should
the the parameter be in seconds or
milliseconds?
What if you could put a unit in there so
pause(1s) and pause(1000ms) are
equivalent.
Not a big idea, and
not that exciting, but
maybe something that
would stop the odd bug from creeping
into
your code.
Scientific Symbols
Scientific_20Symbols [iron_horse, Apr 26 2008]
date_modify()
http://www.php.net/...ion.date-modify.php ...works like that. [DrCurry, Apr 26 2008]
the Frink Programming Language
http://futureboy.homeip.net/frinkdocs/ Has what you speak of. [Spacecoyote, Apr 26 2008]
My reinvention of this wheel
https://docs.google...7q_39mgzw8rc4&hl=en See gtoal's 2nd annotation below [gtoal, Apr 27 2009]
[link]
|
| |
It seems to me the syntax should be something like:
'pause(1000,"S")'
or
'pause(1000,"MS")'
Where the unit of time is passed as a separate parameter. |
|
| |
I think this would just lead to more coding errors than remembering the units are always in milliseconds, but... |
|
| |
A better idea might be to just accept the fate of owning a poor attention span. I know I have... done something what? |
|
| |
I can see where this is useful for time, but
what other variables would it apply to?
Obviously, you may want to distinguish
volts and millivolts, or atmospheres and
pascals, but these aren't really the same in
programming terms as
milliseconds/seconds. However, [+] for
the idea. |
|
| |
I think this would lead to less errors as you would be forced to define your quantities. Even if there was only one unit (eg milliseconds) - being forced to suffix your time variable with ms would remind you what you were working with. |
|
| |
//you're writing a bit of computer code... or pause(1000)// sp. "pause(0x3E8)" |
|
| |
So, what happens if the number is a
variable, say "q", then you get
"pause(qms). And what if qms is another
variable? |
|
| |
If you have a variable 'q' in a strongly typed language then 'q' already has a type - either seconds or milliseconds or something else, but its unit is not ambiguous. So I don't think pause(q) is a problem, and pause(qs) is nonsensical whether you interpret it as the nonexistent variable 'qs' or as q seconds. |
|
| |
A problem can potentially occur when you use a literal value directly without checking what the function requires, and when that value could be ambiguous as to the units it's in. |
|
| |
As such, appending a type specifier to a literal number would help avoid problems. You could consider pause(1000ms) shorthand for pause( (time_milliseconds) 1000). |
|
| |
So as long as it only applies to literal values, I think it's a good idea. [+]. |
|
| |
Google Calculator does this. By coincidence we were talking about the same thing just last week in the yahoo 'compilers101' group. Shouldn't be hard to do, probably more useful for a calculator than a compiler though. |
|
| |
//So, what happens if the number is a variable, say "q", then you get "pause(qms). And what if qms is another variable?// |
|
| |
Realise you have to replace all instances of q. Give up, go make tea. That's what I'd do. |
|
| |
The DateDiff and DateAdd functions in VB do this. To add 3 days to the current day, you use DateAdd("d",3,today()) and to add 3 years you use DateAdd("yyyy",3,today()) |
|
| |
cf. PHP: sleep() in seconds vs. usleep() in microseconds. As per SI, the base unit of time is the second and so that is what should be assumed, unless otherwise indicated. |
|
| |
Seems a bit pedantic: aren't your variables or library functions already going to be in the format most used for the program or module ? |
|
| |
You've basically invented the Frink programming language [link]. |
|
| |
Dimensional analysis can catch a lot of calculation mistakes, but it's hardly perfect. Learning to rely upon it can be a recipe for disaster since many equations require dimensionless scaling factors (the most common being 0.5, as in s=0.5*g*t*t). |
|
| |
Some time back I sketched out some ideas in this vein in more detail - then I found someone had already implemented something almost identical to what I had designed, which I think means that rather than feeling bad that someone had done it before, I should feel good that someone reinforced my gut feeling that this is the obvious way to go :-) See my link above and please follow it through to Mark Austin's "Alladin" system at umd.edu |
|
| |
MyTime = TimeSinceY2KInSeconds();
Do {} While TimeSinceY2KInSeconds() < MyTime + 1; |
|
| |
Apart from that, it's quite a nice idea to have an interface to the computer that is based on real-world units. Maybe on startup, it could determine the size of your monitor and figure out exactly how long a centimetre is for you - this must be on the cards for future touch displays. |
|
| |
The same goes for seconds (assuming the user and the machine are occupying the same relativistic frame of reference of course) |
|
| |