• Chris Ovenden (unregistered) in reply to Phleabo

    That has to be the longest HTML tag ever written!

  • (cs) in reply to Pez
    Pez:
    There should also be a server side failback so users who have Javascript turned off still get the same functionality. Helps usability and security no end. Personally, I wouldn't bother with Javascript validation and just do it on the server

    Indeed, only server-side validation can be trusted. The client-side validation is there purely as a convenience to the user, and to save a client/server roundtrip for innocent mistakes.

  • (cs) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods? Especially since he already is calling methods in the onclick code. Javascript ain't ASP.NET, buddy. There's no separation of code/presentation unless YOU make it happen.

    I'm guessing this is the result of a lazy programmer. "Eh, I wrote it and it works, so I never need to touch it again unless something is wrong."

    I've been staring at this all day, and it still makes no sense.

    Where, exactly, is this "separation of code/presentation" of which you speak?

    Which bit is the code? Which bit is the presentation? Where is Waldo?

    I'm looking forwards to being yelled at, and probably for good reason, but most of the complaints I'm reading don't seem to be about "bad code" or "bad practice;" they seem to be more on the level of religious fundamentalism. You have to do this, you have to do that, you have to wash your feet aftwerwards, and make sure you don't say "See you next Wednesday." (Oops, sorry, that last bit is movie fundamentalism.)

    Seriously. Most of this stuff is irrelevant syntactic sugar. You want a proper language, go get a proper language. (Lisp, Scala, Python, Cobol, Algol68 ...) Don't try the superior Conehead on with the rest of us, who have to actually deal on a day-to-day basis with the mess that is the Web.

    Damn. Missed PHP4 out in that list, there. Can't quite remember why.

  • Josh (unregistered) in reply to Vollhorst

    Why do don't you know grammar?

  • Ambrose (unregistered)

    This code definitely doesn't work at all. The attribute is enclosed by double quotes and it would die at

    var day = ""

    with a syntax error.

    Please note as well that not all browsers will allow line breaks inside attributes.

  • Petey (unregistered) in reply to Vollhorst

    Those aren't bit operators! Those are logical operators.

    Bit operators are & and | (only one).

  • blirp (unregistered) in reply to Vollhorst
    Vollhorst:
    All this silly indentation...
    if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) && 
    validate(form.res_MM, "",form.res_YYYY) &&
    validate(form.res_MM_end, "", form.res_YYYY_end)){
    

    Why do so many programmers don't know bit operators?

    Because that's a f*ing pain to debug. And no known debugger allows me to step into just one of those calls.

    M.

  • Watson (unregistered) in reply to Petey

    Congratulations! You are the <insert appropriate ordinal I can't be bothered determining here> person to make this observation. First place of course went to the person who originally mentioned bit operators, who used the obvious unfair advantage of getting to read it before the rest of us and made the correction in less than two minutes. Still, your contribution has been noted.

  • Watson (unregistered) in reply to Barf 4 eva
    Barf 4 eva:
    Zylon:
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods?
    I believe you mean "functions", not "methods".

    heh, methods or functions? :P Sounds like a meaningless and improper OR statement to me, but then again... Perhaps this is a point clarified specifically within javascript? I don't do JavaScript... buuuuut..

    It's pretty much a distinction without a difference. Especially in Javascript, where "functions" are objects in their own right and just as likely to be anonymous lumps of code passed around, and <script>function foo(){...}</script> makes foo() a method of the window object anyway.
  • zbigg (unregistered) in reply to Vollhorst

    Well ... It think they know about bit-operator.

    Unfortunately most of "debugging" tools are unable to show results of intermediate calculations (calls to validate in this case) In this case it means that without stepping into specific functions you don't know which returned what. So those are in fact "debug by printf leftovers", it's my bet.

    I believe that in some somewhere after xxxflag = something() there is rarely blinking 'alert("dateflag = " + dateflag)' which is currently invisible but appears each time developer tries to debug this part of code.

    (Not that i like it. I'm trying to understand).

    Aha it's also "single point of exit" believer i think, but it's his problem.

  • MaryMary (unregistered) in reply to Vollhorst

    "Why do so many programmers don't know bit operators?"

    FYI:

    '&&', '||', '!=' etc are -logical- operators. '&', '|', '~', '<<', '>>' etc are -bitwise- operators.

  • Rhialto (unregistered) in reply to mabinogi
    mabinogi:
    In that example, method is the name people give to member functions of a class when they want to sound like they know Object Oriented programing, but don't know it well enough to call them messages.
    I never liked the name "message". It is very confusing if you are already aware of the (much older) message passing style of programming. Typically messages are sent between threads/processes. Since objects (in OO sense) do not all have their own thread, "messages" are meaningless.
  • (cs)

    The real WTF (c'mon, let me use this phrase... it's the fi(r)st time I ever used it here!) is that you don't even need to disable javascript to bypass the validation.

    Pressing the Enter key on one of the textfields in the form will also submit the form, and it won't trigger the onclick event. That's why you need validation in the onsubmit event of the form (as well as serverside ofcourse).

  • Cloak (unregistered) in reply to mabinogi
    mabinogi:
    Zylon:
    Barf 4 eva:
    heh, methods or functions? :P Sounds like a meaningless and improper OR statement to me, but then again... Perhaps this is a point clarified specifically within javascript? I don't do JavaScript... buuuuut..
    Function verb(object);

    Method object.verb();

    An oversimplification to be sure, but it gets to the heart of the distinction. And Javascript does support both approaches.

    That's a pretty meaningless distinction.

    In that example, method is the name people give to member functions of a class when they want to sound like they know Object Oriented programing, but don't know it well enough to call them messages.

    A method or message is a function that is designed to operate on or expose the internal state of an object.

    It's entirely possible to have verb(object) functions that are actually methods - particularly in non natively object oriented languages, and it's also equally possible (but not necessarily good design) to have object.verb() functions that are just functions, and do nothing with the state of the object they're bound to.

    I actually prefer what Barf 4 eva said in 172407 in reply to 172398

    At least in VB and Delphi (and more) a function returns something whereas a procedure (or method, who cares?) does not. Not more, not less. Surely, has nothing to do with internal states of objects (hey functions and procedures existed already in BASIC, so for sure that has nothing to do with objects) and all that crap. You can write a function that returns nothing and you can write procedures or methodz that return something by modifying the parameters which were used to execute the method or proc. That's all. It's just a way of saying it but fundamentally they are the same (at least in the way you use them).

  • MA (unregistered) in reply to Vollhorst
    Vollhorst:
    [code] Why do so many programmers don't know bit operators?

    And why do so many programmers dont know gramar?

  • Deniz Dizman (unregistered)

    those double quotes in the code will break the code any way. This piece of code should even execute.

  • (cs) in reply to MA
    MA:
    And why do so many programmers dont know gramar?

    "gramar"? I suppose it makes a change from "grammer" :)

  • Dingbat (unregistered) in reply to Vollhorst

    Why do so many programmers don't know bit operators? About the same as don't know their bitwise from their Booleans

  • (cs) in reply to Barf 4 eva
    Barf 4 eva:
    I always believed a method to be a generalization of EITHER a procedure OR a function, where method is more inclusive, in which case, a function is a method.

    When I last checked, 'subroutine' was the generalization of 'procedure' and 'function', and 'method' was a fancy name for a member subroutine. Of course, in many languages the term 'procedure' is unused in favor of 'function' (AFAIK, this includes JavaScript), so in them the point is moot. (Oh, and in C++ a method is specifically a virtual member function, and every language is free to redefine the terms on their whim.)

  • Barf 4 eva (unregistered) in reply to Spectre
    Spectre:
    Barf 4 eva:
    I always believed a method to be a generalization of EITHER a procedure OR a function, where method is more inclusive, in which case, a function is a method.

    (Oh, and in C++ a method is specifically a virtual member function, and every language is free to redefine the terms on their whim.)

    LOL! I think you nailed it. :)

    I was curious after reading the rest of the responses regarding the meaning of the terminology, and ended up just getting myself lost more than I was originally! I even ended up getting a load of different definitions from what I'd consider reliable sources... In the end, I decided I should get back to work!

    For now, I'll stick with the definitions I've had in the past, which of course are subject to change dependent on the change in language used. :P

  • bb (unregistered) in reply to Vollhorst
    Vollhorst:
    [code]if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) && 
    validate(form.res_MM, "",form.res_YYYY) &&
    validate(form.res_MM_end, "", form.res_YYYY_end)){
    

    Why do so many programmers don't know bit operators?

    Maybe because it's not a bit operator, logical eh? :)

  • Matt (unregistered) in reply to Vollhorst
    Vollhorst:
    Why do so many programmers don't know bit operators?

    Umm... what has this got to do with bit operators? Your answer above uses logical operators. I don't know about JS but in most languages the bitwise and logical operators are different.

    -Matt

  • Stryc9 (unregistered) in reply to Vollhorst
    Vollhorst:

    Why do so many programmers don't know bit operators?

    Me fail English? That's unpossible!!

  • (cs) in reply to Deniz Dizman
    Deniz Dizman:
    those double quotes in the code will break the code any way. This piece of code should even execute.
    Those.

    "shouldn't."

    And why not? Adherence to W3C seems, to me, to be patchy at best. Good luck to anybody trying to formulate the next great Silver Bullet based on ECMA4.

    There is also the possibility of pasting it into a Web page and checking it out. Maybe it executes; maybe not? How would you know if you haven't tried it?

    We are basically living and working in a swamp of ill-defined "standards." Test it, test it, test it once more, release it, and rely on customers to complain.

    Spectre:
    Barf 4 eva:
    I always believed a method to be a generalization of EITHER a procedure OR a function, where method is more inclusive, in which case, a function is a method.

    (Oh, and in C++ a method is specifically a virtual member function, and every language is free to redefine the terms on their whim.)

    Do either of you actually program in C++? If so, please stop, right now. VB.Net is the way to go.

    You're arguing over terminology. If you can't even get that right, then god help you when you have to deal with Liskov substitution, template template parameters, RAII ... to name but a few.

    C++ gets a bad rep because 98% of "C++" programmers should be doing something else, like hairstyles for poodles. (OK, I'll admit that C++ has other issues, but this is by far the most important one.)

    Exercises for the reader:

    (1) How would you distinguish between a C++ procedure and a C++ function? Does it matter? Why? (Joined-up writing gets you an asterisk after the grade. It doesn't mean anything -- just like the question -- but it will make you happy. I promise.) (2) In C++, is a "method" specifically a "virtual function"?

    I may have to go outside for a while. I believe my brain has just imploded.

    Where do you idiots get this stuff from?

  • El Dorko (unregistered) in reply to Vollhorst

    It's a habit of older programmers most likely, because if you use logical &&'s, the compilers/interpreters/parsers of olden times would evaluate all checks, whereas if you used "silly indentation" they knew to break out after the first one returns false.

    I still do that sometimes, just because of a habit. I think most modern compilers know how to handle the single-line version well enough that it shouldn't make a difference.

  • Pilum (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods? Especially since he already is calling methods in the onclick code. Javascript ain't ASP.NET, buddy. There's no separation of code/presentation unless YOU make it happen.

    I'm guessing this is the result of a lazy programmer. "Eh, I wrote it and it works, so I never need to touch it again unless something is wrong."

    This one doesn't know javascript either though. Nor the DOM.

  • Cloak (unregistered) in reply to Deniz Dizman
    Deniz Dizman:
    those double quotes in the code will break the code any way. This piece of code should even execute.

    So what? So you are executing broken code. Yuo will be my guru

  • Cloak (unregistered) in reply to Barf 4 eva
    Barf 4 eva:
    Spectre:
    Barf 4 eva:
    I always believed a method to be a generalization of EITHER a procedure OR a function, where method is more inclusive, in which case, a function is a method.

    (Oh, and in C++ a method is specifically a virtual member function, and every language is free to redefine the terms on their whim.)

    LOL! I think you nailed it. :)

    I was curious after reading the rest of the responses regarding the meaning of the terminology, and ended up just getting myself lost more than I was originally! I even ended up getting a load of different definitions from what I'd consider reliable sources... In the end, I decided I should get back to work!

    For now, I'll stick with the definitions I've had in the past, which of course are subject to change dependent on the change in language used. :P

    Maybe it's best to call them Huey, Dewey and Louie. This way there won't be confusion between subs, subprocedure, method, function, virtual member and wht-do-I-know.

  • Beerguy (unregistered)

    My own personal pet hate was this bit

    stYear.push(parseInt(form.res_YYYY.value)); // start year

    Why not just name the array startYear in the first place?????? Grrrrr.

  • pbi (unregistered) in reply to Vollhorst

    "f (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) &&

    validate(form.res_MM, "",form.res_YYYY) &&

    validate(form.res_MM_end, "", form.res_YYYY_end))"

    huh ? Hehe didnt know that '&&' was a BIT operator ;). What is a logical then ?

  • (cs) in reply to real_aardvark
    real_aardvark:
    (1) How would you distinguish between a C++ procedure and a C++ function?
    Spectre:
    Of course, in many languages the term 'procedure' is unused in favor of 'function'.
    real_aardvark:
    (2) In C++, is a "method" specifically a "virtual function"?
    The C++ Programming Language:
    A virtual member function is sometimes called a method.

    Just calm down. Duh.

  • rob (unregistered) in reply to Vollhorst

    Why do so many programmers don't know bit operators?

    cough like you?

    I think you are getting your logical and bit operators confused!

  • lrucker (unregistered)

    OK, I've only poked around at Javascript (anyone know of a good book on it? I know 16+ languages already; I don't need something that's still explaining for-loops 1/3 of the way in) but even I can see what's wrong with that.

  • bert (unregistered) in reply to El Dorko
    El Dorko:
    It's a habit of older programmers most likely, because if you use logical &&'s, the compilers/interpreters/parsers of olden times would evaluate all checks, whereas if you used "silly indentation" they knew to break out after the first one returns false. ...
    All C derived languages (C, C++, Java, C#) since K&R have explicitly defined && and || to include "short circuit" behavior. && will stop once it hits a false. || will stop once it hits a true.

    On the other hand, VisualBasic dialects (I have not confirmed this with VB.NET) tend to evaluate ALL of the operands without short circuiting. Hence, you must nest or sequence your IF statements if you do not want to run into problems.

    The following pseudo code will work fine in a C based dialect, but could barf in a VB dialect with DivisionByZero.

    example 1

     if count != 0 && sum/count > last then ...

    MUST be written in VB dialects like

    if count != 0 then
       if sum/count > last then

    example 2

    if count == 0 || sum/count > last then ...

    could NOT be written in VB dialects like

    if count == 0 OR sum/count > last then ...

    it could be written like

    match = false
    if count == 0 then
       match = true
    ELSE if sum/count > last then
       match = true
    end if
    if match then ...

    My guess is that the programmer that originated the code has some VB background.

    I still think the real WTF is that no one ever explained the truncation issue! Was the JavaScript being ignored due to the quoting issue? The story's solution would lead me to this conclusion.

  • (cs) in reply to bert
    bert:
    On the other hand, VisualBasic dialects (I have not confirmed this with VB.NET) tend to evaluate ALL of the operands without short circuiting. Hence, you must nest or sequence your IF statements if you do not want to run into problems.

    In post-.NET VB, AndAlso and OrElse are short-circuiting versions of And and Or, respectively.

  • Cloak (unregistered) in reply to bert
    bert:
    El Dorko:
    It's a habit of older programmers most likely, because if you use logical &&'s, the compilers/interpreters/parsers of olden times would evaluate all checks, whereas if you used "silly indentation" they knew to break out after the first one returns false. ...
    All C derived languages (C, C++, Java, C#) since K&R have explicitly defined && and || to include "short circuit" behavior. && will stop once it hits a false. || will stop once it hits a true.

    On the other hand, VisualBasic dialects (I have not confirmed this with VB.NET) tend to evaluate ALL of the operands without short circuiting. Hence, you must nest or sequence your IF statements if you do not want to run into problems.

    The following pseudo code will work fine in a C based dialect, but could barf in a VB dialect with DivisionByZero.

    example 1

     if count != 0 && sum/count > last then ...

    MUST be written in VB dialects like

    if count != 0 then
       if sum/count > last then

    example 2

    if count == 0 || sum/count > last then ...

    could NOT be written in VB dialects like

    if count == 0 OR sum/count > last then ...

    it could be written like

    match = false
    if count == 0 then
       match = true
    ELSE if sum/count > last then
       match = true
    end if
    if match then ...

    My guess is that the programmer that originated the code has some VB background.

    I still think the real WTF is that no one ever explained the truncation issue! Was the JavaScript being ignored due to the quoting issue? The story's solution would lead me to this conclusion.

    In VB (at least versions 5 and 6) you have by default the lazy evaluation but can configure for exact evaluation of booleans

  • apple (unregistered) in reply to Vollhorst
    Vollhorst:
    Why do so many programmers don't know bit operators?

    I have never gotten any impression that && || ! were bit operators. Seems to me they're logical operators.

  • antred (unregistered) in reply to Vollhorst
    Vollhorst:
    Why do so many programmers don't know bit operators?

    What 'bit' operators??

  • mac [unlesbar] (unregistered) in reply to Vollhorst
    Vollhorst:
    All this silly indentation...
    if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) && 
    validate(form.res_MM, "",form.res_YYYY) &&
    validate(form.res_MM_end, "", form.res_YYYY_end)){
    

    Why do so many programmers don't know bit operators?

    Since when is && a bit operation? :)

  • Zashi (unregistered) in reply to Vollhorst
    Vollhorst:
    Why do so many programmers don't know bit operators?

    I don't know. Why do so many programmers not know the difference between logical operators and bit operators?

  • On the Cheap (unregistered)

    WTF?<b>

    Why, oh why, do people comment their closing brackets?

Leave a comment on “OnClick Does What?!”

Log In or post as a guest

Replying to comment #:

« Return to Article