Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 31
  1. #16
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,480
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Quote Originally Posted by Philip M View Post
    The first floppy disks were (I think) 160K capacity.
    I have an eight inch floppy disk on my shelf - it has I think a 5k capacity. I never have had an 8 inch floppy drive to check it.

    The 160k capacity disks didn't come along until after computers that didn't take up a whole room came along and they reduced the disk size from 8 to 5-1/4 inches. The first computer I worked with that used floppy disks was the first Apple ][ bought into Australia by the University of NSW and those disks were the 5-1/4 160k variety. Until the floppy drives became available we were saving to cassette tape.

    I still have four working 5-1/4 drives with one still fitted in a computer along with a thousand or so 5-1/4 floppy disks.

    Then of course there's the 3-1/2 drives with the 720k and 1.44Mb floppy disks they used, the zip drive and a number of 100Mb disks it uses (don't think they are floppy though) as well as a 512Mb tape drive still fitted in one of my computers and a pile of cartridge tapes.

    Youngsters these days don't appear to know anything about trying to save on memory use so that you don't run out. In the early days even saving two bytes by leaving the century off dates generated a huge saving in memory and increased processing speed by a large amount. The savings from not storing those two bytes for several years was many hundreds of times what it cost to add the two bytes back in when memory allowed it and the dates required it.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  2. #17
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,734
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by felgall View Post
    The first computer I worked with that used floppy disks was the first Apple ][ bought into Australia by the University of NSW and those disks were the 5-1/4 160k variety. Until the floppy drives became available we were saving to cassette tape.
    Stephen - that is a damning admission about your age. Your photo makes you look a lot younger - not a day over 35! The first micro-computer I used (and owned) which had a floppy disk was Superbrain (actually two floppy disks), but before that the Ventek machines we used at British Rail in the mid-1970s used cassette tapes. I recall that it took about an hour to change a single byte of code and re-compile!

    Superbrain had 64K RAM. (Luxury - most others at the time had only 32k). I wrote programs which used overlays and the BASIC "chain" command to run bigger applications.

    I also recall the first hard disk drive appearing - it was 5 megbytes. When I got a 32mb Hardcard c.1984 I thought that I would never need a bigger one. As Bill Gates said in 1981, "640K ought to be enough for anybody."

    But it is fair to say that those days are one with Nineveh and Tyre, and there is in most situations little merit in going through contortions to save a few bytes or a few milliseconds. At least in the sort of applications I am involved with nowadays.

    Yes, you are right, I meant 5-1/4-inch floppies as used in micro-computers. As you say, the early 8-inch ones stored only 5K. I remember being shown one by an IBM rep in 1971, and thought "Hmm. That will never take off. 5K is not nearly enough for practical use!".

    Don't forget that a major problem with 5-1/4 inch disks was competing floppy disk formats, with hard and soft sector versions and various different encoding schemes. British Rail invested heavily in a machine called a Sirius, which could read only its own disks which were formatted in some proprietary way. So BR was unable to switch to IBM PCs.

    This thread seems to have wandered a long way from JavaScript Syntax and the ; . Infractions all round?
    Last edited by Philip M; 02-22-2013 at 09:23 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  3. #18
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,480
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Quote Originally Posted by Philip M View Post
    Stephen - that is a damning admission about your age. Your photo makes you look a lot younger - not a day over 35!
    The university brought the Apple computers into Australia in 1979 in order to run a class using them the following year. I was one of five students lucky enough to get to test out the project they intended to use in the class. The first Computerland store selling Apple computers in Australia opened the following year just down the road from where i had got a job operating a Facom 230-15 computer (which used tapes and 5Mb hard drives).

    The photo was taken a few years ago but even then I was a bit older than 35.

    I actually learnt programming the hard way - without any access to a computer I taught myself to program in Fortran. Got to actually use it once I got to university where the programs had to be written as lines on optical cards and if the card reader could read your program and not make any mistakes then a few minutes later you'd get the printed output from the printer next to the reader. The IBM mainframe computer was in a separate room where students were not allowed. I can remember a 15 card program that I had to feed through 20 times before it read everything properly and actually ran the program It managed to produce 20 different errors by misreading different characters in a program that was only about 300 characters long (that's a 0.0003Mb program for any youngsters reading this).
    Last edited by felgall; 02-22-2013 at 09:32 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  4. #19
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,734
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Ever use a Hollerith/IBM punched card machine?

    Remember how the cards were sorted with a needle poked through one of the holes?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  5. #20
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,190
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by felgall View Post
    With my code the assumption is that the browser doesn't change. It gets tested ONCE and once only when the function is called the first time. If my code adds 1000 different functions to 1000 different events it still only tests what browser it is once. Now I personally have never seen a browser suddenly change into a different browser mid script so I can't see any point in testing for if the browser has changed every time you do something that different browsers handle differently. Obviously you haver come across such browsers since your code is written to assume that while the browser might be IE8 while adding the first function to the first event that the person might have managed to upgrade their browser to Chrome by the time you add the second function to the second event.

    Given that the addEventListener code only needs a single statement your code is running twice as many statements as mine for every call to the function from most browsers.

    So instead of making your code 500% more complex you have instead halved the efficiency of the code by doubling the number of statements that need to be run. That's even worse than using a lot more code as the small amount of extra code you added gets run lots of times instead of once.
    firstly, let me make clear that we are debating style, not right vs wrong.
    As you say, my first code indeed does sniff each added event. I coded it from your example and fixed what were strong reservations i had about its operation.

    i don't like to clobber live variables, musical chairs is fine for kids, but not coding. I like to preserve function purity as much as possible, and your function violates that. that's a philosophical minor point. More important to me, the placement flexibility of function statements alone is a big enough boon to library development that i prefer it. Otherwise, i have to make sure all my depends come before the invocation. Once i build the pyramid up a few levels, this can get hard to keep track of.

    that aside, there are some edge-case issues with the code you presented as well. If i incorporate addEvent into, say, a module loader, and i point at it before it runs, it indeed sniffs each time:

    Code:
    addEvent = function(ob, type, fn ) {
    if (window.addEventListener){
     alert('sniffing');
    addEvent = function(ob, type, fn ) {
      ob.addEventListener(type, fn, false );
    };
    }else if (document.attachEvent)
    addEvent = function(ob, type, fn ) {
      var eProp = type + fn;
      ob['e'+eProp] = fn;
      ob[eProp] = function(){ob['e'+eProp]( window.event );};
      ob.attachEvent( 'on'+type, ob[eProp]);
    };
    addEvent(ob, type, fn );
    }
    var evt=addEvent;
    evt(document.body, "dblclick", String);
    evt(document.body, "dblclick", String);
    evt(document.body, "dblclick", String);
    which in chrome, alerts 'sniffing' each time.

    also, since you have addEvent coded as an implicit global, i must ensure that my module both appears in source after the addEvent code, and that the module loader is not invoked until addEvent is called at least once. That's a couple of fairly heavy restrictions that need not be present.


    if i break my own practice of not clobbering existing variables, i can indeed make the first function i posted sniff only once with a tiny modification:

    Code:
    function addEvent(ob, type, fn) {
    
    	addEvent= (document.attachEvent ? addEventIE : addEventW3);
            addEvent(ob, type, fn);
    
    	function addEventW3(ob, type, fn) {
    		ob.addEventListener(type, fn, false);
    	}; /* end addEventW3 */
    
    	function addEventIE(ob, type, fn) {
    		var eProp = type + fn;
    		ob['e' + eProp] = fn;
    		ob[eProp] = function IEEventHandler() {
    			ob['e' + eProp](window.event);
    		};
    		ob.attachEvent('on' + type, ob[eProp]);
    	}; /* end addEventIE() */
    
    } /* end addEvent() */
    this uses ALL function statements, still provides the efficiency you tout so vehemently, all WITHOUT bloat, extra sniffing, late-reassignments, implicit globals, or hard-to-debug anon functions.


    this again doesn't solve all the reservations i have about live-reassignment, and the module loader is still broken, but it does work at least as well as the code you provided.


    in conclusion, your statement "a function statement equivalent to that simple function expression that I use in almost all of my scripts" seems to be falsified by the all-statement version above, unless you can find something wrong with that as well, in which case i'm sure we'll hear about it.
    Last edited by rnd me; 02-22-2013 at 05:00 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  6. #21
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Oh wow, I just now saw this because I was bored and read through the thread:

    Quote Originally Posted by Philip M View Post
    Young Turks like Airblader have no notion of the days of such primitive computing. He probably thinks of us as old farts. But in truth we are sadly no longer young enough to know everything.
    True, I never had these "problems" myself, but I am quite aware of them and back in those days it would've been bad practice to waste space. You're saying you are too old to know everything, but you do know about code indentation you're simply used to not doing it. And it's hard to get rid of a habit that you had for so long, especially if you don't see the value. You probably do see why indentation is good, but what I mean is the value for yourself you do fine without it, so it's not worth the trouble for you.

    I have respect for everyone who has been in this business this long. Just a few weeks ago I read about a study that software developers are typically only highly profitable for companies for a few years before they simply run "out of date" with current technology and standards.

    While the bracket debate to me clearly is a question of taste, code indentation to me isn't. It's nothing but an old habit, as you openly admit, that has no value anymore these days and actually "hurts". To put it more directly: If I refused to indent code (and assuming I wouldn't let my IDE do that for me), I would lose my job so fast that I couldn't even close Eclipse. And that besides our company's amazingly low leave rate of less than four people per year. I said this before, but we have much, much stricter rules than that. A quite general one is the pathfinder rule: If you touch code, leave it cleaner than you found it. Which means refactoring if needed or so much as removing a stupid comment.

    All this of course doesn't matter too much if you work alone. It's natural to run out of sync with current standards just like it first takes time to get into sync with them. I see myself still in the learning phase (I've been programming for roughly 12 years, but just recently started doing it professionally), but eventually I too will find myself doing things that are considered bad practice.

    Eventually we all get garbage collected.

  7. #22
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,734
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Airblader View Post
    To put it more directly: If I refused to indent code (and assuming I wouldn't let my IDE do that for me), I would lose my job so fast that I couldn't even close Eclipse.
    And if as a junior staff member I had told a senior person in my organisation that he was "lazy", I would have lost my job so fast that my feet would not have touched the floor.

    Kindly stop your whinging - you may do what you want, or what your employers want, but I will work my way. I have explained that I am not answerable to anyone - least of all to you. If you don't like the way I code, go and play somewhere else.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  8. #23
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Hence I said

    Quote Originally Posted by Airblader View Post
    All this of course doesn't matter too much if you work alone

  9. #24
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,480
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Quote Originally Posted by Philip M View Post
    Ever use a Hollerith/IBM punched card machine?
    Yes.

    I had been programming for a few years before we got actual terminals attached to the mainframe. Most of the work was writing out the code on coding sheets and sending it out to be punched onto cards but we did have one card machine so we could put together jobs to make small corrections to our code.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  10. #25
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    The original original floppy disks were indeed 8" disks. And they were used to store the MICROCODE (call it CPU boot code if you will) for IBM 360 computers. That is, the 360 computes (except for the 360/75) were microcoded machines: They had a very primitive instruction set built into the hardware and then the instructions that USERS saw were actually executed by a second level that read a user instruction and translated it into the "micro" instructions of the hardware.

    The disks were formatted at the factory, ahead of time, and they had 77 tracks, each with 26 sectors, and each sector with 128 bytes. So their capacity was 256,256 bytes (not quite 256KB). Larger than the first 5.25" floppy disks as were used on the Apple II.

    The most advanced 8" floppies I ever owned was a dual-disk system, where each disk was double-density and double-sided. Still using the 77 tracks, bot formatted with 32 sectors of 256 bytes each, per track. And double-sided meant they stored 1,261,568 bytes per disk. Or about 2.2MB on the two disks. The heads were mounted on a "voice coil" mechanism (rather then the stepping motors used in cheaper drives, including all 5.25" drives) so performance was close to that of the early "winchester" hard disk drives, except for capacity. We actually ran a 3 user time sharing system on that beast.

    Did you know that Apple DOS--first disk operating system for the Apple II--was designed to accommodate disk sizes up to 16MB? But that Apple never chose to "flip the switches" that would have allowed the production version to do so? I know this because Paul Laughton (the author of virtually all of Apple DOS) and I and a couple of other people all worked for the same small consulting company (Shepardson Microsystems) that contracted with Apple to create the DOS.

    Look here:
    http://laughton.com/Apple/Apple.html

    And this is fun (there's a link on that page to it, also):
    http://laughton.com/Apple/contract.gif

    Yeah, that's the entire contract for Apple DOS. Nothing left out.
    Last edited by Old Pedant; 02-22-2013 at 07:26 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  11. #26
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Oh, and speaking of card punches: Apple DOS was written ON A CARD PUNCH! (As was virtually all the software we were creating at the time.) Shepardson had written a generalized assembly language assembler for the National IMP-16 (look that up) and adapted it for a variety of other CPUs, including the 6502. So we would write our assembly language code on coding sheets and Kate Shepardson (Bob's wife) would then punch out cards with our code and we would run the cards into a card reader on the IMP-16. The output of the assembler was a PAPER TAPE with the machine code. In the case of the Apple II, we had Woz (Steve Wozniak) create a plug-in board for our machine with a parallel interface that would then read the paper tape into memory.

    Talk about the long way around.

    We did essentially the same thing producing Atari BASIC and Atari's EASMD (Editor-Assembler-Debugger), but in that case we used the paper tape to burn EProms (since both those languages were delivered to Atari's customer on ROM).

    Then there was the C compiler ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  12. #27
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,480
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Quote Originally Posted by rnd me View Post
    firstly, let me make clear that we are debating style, not right vs wrong.
    Agreed.

    Quote Originally Posted by rnd me View Post
    i don't like to clobber live variables, musical chairs is fine for kids, but not coding. I like to preserve function purity as much as possible, and your function violates that.
    No it doesn't. Once you move away from procedural languages to using object oriented programming concepts such as polymorphism mean that the same name can refer to different things depending on the context. This is just an example of that since addEvent is simply an object which does one thing in one browser and a different thing in a different browser.

    Quote Originally Posted by rnd me View Post
    More important to me, the placement flexibility of function statements alone is a big enough boon to library development that i prefer it. Otherwise, i have to make sure all my depends come before the invocation. Once i build the pyramid up a few levels, this can get hard to keep track of.
    All the code I write for a script is wrapped inside an anonymous function. Where I am producing scripts for others to use where they might use one or perhaps more scripts that need that code in various pages the addEvent is defined inside of that anonymous function so that it is limited to that function. In cases where I use it outside of the individual scripts it is a method of the object I created that handles events - it is never defined as a global function.

    Quote Originally Posted by rnd me View Post
    that aside, there are some edge-case issues with the code you presented as well. If i incorporate addEvent into, say, a module loader, and i point at it before it runs, it indeed sniffs each time:
    The code you posted creates a closure pointing to the original value of the function rather than to the current value. While I agree that such code has the result you say I have no reason for doing that - if I wanted the function to have a shorter name I'd simply change the original variable.

    Quote Originally Posted by rnd me View Post
    also, since you have addEvent coded as an implicit global,
    only in the sample code I posted here. As I mentioned above in actual use that code either goes at the start of an anonymous function where it is then only available for use in the function OR I use the object I attached it to if I need to use it in multiple scripts in my own page (most of the scripts I write are designed to simply plug into the pages of people with no JavaScript knowledge whatever).

    Quote Originally Posted by rnd me View Post
    if i break my own practice of not clobbering existing variables, i can indeed make the first function i posted sniff only once with a tiny modification:
    Agreed. That version does come close to mine using function statements. Effectively it is the same code as mine but instead of using anonymous functions for the two alternatives you have given them names. Your code still includes a function expression though in order to assign whichever of those two named functions to be called in place of the outer one.

    Code:
    addEvent= (document.attachEvent ? addEventIE : addEventW3);
    So my version uses three function expressions and your closest equivalent uses three function statements and a function expression. So you haven't really refuted my comment about the difficulty of setting up code that tests once as to which version of the code to run without using function expressions.

    Just as an aside: do you really test for attachEvent first and use that in IE9 rather than allowing IE9 to use addEventListener (given that the browser supports both)?
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  13. #28
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Talk about a set of far-ranging topics generated from a simple question...

    But anyway...
    do you really test for attachEvent first and use that in IE9 rather than allowing IE9 to use addEventListener (given that the browser supports both)?
    You know, Felgall, I noticed that anomaly, too, and was surprised by it.

    It's akin to all the AJAX code that I see that tests for ActiveXObject first instead of second.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  14. #29
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Once you move away from procedural languages to using object oriented programming concepts such as polymorphism mean that the same name can refer to different things depending on the context.
    Heh! And even the same operator can mean different things depending on context! I remember writing C++ code and overloading operators for things like matrix multiplication, and worse. Or, better, creating "persistent objects" so that even the pointer operator implied the possibility that data would be fetched from disk. It's funny, but that was never confusing because, in a strongly typed language, it's obvious from the context what the meaning must be. Just one of the advantages of strong typing.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  15. #30
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,480
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Quote Originally Posted by Old Pedant View Post
    It's akin to all the AJAX code that I see that tests for ActiveXObject first instead of second.
    At least there's the possibility that the code dates from back when XMLHttpRequest was first introduced and most people were still using IE4 and IE5 so that almost everyone whose browser supported Ajax supported it via ActiveXObject. Back then it would have been reasonable to code it that way around.

    Since both addEventListener and attachEvent were added at about the same time and more people were upgrading to IE5 than were switching to other browsers it probably would have made sense back then to have tested for attachEvent first.

    The time to reverse the test around the other way would probably have been somewhere between the release of Firefox 1.0 and the release of Chrome 1.0. I guess some people are just a bit slow updating old code that still works but five to eight years does seem a rather long time to get around to making such a simple change. Certainly any code written since 2005 ought to be testing for the JavaScript version first and the JScript version second.
    Last edited by felgall; 02-22-2013 at 08:51 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


 
Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •