• Mark (unregistered) in reply to jay
    jay:
    At my last job, my boss established a company standard that we were NOT ALLOWED to change indenting of existing lines of code. So if, for example, you added an IF statement that encompassed an existing block of code, you couldn't move those lines to the right to line up under the IF. The stated reason for this was that when we committed code to the library, this would make those lines look changed when they really weren't.

    (Of course, we were using SVN, which has a flag to say whether changes in spacing should show up as changed lines in output, so basically his problem was that he didn't want to have to check a box.)

    Substituting one small hassle for a very large hassle is, unfortunately, something some managers excel at. Usually it means the small hassle is off their plate and the very large hassle is on someone else.

  • erat (unregistered) in reply to Ardik
    Ardik:
    da Doctah:
    Ardik:
    (As mentioned before by others) why not just
      setTimeout("start()",1000)
    and drop msec completely?! Would've resulted in a quite accurate result with any client (apart from skipping "0", of course).

    A timeout of 1 msec doesn't work in any browser.

    Probably that developer did some trial and error which timing somewhat fits the clock and based on that decided that 1 second has 100 msecs.

    Everyone is making the totally unwarranted assumption that "msec" in the OP's code is supposed to stand for "millisecond".
    Not me!
    da Doctah:
    It's not. In this context, it's "minisecond".
    csec would've been more appropriate then.

    Well, if a vaginal birth is not possible, I guess...Oh, you meant something else. Sorry.

  • (cs) in reply to foad
    foad:
    redtetrahedron:
    fwip:
    redtetrahedron:
    At a previous job, I inherited a javascript app with 15K-line files from a fired co-worker who had a completely haphazard indenting style, enough to make the code virtually unreadable. Also - there were no semicolons ending the lines, just like this code. I convinced my supervisor to buy a code-reformatting tool, but before I could use it, I still had to add semicolons to the end of each statement before the reformatting tool would be able to parse the code. Ugh!
    Step 1. vim code.js Step 2. gg=GZZ Step 3. That was all the steps, you're done already.

    OH! Of course! That's so self-evident and intuitive

    /s

    I missed the part where you were guaranteed that everything in life would be easy and require no knowledge or thought on your part.

    I was commenting on the apparent tendency of UNIX commands to be obscure for the sake of obscurity. To each their own, though...

  • urza9814 (unregistered) in reply to Mason Wheeler
    Mason Wheeler:
    g:
    mike5:
    Not like (hours = timeInSecods / 3600 ), and minutes = (timeInSeconds % 3600 ) / 60 and seconds = (timeInSeconds % 60) ?
    hours = Math.floor(timeInSeconds / 3600);
    minutes = Math.floor((timeInSeconds % 3600) / 60);
    
    Division in javascript results in floats

    Division in any sane language results in floats. (Or fractions, if your language does that.) It's simple mathematics. If you can say 5/2 and get 2 as a result, there's something wrong with your language.

    So you believe all statically typed languages are insane? If you do 5/2 in C, Java or pretty much any statically typed language it's going to give you 2. You've gotta explicitly cast those ints to floats if you want a float as a result.

  • Steve HoldowaySteve (unregistered) in reply to dkf
    dkf:
    letatio:
    Who the hell indents like that?
    I used to work with someone who indented like that. As far as I could work out, it was a style they learned when they started out on FORTRAN (but I don't know which version, 66 or 77)…

    It would have to be fortran 77 as that's when block ifs were introduced

  • Broke my fingers on a teletype (unregistered) in reply to redtetrahedron
    redtetrahedron:
    ...

    I was commenting on the apparent tendency of UNIX commands to be obscure for the sake of obscurity. To each their own, though...

    I take it you have never typed a significant amount of text on the teletype machines that Unix originally ran on. Slow, clumsy keyboards with giant mechanical keys that (slightly exaggerated) you had to mash with your fist to use.

    5 minutes with one of those and you will quickly realize that those commands are not "obscure for the sake of obscurity" but rather "shortened for your fingers' sake".

  • PG4 (unregistered) in reply to Broke my fingers on a teletype
    Broke my fingers on a teletype:

    I take it you have never typed a significant amount of text on the teletype machines that Unix originally ran on. Slow, clumsy keyboards with giant mechanical keys that (slightly exaggerated) you had to mash with your fist to use.

    5 minutes with one of those and you will quickly realize that those commands are not "obscure for the sake of obscurity" but rather "shortened for your fingers' sake".

    So explain to me how the "biff" command got named when something else with 4 characters would have been much better.

  • (cs) in reply to urza9814
    urza9814:
    Mason Wheeler:
    g:
    mike5:
    Not like (hours = timeInSecods / 3600 ), and minutes = (timeInSeconds % 3600 ) / 60 and seconds = (timeInSeconds % 60) ?
    hours = Math.floor(timeInSeconds / 3600);
    minutes = Math.floor((timeInSeconds % 3600) / 60);
    
    Division in javascript results in floats

    Division in any sane language results in floats. (Or fractions, if your language does that.) It's simple mathematics. If you can say 5/2 and get 2 as a result, there's something wrong with your language.

    So you believe all statically typed languages are insane? If you do 5/2 in C, Java or pretty much any statically typed language it's going to give you 2. You've gotta explicitly cast those ints to floats if you want a float as a result.

    Not "pretty much any statically typed language." Just the C family, which is insane for many reasons, including this one.

    In Pascal, on the other hand, (which is also statically typed,) "5/2" returns 2.5; if you want a result of 2, you use the integer division operator: "5 div 2". Which is the right way to do it: division behaves as actual division, and if you want something that's not quite real division but is similar, you use a different operator.

  • Jack 27 (unregistered) in reply to johnckirk
    johnckirk:
    if(msec==100)
    {
    msec=0
    sec--
    }

    I always thought that there were 1000 milliseconds in a second.

    It doesn't matter. They aren't actually counting milliseconds, anyway.

  • (cs) in reply to Broke my fingers on a teletype
    Broke my fingers on a teletype:
    redtetrahedron:
    ...

    I was commenting on the apparent tendency of UNIX commands to be obscure for the sake of obscurity. To each their own, though...

    I take it you have never typed a significant amount of text on the teletype machines that Unix originally ran on. Slow, clumsy keyboards with giant mechanical keys that (slightly exaggerated) you had to mash with your fist to use.

    5 minutes with one of those and you will quickly realize that those commands are not "obscure for the sake of obscurity" but rather "shortened for your fingers' sake".

    No, thankfully. But, surely not needed now? I guess it's a matter of not changing anything you don't have to...

  • (cs) in reply to Mason Wheeler
    Mason Wheeler:
    Division in any sane language results in floats. (Or fractions, if your language does that.) It's simple mathematics. If you can say 5/2 and get 2 as a result, there's something wrong with your language.
    8/10. Would cheerfully flame (actually, someone already did).
  • qbolec (unregistered)

    So TRWTF is nobody has noticed for 6 years, that this clock was skewed by around 30% to 50% because 15ms is not equal 1cs?

  • HoHum (unregistered)

    Errr...The issue with the 0 ain't got nought to do with speed of a computer....

    There's a bug in the code that means 0 will ALWAYS appear to be missed. But noone else noticed that, right?

  • (cs)

    Am I the only one who starts with a timestamp and then just polls the difference for intervals? If you have to roll your own then thats probably the most reliable way I can see to do it.

  • Broke my fingers on a teletype (unregistered) in reply to redtetrahedron
    redtetrahedron:
    ... No, thankfully. But, surely not needed now? I guess it's a matter of not changing anything you don't have to...

    That and several decade's worth of legacy programs, scripts, and software...

    Of course you can customize the shell's commands with the alias command if you feel that the defaults are too cryptic

    Original

    ls

    Shorter

    alias l='ls -lart'

    Windows Flavour

    alias dir='ls'

    Politely Verbose

    alias Please_list_all_the_files_in_this_folder='ls'

    Whimsical

    alias hunt='ls && [ $[$RANDOM % 12] == 0 ] && echo "I smell a Wumpus"'
  • Mie (unregistered) in reply to jay
    jay:
    Mason Wheeler:
    g:
    mike5:
    Not like (hours = timeInSecods / 3600 ), and minutes = (timeInSeconds % 3600 ) / 60 and seconds = (timeInSeconds % 60) ?
    hours = Math.floor(timeInSeconds / 3600);
    minutes = Math.floor((timeInSeconds % 3600) / 60);
    
    Division in javascript results in floats

    Division in any sane language results in floats. (Or fractions, if your language does that.) It's simple mathematics. If you can say 5/2 and get 2 as a result, there's something wrong with your language.

    Right, because who could possibly imagine a real-world problem in which an answer involving a fraction is not valid? Like, we have 5 people in our department and 2 offices. How many should we put in each office? Funny how last time we had this problem, the productivity of the guy we cut in half really fell off, and there was an unexplainable dip in the morale of the other four.

    Hmmm...but it seems two is not the right answer either - that is, unless you lay off anyone who doesn't fit in an office.

  • sr (unregistered) in reply to Mason Wheeler
    Mason Wheeler:
    urza9814:
    Mason Wheeler:
    g:
    mike5:
    Not like (hours = timeInSecods / 3600 ), and minutes = (timeInSeconds % 3600 ) / 60 and seconds = (timeInSeconds % 60) ?
    hours = Math.floor(timeInSeconds / 3600);
    minutes = Math.floor((timeInSeconds % 3600) / 60);
    
    Division in javascript results in floats

    Division in any sane language results in floats. (Or fractions, if your language does that.) It's simple mathematics. If you can say 5/2 and get 2 as a result, there's something wrong with your language.

    So you believe all statically typed languages are insane? If you do 5/2 in C, Java or pretty much any statically typed language it's going to give you 2. You've gotta explicitly cast those ints to floats if you want a float as a result.

    Not "pretty much any statically typed language." Just the C family, which is insane for many reasons, including this one.

    In Pascal, on the other hand, (which is also statically typed,) "5/2" returns 2.5; if you want a result of 2, you use the integer division operator: "5 div 2". Which is the right way to do it: division behaves as actual division, and if you want something that's not quite real division but is similar, you use a different operator.

    why is 5/2 any different to "5 div 2"? Both / and div are arbitrary symbols....why should 1 be more correct than the other?

  • PseudoBovine (unregistered) in reply to PedanticCurmudgeon
    PedanticCurmudgeon:
    Mason Wheeler:
    If you can say 5/2 and get 2 as a result, there's something wrong with your language.
    8/10. Would cheerfully flame

    So you're giving it a zero?

    jay:
    Right, because who could possibly imagine a real-world problem in which an answer involving a fraction is not valid? Like, we have 5 people in our department and 2 offices. How many should we put in each office?

    If you have 5 people and 2 offices, and you put 5/2 (integer valued) in each office, you're still not going to be getting the correct answer. ("Well, Tom, the good news is we're not going to cut you in half. The bad news is that you've been truncated out of an office.")

  • Jimmy (unregistered) in reply to Broke my fingers on a teletype
    Broke my fingers on a teletype:
    redtetrahedron:
    ... No, thankfully. But, surely not needed now? I guess it's a matter of not changing anything you don't have to...

    That and several decade's worth of legacy programs, scripts, and software...

    Of course you can customize the shell's commands with the alias command if you feel that the defaults are too cryptic

    Original

    ls

    Shorter

    alias l='ls -lart'

    Windows Flavour

    alias dir='ls'

    Politely Verbose

    alias Please_list_all_the_files_in_this_folder='ls'

    Whimsical

    alias hunt='ls && [ $[$RANDOM % 12] == 0 ] && echo "I smell a Wumpus"'

    As well as saving fingers, I thought some of the idea was saving sapce. Back in the day when we didn't have massive hard disk, 1 character was a lot, so wasting characters having a command like "copy" when you could call it "cp" seemed a silly thing to do.

  • foo (unregistered) in reply to neminem
    neminem:
    My favorite creative misparsing of the statement "time flies like an arrow" is, "measure the timing of flies in the same way that an arrow would measure that timing", though yes, "measure the timing of flies in the same way that you would measure the timing of an arrow" is also a legitimate (if equally inappropriate semantically) parse.
    Why inappropriate? I can just see the Mythbusters doing their experiments (except they'd need to find something to blow up in the end).
  • Groucho Marx (unregistered)

    Time wounds all heels.

  • (cs) in reply to Mark Bowytz
    Mark Bowytz:
    Actually, I'm closer to an implementation of ELIZA.
    How do you feel about being closer to an implementation of ELIZA?
  • (cs) in reply to PG4
    PG4:
    Broke my fingers on a teletype:

    I take it you have never typed a significant amount of text on the teletype machines that Unix originally ran on. Slow, clumsy keyboards with giant mechanical keys that (slightly exaggerated) you had to mash with your fist to use.

    5 minutes with one of those and you will quickly realize that those commands are not "obscure for the sake of obscurity" but rather "shortened for your fingers' sake".

    So explain to me how the "biff" command got named when something else with 4 characters would have been much better.

    The program 'biff' was named after a dog that would bark at the postman. No other explanation necessary!

    p.s. Programming on an ASR33 will humble many a young programmer quite quickly!

  • Hired Mind (unregistered)

    Please forgive my ignorance here - years ago I was forced at gunpoint to modify a large Java program and swore to never touch it again - but, is there seriously no way to get the local time in seconds since the epoch (or other reference point), in JavaScript?

  • (cs) in reply to Hired Mind
    Hired Mind:
    Please forgive my ignorance here - years ago I was forced at gunpoint to modify a large Java program and swore to never touch it again - but, is there seriously no way to get the local time in seconds since the epoch (or other reference point), in JavaScript?

    Is there a way?

    var start=new Date();
    // later
    var end=new Date();
    var intervalInSeconds = (end-start)/1000;

    Is there a way that the original developer knew about? Maybe not. He also doesn't seem to know about setInterval() in place of setTimeout().

    Worse, using a 1ms timeout instead of a 1s timeout when the lowest resolution your timer needs is at the second level shows not just a lack of knowledge, but a lack of understanding.

  • TK (unregistered) in reply to sr
    sr:
    Mason Wheeler:
    Not "pretty much any statically typed language." Just the C family, which is insane for many reasons, including this one.

    In Pascal, on the other hand, (which is also statically typed,) "5/2" returns 2.5; if you want a result of 2, you use the integer division operator: "5 div 2". Which is the right way to do it: division behaves as actual division, and if you want something that's not quite real division but is similar, you use a different operator.

    why is 5/2 any different to "5 div 2"? Both / and div are arbitrary symbols....why should 1 be more correct than the other?
    It's not that one symbol is more correct than the other. The point is that they are different symbols for different operators. Use whatever symbol you want.

    I really like this change in Python 3. Rather than inheriting the approach of C like Python 2, they now treat "/" as floating point division and "//" as integer division. This makes code more reusable because the operation is the same all the time; the type of the arguments doesn't matter.

    Sure you could cast to get the same effect. But it's nice that you don't have to.

  • (cs) in reply to Kent

    "If your database is having deadlock problems, the solution is to give users 40 minutes (your mileage may vary) to submit the form?

    First of all, deadlocks arise from two (ignorantly written) updates occurring at roughly the same time. Not 40 minutes apart. "

    Deadlocks can easily come from 2 different events far from each other in time. A deadlock is not always a race condition.

    I guess that in this case, the system locked some entries in the database, from the user started his action, and until he finished his work. In that case, forcing the user to work faster would decrease the risk of deadlock, because the time the user held the problematic locks could be decreased.

    Or maybe the developer is just an idiot.

  • (cs) in reply to TK
    TK:
    I really like this change in Python 3. Rather than inheriting the approach of C like Python 2, they now treat "/" as floating point division and "//" as integer division. This makes code more reusable because the operation is the same all the time; the type of the arguments doesn't matter.

    Sure you could cast to get the same effect. But it's nice that you don't have to.

    The idea of having different symbols for different operations (division-giving-long-double versus division-giving-integers) is good. Deliberately choosing several other languages' rest-of-line comment introducer, not so much.

    Oh, and does it coerce floats to integers before or after the // division? (i.e. does 0.41 // 0.1 give 4 or a div-by-zero trap?)

  • Earlchaos (unregistered)

    That piece of crap is not even beginners code, author could've used google to search for a working version...

  • (cs) in reply to erat
    erat:
    Ardik:
    csec would've been more appropriate then.

    Well, if a vaginal birth is not compatible with the doctor's tee-off time, I guess...

    FTFY.

  • RFmich (unregistered) in reply to Steve HoldowaySteve
    Steve HoldowaySteve:
    dkf:
    letatio:
    Who the hell indents like that?
    I used to work with someone who indented like that. As far as I could work out, it was a style they learned when they started out on FORTRAN (but I don't know which version, 66 or 77)…

    It would have to be fortran 77 as that's when block ifs were introduced

    Don't need no Steeenking block ifs:

    C Assume some code above that sets I,B,C,D

      IF (I) 100,200,300
    

    100 CONTINUE A = B GOTO 400 200 CONTINUE A = C GOTO 400 300 CONTINUE A = D GOTO 400 400 CONTINUE

    C ..and more code below. The extra GOTO allows us to C insert code between it and 400 that we can C 'spaghetti into' if we want to be really perverse.

  • (cs) in reply to PseudoBovine
    PseudoBovine:
    PedanticCurmudgeon:
    Mason Wheeler:
    If you can say 5/2 and get 2 as a result, there's something wrong with your language.
    8/10. Would cheerfully flame

    So you're giving it a zero?

    That was mildly funny, but don't quit your day job.

  • TK (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    TK:
    I really like this change in Python 3. Rather than inheriting the approach of C like Python 2, they now treat "/" as floating point division and "//" as integer division. This makes code more reusable because the operation is the same all the time; the type of the arguments doesn't matter.

    Sure you could cast to get the same effect. But it's nice that you don't have to.

    The idea of having different symbols for different operations (division-giving-long-double versus division-giving-integers) is good. Deliberately choosing several other languages' rest-of-line comment introducer, not so much.

    Oh, and does it coerce floats to integers before or after the // division? (i.e. does 0.41 // 0.1 give 4 or a div-by-zero trap?)

    >>> 0.41 // 0.1 4.0

    Sure "//" isn't going to fly in languages that use it for comments, but since Python uses "#" for that, who cares?

  • Robert (unregistered)

    I guess sometimes the fix can be worse than the bug.

  • ysap (unregistered)

    Well, I think there's more to this code when examined carefully - there are a 1,000 milliseconds in a second, not a 100 !

  • QJo (unregistered) in reply to neminem
    neminem:
    TGV:
    Rodnas:
    "Time flies like an arrow, fruit flies like a banana" - G. Marx
    And of course: time flies with a stop watch (Hint: it's an imperative).
    My favorite creative misparsing of the statement "time flies like an arrow" is, "measure the timing of flies in the same way that an arrow would measure that timing", though yes, "measure the timing of flies in the same way that you would measure the timing of an arrow" is also a legitimate (if equally inappropriate semantically) parse.

    I always read it as "measure the timing (indirectly ascertaining their speed) of the flies with the alacrity of the flight of an arrow through the air" - that is, "I want you to time those flies - get a move on!"

  • Neil (unregistered) in reply to redtetrahedron
    redtetrahedron:
    Bring Back Nagesh:
    redtetrahedron:
    Code Slave:
    letatio:
    Who the hell indents like that?
    My co-worker... they could definitely benefit from a slight tap on the cranium with the clue-bat.
    At a previous job, I inherited a javascript app with 15K-line files from a fired co-worker who had a completely haphazard indenting style, enough to make the code virtually unreadable. Also - there were no semicolons ending the lines, just like this code. I convinced my supervisor to buy a code-reformatting tool, but before I could use it, I still had to add semicolons to the end of each statement before the reformatting tool would be able to parse the code. Ugh!
    Wow, you would make an excellent salesman. You managed to convince your boss to spend money on a tool that only half-works, whereas if you'd done some research, you could have got a much better tool for free.

    Eclipse (with the web developers plugins) is one such product that can format JS source code without semicolons, plus it will highlight all the places where they should be, among other potential programming problems. Heck, even jsFiddle will do it for you, plus it comes with JSLint.

    This was 11 years ago.. not sure those tools existed back then? I did look, could not find one for free at the time.
    Gecko (or Netscape 6.x, as you would have known it back then) could do it. However the feature was discontinued and Firefox 17 is no longer capable of reformatting the source.

  • Neil (unregistered) in reply to g
    g:
    In some web-survey code I inherited I found code which measured the time people took for each question with setTimeout(function() { time += 1},1); And divided the resulting time by 100 to get the number of seconds, I guess they used 100 just to get the values to "look" right.
    Did you mean setInterval (or some sort of fake interval created by setting a timeout in the timeout handler)?

    By the way, Firefox has a preference for the minimum interval, so you can make survey time pass more slowly. (Or just switch tabs, as the default for background tabs is higher.) The preference also applies to self-resetting timeouts, although obviously the first one is unaffected. Before that preference existed, there was a 10ms minimum on timeouts and intervals.

  • ab (unregistered) in reply to jay
    jay:
    At my last job, my boss established a company standard that we were NOT ALLOWED to change indenting of existing lines of code. So if, for example, you added an IF statement that encompassed an existing block of code, you couldn't move those lines to the right to line up under the IF. The stated reason for this was that when we committed code to the library, this would make those lines look changed when they really weren't.
    Assuming your boss couldn't learn how to type "-b", the right solution was to check in some helper tool written in Python or Haskell or some other language where indentation is significant. Once someone needed to, e.g., add a conditional somewhere in that tool, your boss would be unmasked as a 1960s robot as he shouted "does not compute" until his head exploded.
  • ab (unregistered) in reply to Mason Wheeler
    Mason Wheeler:
    In Pascal, on the other hand, (which is also statically typed,) "5/2" returns 2.5; if you want a result of 2, you use the integer division operator: "5 div 2". Which is the right way to do it: division behaves as actual division, and if you want something that's not quite real division but is similar, you use a different operator.
    Complaining that "5/2 == 2" is wrong because that's not how the division operator works in grade-school math is like complaining that "for (i =0; i != 10; ++i) {}; i == 10;" is wrong because that's not what the word "each" means in English. There is no mathematical division operator there. Have you ever seen "5 divided by 2" spelled as "5/2" in any context except programming? That's not how division is written. (Of course it is how you write a fraction in some contexts, but in that case, it's the fraction "5/2", not an expression to be evaluated as 2, or 2.5, or anything else.)

    Since "5/2 == 2" is clearly a programming expression, not a mathematical expression, it only makes sense if you understand what language it's written in. In most C-family languages, it's true. In, say, Python 3, it's false. Neither one of those is "right" outside of context.

    The right answer, of course, is to use Applescript (or Hypercard), where you write "5 ÷ 2", just as you did in grade school, and by the time you've figured out how to type the "÷" on a keyboard with no such symbol, you no longer care what the answer was.

  • ab (unregistered) in reply to Hired Mind
    Hired Mind:
    Please forgive my ignorance here - years ago I was forced at gunpoint to modify a large Java program and swore to never touch it again - but, is there seriously no way to get the local time in seconds since the epoch (or other reference point), in JavaScript?
    Given that Java and JavaScript are completely different and unrelated languages, it looks like Netscape's marketing ploy 17 years ago paid off by making sure people like you never learned their language. After all, who wants programmers who understand, admit, and ask for forgiveness of ignorance while asking simple questions, when you can attract programmers who are absolutely sure that the one tool they know how to use must be the right one?
  • Anone (unregistered) in reply to ab
    ab:
    Have you ever seen "5 divided by 2" spelled as "5/2" in any context except programming? That's not how division is written.

    That's how pretty much everyone wrote division that I'm aware of in high school and university.

    a la

    e/m = c²

    or

    e

    • = c² m

    Why would you ever use the basic division symbol when it takes up more room and takes longer to write out? Especially since it's just a pictograph for the slash version anyway, with the dots representing the numerator/denominator.

  • Samwise (unregistered)

    Lets make time fly even faster:

    	var sec = 0, min = 40;
    	var interval = setInterval(function(){
    		if(min==5 && sec == 0){ alert("Save yo content, foo!");}
    		if (sec == 0){min--;sec = 59;}
    		if (min < 0){ min = 0; sec = 0; clearTimeout(interval);}
    		var fnPad = function(v){ v=v.toString(); while(v.length<2){v = "0" + v;} return v;};
    		self.status=min + ":" + fnPad(sec--);
    	}, 100);
    

Leave a comment on “Time Flies”

Log In or post as a guest

Replying to comment #:

« Return to Article