Half a croissant, on a plate, with a sign in front of it saying '50c'
h a l f b a k e r y
Quis custodiet the custard?

idea: add, search, annotate, link, view, overview, recent, by name, random

meta: news, help, about, links, report a problem

account: browse anonymously, or get an account and write.

user:
pass:
register,


                                           

Dimensioned Variables

Numbers with units.
  (+5, -4)
(+5, -4)
  [vote for,
against]

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.

st3f, Apr 25 2008

Scientific Symbols Scientific_20Symbols
[afinehowdoyoudo, 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...
phoenix, Apr 25 2008
  

       What [phoenix] said.   

       A better idea might be to just accept the fate of owning a poor attention span. I know I have... done something what?
daseva, Apr 25 2008
  

       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.
MaxwellBuchanan, Apr 25 2008
  

       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.
wagster, Apr 25 2008
  

       //you're writing a bit of computer code... or pause(1000)// sp. "pause(0x3E8)"
AbsintheWithoutLeave, Apr 25 2008
  

       //pause(1000ms)//   

       So, what happens if the number is a variable, say "q", then you get "pause(qms). And what if qms is another variable?
MaxwellBuchanan, Apr 25 2008
  

       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. [+].
Srimech, Apr 25 2008
  

       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.
gtoal, Apr 25 2008
  

       pause.ms(1000)
Ian Tindale, Apr 26 2008
  

       //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.
wagster, Apr 26 2008
  

       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())
angel, Apr 26 2008
  

       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.
vincevincevince, Apr 26 2008
  

       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 ?
FlyingToaster, Apr 26 2008
  

       You've basically invented the Frink programming language [link].
Spacecoyote, Apr 26 2008
  

       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).
supercat, Apr 27 2008
  

       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
gtoal, Apr 27 2009
  

       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)
zen_tom, Apr 27 2009
  
      
[annotate]
  


 

back: main index

business  computer  culture  fashion  food  halfbakery  home  other  product  public  science  sport  vehicle