 h a l f b a k e r y Number one on the no-fly list
idea:
add, search, annotate, link, view, overview, recent, by name, best, random
meta:
news, help, about, links, report a problem
account:
Browse anonymously,
or get an account
and write.
Login
Create account.
|
|
|
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]
[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]. |
|
| |
Or, if the language allows, use typesafe
enumeration in the passed parameters
(Second, Millisecond, whatever) instead
of
primitive types like integer and double. |
|
| |
Or get an editor that provides a decent
synopsis
of a function's intent and parameter
specs
when you hover over an occurrence of
it. |
|
| |
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). |
|
| |