• oli (unregistered)

    would like to know, how parseInt() looks like :)

  • Jack (unregistered) in reply to SenTree
    SenTree:
    Sudo:
    I charge in GB pounds. The quality of my code is undefined.
    I also charge in GB pounds. My code is of sterling quality.

    This one wins the internets.

  • cappeca (unregistered) in reply to Non-consultant
    Non-consultant:
    This kind of thing is all too common from OO zealots... :S

    FTFY

  • Crash (unregistered) in reply to My Name
    My Name:
    May I present:
    Dots vs. Dots in PHP 5.3.1:
    echo "-". 1.1; // No error, output: -1.1
    echo "-". 1 . 1; // No error, output -11
    echo "-".1.1; // Error
    echo "-".1 .1; // Error
    echo "-". 1. 1; // Error
    echo "-".1. 1; // Error
    echo '

    -'. 1 .!"0". 1.-5; // No error, output: -5 echo "-". 1 .!"0". 1.-18; // No error, output: -129 echo "-". 1 .!"0". 1.-233; // No error, output: -344

    Disclaimer: I do not take any responsibility for damages caused by this code. Use at your own risk. Plea: Do not use.

    Any problems with the above code are due to ambiguity in your code, not the language. This is what gives PHP a bad name, bad programmers. If you want a negative number you should type

    $variable = -1.1;
    If you want it stored as a string:
    $variable = '-1.1';
    but there's absolutely no reason to try
    $variable = '-'.1.1;
    or half of your examples, for that matter
  • Anonymous Coder (unregistered) in reply to Refugee from another Universe

    Yes, I agree this is bad. But it happens. Far too often. I was working at a project where we had things like:

    always @(a) begin b = a; end

    always @(c) begin d = c; end

    And pages of it....

    (This is VERILOG, a hardware description language. As in the current WTF, the second function, this is just a pass through and completely redundant.)

    We were not allowed to refactor this mess in case it could break abything - ha - like there was anything to break. And this in the source code for a microprocessor in use today - be afraid.

  • (cs) in reply to My Name
    My Name:
    Pentium100:
    immibis:
    My Name:
    As for dynamic typing and auto-casting I can only quote a piece I posted here before: ...snip...
    How the hell......................??????????????? Also, generates 13 undefined variable and undefined constant messages.
    Interesting, I tried to run it on my web server and the output was
    PHP is the Answer to Life, Universe and Everything!

    Note that I neither support the statement "PHP is the Answer to Life, Universe and Everything!" nor "PHP is the root of all evil!". In my opinion, PHP can be used in a good way, and might be helpful at times, but it is by far not the best (not even script) language out there. The root of all evil, however, sits in front of the computer and/or in that person's environment. I, for example, have been given a book as a present that suggests using PHPs ability to parse variables inside of strings, e.g. $root = "bar"; $tree = "foo$root"; wherein $tree == "foobar"; would evaluate as true. I'm happy to have learned about this possibility's downsides; luckily I never even used it. So, do not always see the scripter/programmer as the only one at fault, but also his environment.

    If you think that stuff is scary, try:

    javascript:($=[$=[]][(__=!$+$)[_=-~-~-~$]+
    ({}+$)[_/_]+($$=($_=!''+$)[_/_]+$_[+$])])()[
    __[_/_]+__[_+~$]+$_[_]+$$](_/_)
    

    While I would never advocating executing random code found on the internet unless you understand what it does, in this case, if you copy and paste it to your url bar, it is the equivalent of

    javascript:alert(1);

    See this blog entry for an explanation of how it works, or the original slide which it came from at Ryan Barnett's BlackhatDC presentation " XSS Street-Fight: The Only Rule Is There Are No Rules", slide 40...

    (Links to further analysis in the comments of the blog post...)

  • Steven (unregistered) in reply to EatenByAGrue
    EatenByAGrue:

    On the flip side, in a weakly-typed language, it's far easier to reuse an algorithm for something other than its original intended purpose. It's also much easier to write unit tests, because you don't have to jump through hoops to make your mocked out test object look enough like the real thing to allow a call the the code under test using the test object.

    An example: Let's say you have some method to multiply everything in an array by 2. Simple enough, right? But in a strongly typed language, you're likely to end up with different code to do the same thing on integers, on floats, on Integer wrapper objects, on Double wrapper objects, on objects that represent an amount in US currency, or on something you hadn't even thought up that's capable of being multiplied by 2.

    You're right that the challenge in weakly-typed languages is figuring out what you actually got handed to a particular method. But it does give you a ton of flexibility.

    Or you could use generics/templates in a strongly typed language.

  • Curious George (unregistered) in reply to 4Reel
    4Reel:
    Zylon:
    4Reel:
    This explains very succinctly why dynamic typing bothers me. I'm sure there's a more graceful way to deal with it, and it's not like THIS is required, but still - having to fight with the interpreter so that it treats a value as the data-type I want defeats the point of an ultra-high level language.
    Are you dumb, or trolling? The only time you should have to "fight" to maintain the correct data type is when accepting unsanitized input or doing type coercision... which is the exact same thing you have to do with strictly-typed languages.

    How about option 3 - student? I'm still working on my bachelor's degree in Computer Science. I visit this website because I enjoy learning about software development, and I posted my opinion. If it's based on incorrect information (which is debatable - I disagree with you), I'd appreciate being corrected.

    ...but please, continue to be obnoxious - nobody should ENJOY learning.

    Don't worry about "Zylon", he hadn't taken his Zoloft yet. Notice there's no reply from him...he feels contrite now.

    As with anything, use the appropriate tool for the job. "If all you have is a hammer, every problem looks like a...".

  • (cs) in reply to Crash
    Crash:
    My Name:
    <snip>
    Any problems with the above code are due to ambiguity in your code, not the language. This is what gives PHP a bad name, bad programmers. If you want a negative number you should type
    $variable = -1.1;
    If you want it stored as a string:
    $variable = '-1.1';
    but there's absolutely no reason to try
    $variable = '-'.1.1;
    or half of your examples, for that matter
    I agree with you. But you apparently missed why I posted it at all. This example is supposed to show PHPs concatenation operator does not always mean concatenate as you said here:
    Crash:
    Sure, that would seem silly if you're used to Java but at least PHP's concatenation operator always means concatenate and its addition operator always means add. They are not interchangeable and they don't do different things depending on the operands' types.
    The same reasoning you used for the PHP examples I posted, you can use for ambiguous cases in Java.
    echo 'Result: '.1+$someVariable;
    opposed to
    System.out.println("Result: "+1+someVariable);
    Both are ambiguous.

    PHP: Expects the dot in front of a number to be a decimal point and discovers that the number in front of the decimal point is missing. It suspects you tried something else and tells you to either end the command with a semicolon or use a comma as concatenation operator in this case. While this is an extra WTF - using two different concatenation operators which are not interchangable and only valid in certain situations - it is not the point of my argument. The point is: The dot is not interpreted as concatenation operator in this case because it precedes an operand of a certain type.

    Java: Concatenates "1" to the string, and then someVariable's content. We can agree that it depends on the context whether "+" is seen as concatenation operator or not. Therefor it is ambiguous.

    In both cases you can put parenthesis around the math expression to get the math done if that is what you intended to do. It is better practice; in most cases, it is even better to use a seperate variable.

    Since my initial goal was to show that PHP's concatenation is not disambiguous, I won't get into the argument whether Java's or PHP's concatenation operator is superior. I'd probably cause religious wars with that.

  • (cs) in reply to random_garbage
    random_garbage:
    If you think that stuff is scary, try:
    javascript:($=[$=[]][(__=!$+$)[_=-~-~-~$]+
    ({}+$)[_/_]+($$=($_=!''+$)[_/_]+$_[+$])])()[
    __[_/_]+__[_+~$]+$_[_]+$$](_/_)
    

    While I would never advocating executing random code found on the internet unless you understand what it does, in this case, if you copy and paste it to your url bar, it is the equivalent of

    javascript:alert(1);

    See this blog entry for an explanation of how it works, or the original slide which it came from at Ryan Barnett's BlackhatDC presentation " XSS Street-Fight: The Only Rule Is There Are No Rules", slide 40...

    (Links to further analysis in the comments of the blog post...)

    I bow to the masters.

  • (cs) in reply to Steven
    Steven:
    EatenByAGrue:

    On the flip side, in a weakly-typed language, it's far easier to reuse an algorithm for something other than its original intended purpose. It's also much easier to write unit tests, because you don't have to jump through hoops to make your mocked out test object look enough like the real thing to allow a call the the code under test using the test object.

    An example: Let's say you have some method to multiply everything in an array by 2. Simple enough, right? But in a strongly typed language, you're likely to end up with different code to do the same thing on integers, on floats, on Integer wrapper objects, on Double wrapper objects, on objects that represent an amount in US currency, or on something you hadn't even thought up that's capable of being multiplied by 2.

    You're right that the challenge in weakly-typed languages is figuring out what you actually got handed to a particular method. But it does give you a ton of flexibility.

    Or you could use generics/templates in a strongly typed language.

    Or, even better, use a language that supports real polymorphism.

    import Data.Array.IArray
    
    doubleArrayValues :: (Num n, IArray a n, Ix i) => a i n -> a i n
    doubleArrayValues = amap (*2)
    
  • Farkisaurus (unregistered) in reply to Chris
    Chris:
    I always hate WTF's based on "omg that's a simple function". without context I have no idea if these were meant to be the equivalent of function-pointers/functors. In such a case, you might have a "foreach x in y: if is_predicate() then a() else b();" template set up somewhere, where "is_predicate(), a(), b()" are arguments. perhaps is_predicate(), a(), or b() will end up being a simple "do nothing", increment, or comparison. In that case, "DoNothing" makes a lot of sense. The code has to call a function, nothing needs to be done, so the "DoNothing" function is used.

    JavaScript supports anonymous functions for this purpose.

  • barfoos (unregistered)

    Such functions are actually very common in functional programming.

    The latter one is often called IDENTITY or just (lambda (x) x).

    So I don't see the wtf.

  • Ol' Bob (unregistered) in reply to Coyne

    Uh, lemme guess - you worked for AA back in the ol pre-Enron days..? :-)

  • Joogy (unregistered) in reply to Coyne
    Coyne:
    IncrementByOne. One function point, 1 hour: $200.

    AssignStringInToOut. Zero function points: Priceless.

    And (as people have no doubt said, given I'm late on the scene) returns exactly what it was passed...

Leave a comment on “Enterprise Incrementation”

Log In or post as a guest

Replying to comment #:

« Return to Article