Slashdot Mirror


Ask Slashdot: What Are the Strangest Features of Various Programming Languages?

itwbennett writes: Every programming language has its own unique quirks, such as weird syntax, unusual functionality or non-standard implementations -- things that can cause developers new to the language, or even seasoned pros, to scratch their heads in wonder (or throw their hands up in despair). Phil Johnson has rounded up some of the strangest — from the + operator in JavaScript to the trigraphs in C and C++ and indentation level in Python. What programming language oddities cause you the most grief?"

512 of 729 comments (clear)

  1. Powershell by Anonymous Coward · · Score: 5, Interesting

    -eq as the equality operator in Powershell is pretty odd.

    1. Re:Powershell by i+kan+reed · · Score: 1

      And bash having it is precisely why powershell has it. They wanted to capture every bash user as instantly friendly for neo-dos, and stole as many nix commands as they could. I haven't actually tried, but I have this suspicion that a fair number of bash scripts would just work in powershell.

    2. Re:Powershell by Austerity+Empowers · · Score: 1

      Per uses eq for string equality checks, making the distinction between that and == for numerics. I'm not sure that one is weird.

      Verilog has a nice one though ===, meaning two wires are in exactly equal states, including more abstract states like "don't care" or "high impedance", rather than simple == which is a logical comparison. It has no real physical meaning, it's purely for programming purposes.

    3. Re:Powershell by Anonymous Coward · · Score: 2, Informative

      I would suspect that none of them would work. While PowerShell did borrow a lot of syntax from shell batch languages and dynamic languages it is quite dissimilar to both.

    4. Re:Powershell by Jeremiah+Cornelius · · Score: 1, Troll

      This is SYNTAX, not FEATURE.

      When I think of a languages strangest feature? No doubt, it's the ear lobes. And the crinkly bits at the corners of their eyes, when they smile. :-)

      --
      "Flyin' in just a sweet place,
      Never been known to fail..."
    5. Re:Powershell by Vlad_the_Inhaler · · Score: 5, Funny

      I'm from a different generation. When I was learning things there were attempts made to make languages somewhat failsafe by avoiding ambiguity. Then I saw the C syntax.
      - if (a = b) assigns the contents of b to a and executes the code following if b <> 0. Who the hell thought that would be a good idea?
      - sizeof(string) (I may have got the name of the function wrong) returns the length of a single byte rather than the length of the entire string. Who the hell thought that would be a good idea?
      - strings terminated by a binary zero rather than their physical size. Who the hell thought that would be a good idea?

      Kids grew up with this idiocy, I program in Fortran, Cobol, even Assembler to avoid that mess. Oh, and buffer-overruns have been a serious security problem for years now. Well what a f****** surprise.

      --
      Mielipiteet omiani - Opinions personal, facts suspect.
    6. Re:Powershell by angel'o'sphere · · Score: 4, Informative

      C was designed to be a portable assembler.
      In assembly it is very common to reuse the "register flags" that get set after an assignment.
      E.g. the famous and simple strcpy function in C (a two liner plus signature) is in 68k assembly also only a two liner:

      loop:
            move.b (A0)+, (A1)+
            bne loop

      The loop runs until a zero value is moved.

      izeof(string)
      That does not return the size of a byte but the size of a pointer as a string is a pointer 'char's. Seems you missed the existence of the strlen function.

      - strings terminated by a binary zero rather than their physical size. Who the hell thought that would be a good idea?
      Well, age old argument. Basically a matter of taste or sadly a historical "evolution".
      Modern languages like Java and C# allow arbitrary long strings and store ofc the size.
      In older times we only had the Pascal world, where the first byte indicated the size of the string and the C world where a zero byte terminated the string.
      Other 'worlds' like Fortran and Cobol only had fixed sized strings and padded the end of the string with blanks.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    7. Re:Powershell by MightyMartian · · Score: 3, Informative

      Powershell is just enough like Bash to make me groan after ten minutes and ask "Why the f--- didn't they just make an integrated Bash shell?"

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    8. Re:Powershell by i.r.id10t · · Score: 2

      PHP does the same/similar, but the === checks not just the data contained but the data type since PHP uses untyped variables.

      So

      $a=$b assigns the value in $b to $a
      $a==$b returns true if the value contained is the same.
            $a="1"
            $b=1
      $a==$b returns true

      BUT... given
            $a="1"
            $b=1
      $a===$b is FALSE since one is stored as a string and the other as an integer

      Which kinda makes sense for a language that has untyped variables.....

      --
      Don't blame me, I voted for Kodos
    9. Re:Powershell by Fwipp · · Score: 1

      For assignment, not comparision.
      $ useful_var="so good"
      $ second_var ="no good"
      bash: second_var: command not found
      $ third_var= "oh no"
      bash: oh no: command not found

      It makes sense if you know how bash works, but it's definitely a gotcha to newbies.

    10. Re:Powershell by Anonymous Coward · · Score: 1

      Powershell pipes objects, not strings. Everything in powershell is an object, making it very, very, VERY different from most other shells.

      ie: if you wanted to list all files larger than a size, you'd get all files in a directory, which would return to you a list of file objects, with properties and methods like in any other language. You'd then filter by that property. Fairly different from returning the data as text and filtering it.

    11. Re:Powershell by asmkm22 · · Score: 3, Interesting

      A lot of bash and *nix stuff is in PowerShell, which I think it's the point. I remember the first time I opened a session and instinctively typed "ls" without it giving an error.

    12. Re:Powershell by Vlad_the_Inhaler · · Score: 1

      Both Fortran and Cobol allow you to pass slices of a string to a subroutine or anything else, the syntax is in each case stringvar (x:y) although the meaning of y is different. In Fortran it is (from:to) and in Cobol it is (from:bytecount).
      When I was learning we used Algol68 and - although I have not used it for a good 35 years - most other languages come up wanting when compared.

      --
      Mielipiteet omiani - Opinions personal, facts suspect.
    13. Re:Powershell by LoneTech · · Score: 3, Informative

      - sizeof(string) (I may have got the name of the function wrong) returns the length of a single byte rather than the length of the entire string.

      A number of things misleading here, which do stem from C's archaic background: Firstly, sizeof is not a function (those parenthesis are not needed and only make it confusingly resemble a function call), it is a rather special operator both in that it looks like a name and operates on types instead of values. There is no string type at all. There are two types frequently used as strings, char arrays and char pointers; only in the case of the array would sizeof return the storage size (which is larger than the string length, unless you've already encountered a buffer overflow). Otherwise you get the size of a pointer, notably also since arrays cannot be passed around but get translated into pointers. In neither case do you get the size of a character.

      Of course, the more you explain about C the less sensible it appears. ;)

    14. Re:Powershell by Jamu · · Score: 1

      strings terminated by a binary zero rather than their physical size. Who the hell thought that would be a good idea?

      One advantage to null-terminated strings is that there's typical only one format - well one for each character type at least. For length encoded strings, the format depends on the register size, and the endianness of the platform. Of course C does not enforce the use of zero-terminated strings. Not even for string literals.

      --
      Who ordered that?
    15. Re:Powershell by lister+king+of+smeg · · Score: 4, Funny

      Powershell is just enough like Bash to make me groan after ten minutes and ask "Why the f--- didn't they just make an integrated Bash shell?"

      Powershell - the ugly the bastard child of Bash and Batch.

      --
      ---Saying gnome 3 is better than windows 8 not so much a compliment as it is damning with light praise.
    16. Re:Powershell by wonkey_monkey · · Score: 2

      if (a = b) assigns the contents of b to a and executes the code following if b 0.

      It makes sense to me. The statement inside the () gets evaluated, and = is the assignment operator only (which is better than forcing it to double up as comparison operator, isn't it?). For return value, what else could it return?

      --
      systemd is Roko's Basilisk.
    17. Re:Powershell by slazzy · · Score: 1

      All equality operators and not created equal.

      --
      Website Just Down For Me? Find out
    18. Re:Powershell by Anonymous Coward · · Score: 1

      Simula FTW.

      I was required to use it in school (obviously long ago) for one assignment in a "survey of languages" course. Little was said about it, but it was instantly obvious to me that the general paradigm made a lot of sense. Of course it was 15 years into my professional career before I got to use an OO language (C++ in that case) on the job (mostly in server development).

    19. Re:Powershell by makq · · Score: 1

      Are you sure that we did not settle on UTF8 because of C, ASCII assuming legacy code and null terminated strings? With those in place, UTF8 makes sense. When stuck in a crappy situation, it may have been the best alternative?

    20. Re:Powershell by VGPowerlord · · Score: 3, Insightful

      - sizeof(string) (I may have got the name of the function wrong) returns the length of a single byte rather than the length of the entire string. Who the hell thought that would be a good idea?

      Hey, just because you don't know the language doesn't mean it's necessarily wrong. Documentation for sizeof would have told you that it's for telling you the size in bytes of datatypes on a particular system. It's often paired with malloc to allocate memory for something.

      The C specification is remarkably lax on the size of its numeric datatypes, too. To the point where eventually a bunch of bit-specific sizes were introduced because the basic versions weren't. example: uint32 is a 32-bit unsigned integer, where as uint is an unsigned integer that's 16-bits or larger depending on the platform.

      For that matter, even pointer size changes depending on systems. For instance, it's 4 bytes for 32-bit Intel systems and 8 bytes for 64-bit Intel systems.

      --
      GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
    21. Re:Powershell by itzly · · Score: 2

      - strings terminated by a binary zero rather than their physical size. Who the hell thought that would be a good idea?

      Zero termination is simpler, and more flexible. Also, it avoids having to choose the appropriate number of bytes for the size field. Besides, if you want strings with size field, it's simple enough to implement that yourself.

    22. Re:Powershell by Bacon+Bits · · Score: 5, Interesting

      Two reasons:

      1. POSIX environments have already been done on Windows, and they universally suck. SFU/Interix is shit. Cygwin is shit. MKS Toolkit is shit. MinGW/MSYS, which does a better job than any of them, is mostly shit. Even UnxUtils, which is just binaries modified for use with the actual Windows cmd shell are mostly shit. There are so many fundamental differences of philosophy that make working with a Windows system as though it were a POSIX system fundamentally untenable. You're stuck with mostly just munging text files in a binary world.

      2. Powershell is what .NET developers think Windows administrators want in a shell. That's why you're allowed to do stuff like import .NET assemblies and use essentially unmodified C# code, but there's still no native SFTP client or server.

      Powershell is about 90% of what an administrator actually wants in a shell, and it's actually not that bad. Compared to cmd.exe or VBscript it's balls out fantastic. However, an administrator shouldn't need to learn about .NET objects to be able to write a script, and they shouldn't feel like there's such a fundamental separation between what the shell can do with .NET piping and what executable programs can do. There's a very real encouragement to make everything in Powershell written in and with Powershell exclusively. Like no calling of a binary to do something unless you have no other choice. The shell and the community philosophy very much discourage that... for no real reason other than it's more difficult to get a .NET object out of a binary file and manipulate it with arbitrary .NET methods. I've seen people re-implement a command line zip program with [System.IO.Compression] instead of just using 7z.exe. Why? Just so they can use .NET objects that they never do anything with.

      Honestly I really love Powershell, but I wish the philosophy were geared more around getting shit done than getting shit done with .NET.

      --
      The road to tyranny has always been paved with claims of necessity.
    23. Re:Powershell by i+kan+reed · · Score: 1

      No, an object has the rather important distinction of carrying behaviors along with it.

    24. Re:Powershell by __aaclcg7560 · · Score: 1

      I read somewhere that Powershell came about because the Microsoft programmers didn't want to rewrite the command shell. Refactoring old spaghetti code isn't as sexy as writing new spaghetti code.

    25. Re:Powershell by rmstar · · Score: 2

      Of course, the more you explain about C the less sensible it appears. ;)

      It's funny, really.

      Quote:

      both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.

      That's what proper language design is supposed to avoid. Oh well.

    26. Re:Powershell by brokenin2 · · Score: 1

      I don't think that bash really has it.. It seems like it does, but at least on most systems I've used, that's part of the program "test".

      "Test" usually has a symlink to it under the name "[" which is actually what you're running when you type something like "if [ 5 -eq 7 ]"... Note.. the program "test" ignores any parameter of "]" making them completely optional most of the time..

      It sure looks like syntax, but I think that "[" is just like any other character in bash.. "if" is just testing the return value from the program "["..

    27. Re:Powershell by UnknownSoldier · · Score: 1

      > if (a = b) assigns the contents of b to a and executes the code following if b 0. Who the hell thought that would be a good idea?

      There are indeed times it is useful but I 100% agree, using the _same_ syntax as assignment was full retard. They should of used:

      :=

        to tell the compiler, yes, I know that I am assigning inside an if statement -- a programmer couldn't accidently use it by mistake then.

      i.e.

            if( a := b ) { // do true logic
            }

      I know one game shipped with buggy AI because somebody forgot to use two equal signs inside an if statement!

      The other part of the problem was that stupid compilers didn't warn about an assignment inside an if statement.

      The C/C++ community doesn't have a clue about standardizing compiler warnings, errors, and pragmas.

    28. Re:Powershell by david_thornley · · Score: 1

      both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.

      Really? Whoever writes that crap, please don't apply here. We write good C++ here, and enforce it with code reviews.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    29. Re: Powershell by i+kan+reed · · Score: 1

      A. Yes, thingies is a word.
      B. Most "thingies" don't bear behavior with them. A series of 1's and 0's doesn't bear any sort of self interpretation.

    30. Re:Powershell by luis_a_espinal · · Score: 1

      And bash having it is precisely why powershell has it. They wanted to capture every bash user as instantly friendly for neo-dos, and stole as many nix commands as they could. I haven't actually tried, but I have this suspicion that a fair number of bash scripts would just work in powershell.

      Oh my god, this post hurts to read. Powershell scripting is nothing like Unix shell scripting in general (and Bash scripting in particular). Completely different beasts, syntactically and semantically. It's like suggesting PL/SQL scripts would work when executed by a Python interpreter.

    31. Re:Powershell by luis_a_espinal · · Score: 1

      Two reasons:

      1. POSIX environments have already been done on Windows, and they universally suck. SFU/Interix is shit. Cygwin is shit. MKS Toolkit is shit. MinGW/MSYS, which does a better job than any of them, is mostly shit. Even UnxUtils, which is just binaries modified for use with the actual Windows cmd shell are mostly shit. There are so many fundamental differences of philosophy that make working with a Windows system as though it were a POSIX system fundamentally untenable. You're stuck with mostly just munging text files in a binary world.

      2. Powershell is what .NET developers think Windows administrators want in a shell. That's why you're allowed to do stuff like import .NET assemblies and use essentially unmodified C# code, but there's still no native SFTP client or server.

      Powershell is about 90% of what an administrator actually wants in a shell, and it's actually not that bad. Compared to cmd.exe or VBscript it's balls out fantastic. However, an administrator shouldn't need to learn about .NET objects to be able to write a script, and they shouldn't feel like there's such a fundamental separation between what the shell can do with .NET piping and what executable programs can do. There's a very real encouragement to make everything in Powershell written in and with Powershell exclusively. Like no calling of a binary to do something unless you have no other choice. The shell and the community philosophy very much discourage that... for no real reason other than it's more difficult to get a .NET object out of a binary file and manipulate it with arbitrary .NET methods. I've seen people re-implement a command line zip program with [System.IO.Compression] instead of just using 7z.exe. Why? Just so they can use .NET objects that they never do anything with.

      Honestly I really love Powershell, but I wish the philosophy were geared more around getting shit done than getting shit done with .NET.

      Powershell can get anything done for automating things on Windows, but I sure wish they had done a better job defining the syntax and the cmlets. Seriously, that is some convoluted, dirty shit going on right there. So bad that at times I've considered IronPython a better, more modular alternative (in some circumstances obviously.)

      OTH, I do like Powershell's ability to integrate with .NET. That really helps automating certain things when developing, delivering and customizing complex turn-key solutions in Windows. At least that has been my experience, and quite naturally YMMV.

    32. Re:Powershell by SecretAsianMan · · Score: 1

      As a fluent PowerShell and bash user, I would bet money that PowerShell was designed by some poor sot from the Visual Basic team after watching a 15-minute presentation on bash.

      --

      Washington, DC: It's like Hollywood for ugly people.

    33. Re:Powershell by The+MAZZTer · · Score: 1

      < and > are used for input/output redirection so they used -gt and -lt. Not sure why they didn't just use = for equals but they might have wanted to just be consistent?

    34. Re: Powershell by jader3rd · · Score: 1

      Given that most PowerShell scripting is developed against live environments it seems necessary to be very explicit that you want to do a comparison instead of an assignment. A mistake we've all made in C. = and == are just too close to each other.

    35. Re:Powershell by KingMotley · · Score: 1

      OR maybe it had it because DOS and CMD had a similar operand (EQU)

    36. Re:Powershell by BasilBrush · · Score: 1

      Hey, just because you don't know the language doesn't mean it's necessarily wrong.

      And just because you do know it doesn't make it right. Just because a language operates according to it's documentation isn't any evidence that it wasn't a bad feature idea.

      It's often paired with malloc to allocate memory for something.

      So to allocate a string you have to multiply sizeof with strlen and add 1 for the null terminator? This kind of nonsense should have been obsolete decades ago.

    37. Re:Powershell by BasilBrush · · Score: 1

      Zero termination is simpler, and more flexible.

      And far slower, more buggy and more insecure.

      Also, it avoids having to choose the appropriate number of bytes for the size field.

      Pointer sized means that you couldn't handle a longer zero terminated string in memory anyway.

      Besides, if you want strings with size field, it's simple enough to implement that yourself.

      Heck implement all the rest of a language too and you won't have to put up with C at all.

    38. Re:Powershell by Darinbob · · Score: 1

      A botched Batch of Bash.

    39. Re:Powershell by rmstar · · Score: 1

      We write good C++ here, and enforce it with code reviews.

      So you do but you don't? Very good, my friend. Very good.

    40. Re:Powershell by Darinbob · · Score: 1

      Right, trying to be fully POSIX in a broken Windows environment is really hard. But they could have had sh compatible scripting done trivially.

      The godawfulness of Powershell (hint, I don't know that much about it but get my brain into knots trying to decipher it) is that it wants to be able to script the use of libraries and APIs, whereas most command line scripting languages are all about scripting commands. That may be ok for other scripting languages which aren't intended to be used from the command line (python, ruby, etc), but for something with the word "Shell" in it, PowerShell is amazingly clumsy to use for quick off-the-cuff scripts. If it wanted to just be another scripting language not intended for interactive use, then it should not have put "shell" in the name.

      Seriously, for all the problems in Cygwin at least it works and is invaluable to getting actual stuff done on Windows in a sane way.

    41. Re:Powershell by Darinbob · · Score: 2

      I thought 'test' in Bash is built in, whereas in older shells it relied on the Unix command 'test'.

    42. Re:Powershell by chispito · · Score: 1

      Comparing PS and Bash isn't really fair. Your tolerance or affinity for either will probably equal your tolerance or affinity for the OS. If you believe in the Unix philosophy bit about flat text, you're probably not going to be impressed with PS's object orientation (though PS can do flat text just fine).

      For my part, I would love to learn bash, but my job doesn't really involve any *nix. PS came easy because I already needed a better way to work in Windows.

      --
      The Daddy casts sleep on the Baby. The Baby resists!
    43. Re:Powershell by nine-times · · Score: 4, Insightful

      You know, I kind of hated Powershell until I was forced to use it.

      I still hate it. But then I have to write a bash script, and I run across some specific problem while writing a bash script, and find myself thinking, "This would be easier in Powershell." So that's something.

      It's really not like Batch files, though. It really isn't that bad of a scripting language.

    44. Re:Powershell by nyet · · Score: 1

      if (ret = fun()) printf ("fun failed, ret=%d\n", ret);
      Now, of course most compilers warn you when you do that...

    45. Re:Powershell by NoOneInParticular · · Score: 2

      One of my favourites in C:

      int* a = ...
      2[a] = 5;

      Not sure if this is still allowed by the latest standards, but it used to work.This makes use of the fact that the bracket operator x[y] is syntactic sugar for *(x+y). So:

      a[2] = *(a + 2) = *(2 + a) = 2[a]

      Now try that somewhere else!

    46. Re:Powershell by Bigbutt · · Score: 1

      I used a program called Megabasic back in the mid 80's that used paren'd colons to slice up a string.

      [John]

      --
      Shit better not happen!
    47. Re:Powershell by MightyMartian · · Score: 3, Interesting

      Apart from anything else, what I truly dislike about Powershell is how verbose it is. Perhaps it's my *nix heritage, but I like tidy little mnemonic commands like "mv", "rm" or "grep". Less typing, less things to wrong when you're writing scripts. I also find the syntax rather awkward. It's far better than the alternatives (like vbscript or jscript with WMI), but it's still a long ways away from what I would consider a decent scripting language.

      Actually, the worst part of about Powershell is how awfully slow it is. I'm sure that is because it's basically an interface sitting on top of .NET. The *nix shells are, for the most part, self-contained binaries, so bringing up a Bash script is very fast. But then again, sh and its descendants aren't trying to create a "do it all" environment, but rather create control structures and variables to expand upon existing *nix commands.

      I wrote a Powershell scriptlet a few months ago to dump Exchange 2010 mailboxes based on some criteria. Works like a charm, and like I said, despite my dislike of Powershell itself, I'm very grateful that it exists. But loading the Exchange scriptlets library takes something 10 to 20 seconds, and you can see Powershell nailing system resources like crazy to get to that point.

      While its roots, or at least its inspiration, are the Unix shells, in very important ways, it ignores key Unix principles. It is indeed what Bash would work like if it had been written by Microsoft.

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    48. Re:Powershell by LanceUppercut · · Score: 1

      `sizeof(string)` never "returns the length of a single byte".

      `sizeof(string)` evaluates to the byte-size of `string` object. E.g. it evaluates to the full size of the character array, if `string` is a character array. Or it evaluates to the byte-size of a pointer, if `string` is a pointer.

    49. Re:Powershell by MightyMartian · · Score: 2

      Compared to other scripting languages (I'm thinking Bash, Python, heck even Perl), yeah, Powershell kind of sucks. But compared to the incredible hacks that had to be used a decade ago to do scripting on Windows servers, it's a 1000% improvement. But, at the end of the day, it has to be one of the worst scripting languages I've ever used.

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    50. Re:Powershell by LanceUppercut · · Score: 1

      There's no dedicated feature in C language that makes specifically `if (a = b)` possible. Your `if (a = b)` example is just a side effect of the fact that `=` operator in C behaves just like any other operator: it has a result and it can have side-effects. This is perfectly logical and useful way to design an operator.

      You decided to make an `if` that depends on the result of `=` operator? Yeah, you can do that in C, but if you don't like it - it is your fault. Don't like it? Don't do it! Blaming it on the language is like hitting your thumb with a hammer and then blaming it on hammers.

    51. Re:Powershell by Darinbob · · Score: 1

      Remember some of those early languages were designed when keyboards were a lot more painful to use. Some people actually preferred "="/"==" in preference to ":="/=" as being much easier to type.

      Then again you could get mistakes even if "=" is test for equality, as in a statement written "a = 1" by mistake instead of "a := 1", but does not give a syntax error as it's legal (an expression is also a statement in C and many languages). So to be really safe you need ":="/"==", but at the point people think it's too verbose.

      Strings terminated by 0 is common sense. Strings with physical size is ALSO common sense. Both ideas have their merits and flaws. There is no right answer here! Which is best depends upon which operations you do and which combinations of operations are done. Ie, knowing the length of a string extremely quickly is good, but if you're also going to be operating on every character of the string (as in string comparisons) then it doesn't save you any time. Similarly, counted strings limit the maximum length of your strings (early languages would have one character only as length which was a severe limitation).

      Buffer overruns are a problem indeed but when the first goal of the language was efficiency then it's always left to the programmer to write correct code. Enforcing array lengths at run time can be big performance hit and increase the size of the code. With this attitude, I'm surprised you use assembler where the programmer is allowed to make all sorts of mistakes.

      sizeof("somestring") returns 11, not 1. Whereas sizeof(char*) returns the size of the pointer, not 1.

    52. Re:Powershell by Darinbob · · Score: 1

      UTF8 is certainly better than wide characters. Multibyte makes a lot of sense. Easy to get number of characters, easy to get number of bytes with strlen, easy to copy with strcpy, no endianness issues to deal with. The only fault really is that it's Unicode so you get the political wrangling.

    53. Re:Powershell by next_ghost · · Score: 1

      - if (a = b) assigns the contents of b to a and executes the code following if b <> 0. Who the hell thought that would be a good idea?

      Somebody who thought that adding unnecessary special cases to otherwise very simple and straightforward language was a bad idea. And he was absolutely right.

      - sizeof(string) (I may have got the name of the function wrong) returns the length of a single byte rather than the length of the entire string. Who the hell thought that would be a good idea?

      First of all, sizeof is a compile-time operator. The compiler replaces it with a fixed constant which indicates how many bytes are needed to store the argument (which is either a symbol or another constant) in memory. If you pass a pointer, you'll get the size of the pointer (4 bytes on x86). If you pass a statically allocated array, you'll get the total size of the array (int foo[9]; sizeof foo; will give you 36 on x86). If you pass a constant, you'll get the total size of the given constant in memory (sizeof "foo bar baz"; will give you 12). But all of that happens at compile time.

      When foo is a variable of simple type or instance of structure, sizeof tells you the size of foo itself. But when foo is a pointer, you want sizeof to tell you the size of some completely unrelated block of memory? The fact that foo can point somewhere to the middle of the memory block makes the idea even more ridiculous. Now tell me, who the hell would ever think that making sizeof behave inconsistently like that is a good idea?

      - strings terminated by a binary zero rather than their physical size. Who the hell thought that would be a good idea?

      Somebody who realized that zero-terminated strings have the lowest possible overhead for the most common string operations. Both from the machine's point of view and from the programmer's point of view. And it also avoids artificial limits on string length (Pascal's 255-byte strings say hi!).

    54. Re:Powershell by david_thornley · · Score: 1

      Lisp has various equality operators, such as eq, eql, equal, equal-p, =, string-=, string-equal, char-=, and char-equal. I'm not sure I got all of them. In general, the longer the operator name in a given type, the more things will compare equal (except that eql is a combination of the = versions of the others, plus things ruled equal by eq).

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    55. Re:Powershell by spitzak · · Score: 2

      Null-terminated strings were considered superior to using a length because they allowed strings to be > 255 bytes long (using 16 bits for the length would allow longer counted strings, but at that time with 4K of memory nobody in their right mind would suggest wasting a byte like that!).

      Null-terminated strings also have the nice property that getting the "tail" is a very fast operation, since you just return a pointer to the middle. This meant that searches could return strings, rather than indexes. This then meant that every function that worked on text only needed one argument, a string, rather than two (a string and an index). The savings due to this were pretty significant.

    56. Re:Powershell by beelsebob · · Score: 1

      What you just wrote is a strong indicator that you have no clue how much undefined behavior you have in your programs, and just happen to be getting away with just now.

    57. Re:Powershell by pubwvj · · Score: 1

      "- strings terminated by a binary zero rather than their physical size." ...
      "I program in ... Assembler to avoid that mess."

      I take it you never never worked in tight memory situations of the early processors. Just about everything people cite as example has an explanation related to the environment it occurred in. Very evolutionary. Things make sense when you understand the context. If you try you might.

    58. Re:Powershell by WalrusSlayer · · Score: 1

      Hey, just because you don't know the language doesn't mean it's necessarily wrong.

      And just because you do know the language doesn't mean it's necessarily right!

    59. Re:Powershell by solidraven · · Score: 1

      Compilers actually started reading code though :(

    60. Re:Powershell by Aardpig · · Score: 1

      Video shader in Fortran? Check, done that.

      --
      Tubal-Cain smokes the white owl.
    61. Re:Powershell by david_thornley · · Score: 1

      I've studied the language pretty well. I've read the Standard enough to know that a lot of stuff is well defined, and when I go through the program, I see only constructs I recognize as defined (or implementation-defined, or unspecified, and we won't write code that depends on anything unspecified).

      Okay, one caveat. We don't check for integer overflow, although I'm pretty sure it almost never happens. I know where and how we use integers.

      It is possible to write conforming C++ programs. It isn't always easy.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    62. Re:Powershell by dlingman · · Score: 1

      a[2] = *(a + 2) = *(2 + a) = 2[a]

      You're missing a ; at the end. Other than that, an optimizing compiler should notice that you're assigning something to itself, and make that entire line go away...

    63. Re:Powershell by nine-times · · Score: 1

      Out of curiosity, can you explain what's so bad about it?

      Honestly, I thought it was awkward and confusing until I got used to it, and then it seemed... not so bad. Is it really bash itself that's so good, or is it tools like awk, grep, and sed?

      Because Powershell has some nice little things built-in like parameter validation for function parameters, and extremely simple XML parsing, without even using other tools. I'm not much of a programmer, but for my purposes, I can sometimes write simpler and more readable code in Powershell than I know how to do in Bash-- I usually often write my scripts in Ruby because I feel like my complex Bash scripts become unreadable to me. I'm curious what, from a real programmer's point of view, is so bad about Powershell?

    64. Re:Powershell by kenshin33 · · Score: 1

      size of IS NOT a function. it is a unary OPERATOR that get's replaced at compile time not at runtime by the size in bytes of what ever you passed to it (generate assembly of simple code using size of and you'll see that it sizeof(int) gets replaced by the constant 4 but as of C99 if the operand is a variable length array things get complicated as it will compute the size at runtime, so the assembly code is way more complicated )

    65. Re:Powershell by Tom · · Score: 1

      C is for grown-ups. It is solidly based in the same core assumption as the Unix commandline: That the user knows what he's doing and the system shouldn't try to know better.

      if (a = b) is crazy useful and I'm most happy that PHP retains this convention. I use it all the time because it does the same but is much more readable than

      a = fopen("filename.ext");
      if (a) {
      ...
      }

      sizeof tells you what you ask it, and if you ask it about a pointer (strings are pointers in C), then it will tell you about the pointer because it assumes that is what you want to know and if you'd wanted to know the length of the string, you would've asked for the length of the string via the strlen() function, for example.

      String termination as well is an example of doing only what is needed, revealing how close C still is to assembler. Not doing nonsense like manipulating counters that may never be needed is one of the reasons C is fast.

      Kids grew up with this idiocy, I program in Fortran, Cobol, even Assembler to avoid that mess.

      You program in Cobol and talk about mess? This ranks high in the top list of crazy things I've heard on /.

      --
      Assorted stuff I do sometimes: Lemuria.org
    66. Re:Powershell by rmstar · · Score: 1

      I've studied the language pretty well. I've read the Standard enough to know that a lot of stuff is well defined, and when I go through the program, I see only constructs I recognize as defined (or implementation-defined, or unspecified, and we won't write code that depends on anything unspecified).

      Or, put another way, you have spent a very large number of hours to master this stuff. This is a failure of language design, as it is known that you can write languages that do not require such a high time investment.

      It is possible to write conforming C++ programs

      I don't think anyone is disagreeing with you on this point. The critique is that is needlessly difficult. Even an expert has a bad day now and then, and when that happens, in C++ he is exposed to a much larger number of pitfalls and traps than in other languages.

    67. Re:Powershell by chiguy · · Score: 1

      a[2] = *(a + 2) = *(2 + a) = 2[a]

      You're missing a ; at the end.

      Other than that, an optimizing compiler should notice that you're assigning something to itself, and make that entire line go away...

      I think he meant that as equivalence instead of assignment, but I'm not sure.

      --
      passetspike!
    68. Re:Powershell by spiralx · · Score: 1

      Nope, it's actually heavily influenced by Perl of all things, one of the guys who created it has also written a book on PS which has various sidebars about the design of the language.

    69. Re:Powershell by BadDreamer · · Score: 1

      When strings are built from a chunk of data and a piece of metadata denoting their length you run the risk of heartbleed style bugs in all code, everywhere. You run into issues of how to handle when the string actually is one length, and the metadata says it's another - especially when the metadata says it's longer.

      Zero terminated strings is a damn good idea for cases when computing power and memory are limited, or where performance matters more than solid string performance, such as in kernels and embedded programming. Yes, when you develop a business process middle layer they're a liability, but if you're doing that in C you've got bigger problems.

    70. Re:Powershell by psmears · · Score: 1

      The compiler replaces it with a fixed constant which indicates how many bytes are needed to store the argument (which is either a symbol or another constant)

      No, it can be any expression or any type. Doesn't have to be a symbol, and doesn't have to be constant.

    71. Re:Powershell by next_ghost · · Score: 1

      Ah, yes, of course. Thanks for the correction.

    72. Re:Powershell by dcpking7700 · · Score: 1

      Too right, Tom - C is definitely for grown-ups!

      RTL/2 was fun. There waere two commands - CODE and RTL - between which you could write plain assembler code. It only compiled if you used the right compiler switch! You could also do things like copying a Char to and In to find out which char it was by ansi number if you used that magic compiler switch!

      Least-used feature in a language?

      Has GOT to be the FORTRAN keyword in C, which allows you to embed FORTRAN inside a C program !

      Mike
      --
      You have the right to remain sentient. If you give up that right you shall be elected.

    73. Re:Powershell by smellotron · · Score: 1

      So to allocate a string you have to multiply sizeof with strlen and add 1 for the null terminator?

      Since you specifically mentioned strlen, I can tell that you are doing the wrong thing. It is guaranteed that sizeof(char) == 1, so you can skip the sizeof. And then instead of allocating strlen(x)+1, you could use the standard function strdup .

      Aside from this particular example, what is your beef with sizeof? Do you know an alternative for compile-time size calculations?

    74. Re:Powershell by shutdown+-p+now · · Score: 1

      PowerShell is really more of a bastard child of Bash and C#.

      (Rumor has it that the coupling was so unnatural that the prodigy is sterile.)

    75. Re:Powershell by flargleblarg · · Score: 1

      Documentation for sizeof would have told you that it's for telling you the size in bytes of datatypes on a particular system.

      s/bytes/chars/

      example: uint32 is a 32-bit unsigned integer,

      s/uint32/uint32_t/ (unfortunately)

    76. Re:Powershell by flargleblarg · · Score: 1

      They should of used:

      :=

      s/of/have/

      I know one game shipped with buggy AI because somebody forgot to use two equal signs inside an if statement!

      That's not C's fault. That's the developer's fault for ignoring the compiler warning about it. (Or for not having enabled the warning.)

    77. Re:Powershell by BasilBrush · · Score: 1

      It is guaranteed that sizeof(char) == 1, so you can skip the sizeof.

      I see that it is in C99. But it wasn't when I was learning C in the 1980s.

      Since you specifically mentioned strlen, I can tell that you are doing the wrong thing.

      Well I don't use C strings at all, except in the infrequent occasions I'm using a C library from Objective-C that uses them.

      Aside from this particular example, what is your beef with sizeof? Do you know an alternative for compile-time size calculations?

      Sure. Don't use a language that encourages pointer calculations. If you're working in the kernel or hardware drivers maybe. But for applications C is probably the wrong tool.

    78. Re:Powershell by smellotron · · Score: 1

      I see that it is in C99. But it wasn't when I was learning C in the 1980s.

      Well! I'll get off your lawn now. I learned on C99, I did not know that the guarantee was new.

      Don't use a language that encourages pointer calculations. If you're working in the kernel or hardware drivers maybe.

      That is hardly an argument against sizeof as a language feature. I think we both agree—outside of the first learning experience—developers who are getting tripped up by sizeof should't be using C in the first place; but it is not the fault of the language or a misfeature.

    79. Re:Powershell by Shirley+Marquez · · Score: 1

      Embedded assignment in C came from a different era - one when both computers and compiler technology were much more limited. Using it made it possible to generate more efficient code for the common sequence of operations where you want to calculate a new value and both save it and make a test based on it.

      Let's look at the code that a naive compiler would produce for two hypothetical sequences. (These are given in a simple hypothetical assembly language, but the examples are representative of what real code would have looked like. Details such as which register was used, relevant to the PDP-11 but not to many of its predecessors, are omitted.) First, the straightforward one without embedded assignment:
      a=b
      LOAD A
      STORE B
      if (a)...
      LOAD A
      BEQ NOTA
      (code that follows the comparison)
      NOTA: (code after the if)

      Next up, the code generated when the conditional assignment is used:
      if (a=b) ...
      LOAD A
      STORE B
      BEQ NOTA
      (code that follows the comparison)
      NOTA: (code after the if)

      The redundant load operation is now gone, yielding a 25% reduction in code size and execution time for this test on computers that were in use when C was invented.

      The original implementations of C had to run on computers that were hopelessly limited by modern standards; a typical configuration would be a PDP-11 with 16K bytes of memory. To put that into perspective, that is less powerful than the microcontroller that runs your neighborhood traffic light. Any decent modern C compiler will recognize the unnecessary load and optimize it out unless a is declared volatile, a declaration that didn't exist back in the early days of C because there was also no such thing as register variables, let alone compilers that would automatically promote some variables to that status. But the compiler that ran on that 16K PDP-11 did not perform that optimization, and attempting to add that capability to the compiler would have resulted in something too slow to be usable.

    80. Re:Powershell by UnknownSoldier · · Score: 1

      That was back in the 90's, there was _no_ compiler warning. That was the problem. :-/

    81. Re:Powershell by denis-The-menace · · Score: 1

      http://batsh.org/

      No this IS.

      "Batsh is a simple programming language that compiles to Bash and Windows Batch. It enables you to write your script once runs on all platforms without any additional dependency."

      --
      Obama's legacy: (N)othing (S)ecure (A)nywhere and (T)error (S)imulation (A)dministration
    82. Re:Powershell by flargleblarg · · Score: 1

      Ok, so it's the developer's fault for not using lint then.

      :-)

    83. Re:Powershell by david_thornley · · Score: 1

      Well, yes. I've put in a lot of work learning C++, and so have many of my colleagues. The fact that this is necessary to write good C++ is indeed a fault of the language, but we do have what are in general conforming C++ software. I don't know how many other C++ shops can reasonably make that claim.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  2. a fucking slideshow? by Anonymous Coward · · Score: 5, Insightful

    Posting a slideshow on Slashdot? Lame. What, was Buzzfeed not available?

    1. Re:a fucking slideshow? by Anrego · · Score: 4, Insightful

      I don't even bother with infoworld links any more. It'll be a bunch of slides with a sentence of text, an unrelated image, and ads everywhere (ads on the slides, ads before the slides, an add in the middle of the slideshow, and an ad at the end). Content wise, usually they find one or two interesting things, then fill the rest of the slots with stupid shit everyone already knows.

    2. Re:a fucking slideshow? by Anrego · · Score: 1

      * itworld (reading another post where they messed it up, so I messed it up!)

    3. Re:a fucking slideshow? by Tukz · · Score: 3, Insightful

      And not only that, the slides slides to advertisements WHILE YOU'RE READING THEM!
      Closed the tab at that point.

      --
      - Don't do what I do, it's probably not healthy nor safe. -
    4. Re:a fucking slideshow? by amicusNYCL · · Score: 4, Insightful

      That was my experience. I opened the page, clicked Next past the intro slide, saw a picture of apples and oranges, some text talking about "+" in Javascript, clicked Next again, it faded out to show an ad that I blocked, and I closed the page. Bunch of crap.

      --
      "Our two-party system is like a bowl of shit looking at itself in a mirror." - Lewis Black
    5. Re:a fucking slideshow? by Anonymous Coward · · Score: 1

      "8 annoying programming features, plus 2 you've never thought of!" "Developer posts annoying language features, you won't believe what happens next!"

    6. Re:a fucking slideshow? by QuietLagoon · · Score: 2

      I don't even bother with infoworld links any more....

      Earlier this week I removed ComputerWorld from my bookmarks. They just went through a site redesign, and the page content has dropped dramatically, plus there's an automatic slideshow scrolling horizontally on the top of your screen as you're trying to focus on and read something else on the page.

    7. Re:a fucking slideshow? by fustakrakich · · Score: 1

      itwbennett...

      C'mon folks open your eyes..

      --
      “He’s not deformed, he’s just drunk!”
    8. Re:a fucking slideshow? by smartkid88 · · Score: 1

      I don't even get to see the intro slide. All that loads is a broken empty kind of shell with no content.

    9. Re:a fucking slideshow? by wiredlogic · · Score: 1

      I didn't see any of that thanks to NoScript. Just a partially rendered layout with no content. If Devs can't get their shit together to make a web site usable without Javascript I move on and find something else to do.

      --
      I am becoming gerund, destroyer of verbs.
    10. Re:a fucking slideshow? by Darinbob · · Score: 1

      With noscript, it takes ages to figure out what to enable to allow the actual text to appear. Everything on these sites is hidden behind a maze of scripts. It's job security for webbies I suppose.

    11. Re:a fucking slideshow? by Darinbob · · Score: 1

      I got it to work by temporarily enabling a set of scripts. When the "ad" came it was blank with only a message saying "click here to resume" :-)

  3. Database Identity by Baby+Duck · · Score: 2, Insightful

    It's outdated database security models that cause me the most grief. I don't want jsmith logging in from gatech.edu to be considered a DIFFERENT HUMAN BEING that jsmith logging in from whitehouse.gov. I want to say, there's ONE PERSON, John Smith, username jsmith, who is allowed to login from BOTH domains with the SAME PASSWORD and GRANTS. Nope. Can't do it. Newer versions MIGHT allow you to swap in your own authentication module instead, but NOT the authorization piece, so I'm still screwed!

    --

    "Love heals scars love left." -- Henry Rollins

    1. Re:Database Identity by tompaulco · · Score: 1

      I think it is the opposite of outdated. It used to be that jsmith was jsmith. Now, with all this fancy Windows Authentication, you can be guaranteed no end of hassle. For instance, at my company, our laptops are on a different domain than production, for some sort of security reason. However, one of the database servers is set up with windows authentication, which means, yup, you can't log into it from your laptop. You have to first remote desktop into something on the production domain, and then run SQL enterprise manager from there.

      --
      If you are not allowed to question your government then the government has answered your question.
    2. Re:Database Identity by tepples · · Score: 1

      I want to say, there's ONE PERSON, John Smith, username jsmith, who is allowed to login from BOTH domains with the SAME PASSWORD and GRANTS.

      Same password, yes, that's what OpenID and OAuth-based authentication are for. But why would someone have the same grants on gatech.edu as on whitehouse.gov? Just because you're allowed to manage a professor's presence on Georgia Tech's web site doesn't mean you should be allowed to deface Barack Obama's site.

    3. Re:Database Identity by Baby+Duck · · Score: 1

      That's the opposite direction. The user is coming FROM those gatech.edu and whitehouse.gov domains to a third one. It's the third domain you are reading/writing data for.

      --

      "Love heals scars love left." -- Henry Rollins

    4. Re:Database Identity by asmkm22 · · Score: 2

      Maybe I'm missing something here, but why can't you just specify the domain name before the user name when you attempt to login to the database from your laptop?

    5. Re:Database Identity by angel'o'sphere · · Score: 1

      That has nothing to do with windows authentication nor is it fancy.

      If you do it right you have subdomains like: production, prelife, test, development, admin. And firewalls prevent any access from development to prelife or production.
      If you do it really right all hostnames in production are mirrored in prelife and test, or you have another level of subdomains if you need several "test domains".

      If a certain developer needs access to production or prelife he ofc has to go via a special admin "realm" and ofc needs to have a special authentication. That is a no brainer. To sad that it "complicates your live" and you "don't grasp the reason" for it. (Hint: such a connection through an extra 'admin pc' can be automated ... it just likes you connect directly to the host behind it ... ask your sys admin)

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    6. Re:Database Identity by suutar · · Score: 1

      I think it's meant not so much as "this person has the same rights in two different databases" as "this person has the same rights regardless of which ISP he's using to get to this database".

    7. Re:Database Identity by Jane+Q.+Public · · Score: 1

      I'm not sure how that would play out in Postgres, but if you're using MySQL or a variant like MariaDB, you can

      GRANT ALL ON *.* TO 'username'@'*' IDENTIFIED BY 'password';

      Works for me.

    8. Re:Database Identity by jrumney · · Score: 1

      Perhaps because the Production domain does not trust the Developers domain? And nor should it. Seriously - developers working directly on the production servers?

    9. Re:Database Identity by asmkm22 · · Score: 1

      If that's the case, just start the SSMS from the command line using "runas /netonly /user:domain\user"

  4. Infoworld... pass by Anonymous Coward · · Score: 3, Insightful

    I envision an add filled slideshow with almost no content, and what content is there to be boring and well known so I’ll skip the article.

    To answer the question, most of perl seems to be built around bizarre unintuitive constructs that you just have to kinda know about, so pointing out any of that would seem unfair.

    In C, the first time I saw the size of elements of a struct specified (i.e. int something : 3) it threw me (and that’s a hard problem to google). It was being used to essentially overlay a struct onto a chunk of memory being received via an interface and extract values, which was actually kinda a cool use of the feature (though a comment woulda been nice unknown dev!).

    Some of the type erasure mechanics of Java can be a bit confusing the first time you hit up against them.

    The way javascript does dates, and timezones

    I dunno, most languages have their weird bits, but I can’t think of anything that is egregiously terrible.

    As far as tools, I'd say pacman (Arch's package manager) and git (yes, I'm an SVN fanboy) have the highest concentration of "the hell were they smoking" flags and usage instructions. Pacman seemed to pick it's arguments randomly, and git seems to go straight off the deep end if you want to do anything non-trivial.

    1. Re:Infoworld... pass by sconeu · · Score: 1, Informative

      In C, the first time I saw the size of elements of a struct specified (i.e. int something : 3) it threw me

      Considering that you misunderstand/misunderstood the syntax, I'm not surprised.

      It's not saying it's a 3 byte int, it's saying it's a 3-bit field.

      --
      General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    2. Re:Infoworld... pass by marcosdumay · · Score: 1

      From the GNU C manual (in the section about bit fields):

      You can also specify a bit field of size 0, which indicates that subsequent bit fields not further bit fields should be packed into the unit containing the previous bit field. This is likewise not generally useful.

      I guess now I have a new favorite C feature... Well, as soon as I actually understand what this means.

      Also, GCC accepts empty structs, and they use no memory! I should look at the C specs more often.

    3. Re:Infoworld... pass by xvan · · Score: 1

      That's also used by the CMSIS for ARMs ... There, struct pointers are pointed to the pheripherals registers memory map, so you can make calls like TIMER->value.

    4. Re:Infoworld... pass by angel'o'sphere · · Score: 1

      Actually he did not mention bytes but only "size".

      But I guess many C/C++ programmers never digged (how is that spelled right?) into it, so your comment is likely welcome.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    5. Re:Infoworld... pass by stderr_dk · · Score: 1

      The way javascript does dates

      Are you talking about getYear() being years since 1900 or something else? You might want getFullYear() or getUTCFullYear().

      and timezones

      Javascript only does UTC and "whatever timezone the browser is using". If you need other timezones, you'll need a third party library (such as this shameless plug).

      --
      alias sudo="echo make it yourself #" ; # https://pipedot.org/~stderr & http://soylentnews.org/~stderr
    6. Re:Infoworld... pass by AdamHaun · · Score: 1

      C's bit fields are a really helpful feature in embedded programming. Unfortunately their implementation is strongly tied to the target CPU architecture. In particular, the endianness of the fields cannot be redefined in code, and bit fields are usually not allowed to cross word boundaries.

      --
      Visit the
    7. Re:Infoworld... pass by lgw · · Score: 1

      In C++, empty classes are a nice thing because they can' be a useful trick for overloading. (Instead of passing an enum to select function behavior at runtime, you pass an instance of a content-free class to select function behavior at compile time.) Not sure what the point would be in C - you can give a type to an arbitrary pointer, and do strongly typed enums that way?

      --
      Socialism: a lie told by totalitarians and believed by fools.
    8. Re:Infoworld... pass by Menkhaf · · Score: 1

      I'm not a native English speaker either, but it's past tense, so I believe it should be "dug". English is weird (but not any weirder than German with their unrecognizable genders or Danish with en/et)...

      --
      A proud member of the Onion-in-Hand alliance
    9. Re:Infoworld... pass by angel'o'sphere · · Score: 1

      Ah, you are right, 'dug' but the damn spelling correction did not provide that as a possible solution, I'm getting old!
      Thanx :)

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    10. Re:Infoworld... pass by DrJimbo · · Score: 1

      In C, the first time I saw the size of elements of a struct specified (i.e. int something : 3) it threw me (and that's a hard problem to google). [...] (though a comment woulda been nice unknown dev!)

      The first hit from Google(struct) is the Wikipedia(struct) entry which starts with:

      A struct in the C programming language (and many derivatives) is a complex data type declaration that defines a physically grouped list of variables to be placed under one name in a block of memory, allowing the different variables to be accessed via a single pointer, or the struct declared name which returns the same address. The struct can contain many other complex and simple data type in an association, so is a natural organizing type for records like the mixed data types [...]

      Furthermore, I really don't think a comment should be used to explain a language element that is clearly defined in The C Programming Language (K&R) by Brian Kernighan and Dennis Ritchie. A C programmer should assume the reader is familiar with what is in K&R, otherwise the comments become a language tutorial.

      As for Perl, once I really learned Perl I found it to be extremely intuitive. It is a very powerful and very expressive language. All of the sigils (and related "line noise" characters) make the code much easier to read and they make it extremely trivial to define and understand complicated data structures. Larry Wall, the creator of Perl, got an undergraduate degree in natural and artificial languages and then went on to do graduate work in linguistics. The Wikipedia says:

      Wall's training as a linguist is apparent in his books, interviews, and lectures. He often compares Perl to a natural language and explains his decisions in Perl's design with linguistic rationale.

      Your comment about Perl seems to boil down to the fact that it is different from languages you are familiar with and you never bothered to learn it so it makes no sense to you. Your gripe about the C struct element seems to be similar, like everyone else in the world, you have trouble reading languages you are not familiar with. I have the same problem with Russian and other languages I have never learned.

      BTW, have you ever noticed that nuclear missiles tend to be only targeted at countries that use a different alphabet? Perhaps it is only a coincidence but I think it may be related to your problems with Perl, an oversimplification that equates foreign with bad.

      --
      We don't see the world as it is, we see it as we are.
      -- Anais Nin
    11. Re:Infoworld... pass by Anrego · · Score: 1

      Furthermore, I really don't think a comment should be used to explain a language element that is clearly defined in The C Programming Language (K&R) by Brian Kernighan and Dennis Ritchie. A C programmer should assume the reader is familiar with what is in K&R, otherwise the comments become a language tutorial.

      I generally agree that comments shouldn't be required to explain language mechanics unless they are obscure (which the bitset stuff isn't, I mean if you've never run into them they might be, but that would be the same for any language construct and as you said, you generally assume a developer is going to know the language they are working with).

      What I personally would generally include would be a comment along the lines of "this struct represents the KillAllHumans message body as per <some specification;>" where the struct is defined, and then a comment along the lines of "overlay our message structure over the buffer to extract our data". This way even if someone wasn't familiar with the bitset notation, they could probably infer it.

      As for Perl, once I really learned Perl I found it to be extremely intuitive. It is a very powerful and very expressive language. All of the sigils (and related "line noise" characters) make the code much easier to read and they make it extremely trivial to define and understand complicated data structures. Larry Wall, the creator of Perl, got an undergraduate degree in natural and artificial languages and then went on to do graduate work in linguistics.

      Perl... easy to read... ok back to your room now ;p

      I'll grant you that perl is very organic, probably the best "code as you think" language that I know of, but the vast collection of syntax and the functional density one can achieve (and some seem compelled to do so) makes it a pain to read if you didn't write it.

      I've read the camel book cover to cover, and at one point I was fairly good with it, but after a few years of neglect that skillset has completely dissolved. I have a feeling if I tried to do anything with it now, I'd be hitting up google for things like "how do you iterate through an array of hashmap references".

    12. Re:Infoworld... pass by DrJimbo · · Score: 1

      What I personally would generally include would be a comment along the lines of "this struct represents the KillAllHumans message body as per " where the struct is defined, and then a comment along the lines of "overlay our message structure over the buffer to extract our data". This way even if someone wasn't familiar with the bitset notation, they could probably infer it.

      I agree, comments are for the information you add, although well thought out variable names go a long way to making code understandable:

      /* as per some specification */
      struct KillAllHumans_Body {
      ...
      }

      I'll grant you that perl is very organic, probably the best "code as you think" language that I know of, but the vast collection of syntax and the functional density one can achieve (and some seem compelled to do so) makes it a pain to read if you didn't write it.

      I am not disputing that it is easy to write obfuscated Perl but Perl style guidelines have come a very long way with Perl Best Practices by Damian Conway and the Perl::Critic module and the perlcritic program. There is a lot of Perl code written by other people that I find very easy to read. The key is to write clear code and use good variable and function names. The sigils provide context (and higher information density) which is what makes good Perl code easier to read than good Java or C code. YMMV.

      Gregory Chaitin, one of the founders of algorithmic information theory once said in jest:

      The LISP interpreter is about three-hundred lines of Mathematica code. Then I redid it in C, and it's a thousand lines of C, and the program is incomprehensible, which means that I'm a good C programmer!

      Perl does tempt you to show off by writing incomprehensible (and perhaps incompressible) code. The style guidelines and experience can help you avoid this temptation.

      IMO, the Camel Book is informationally dense. One reading was not nearly enough for me. I probably have read it all at least a half dozen times. I haven't used it in years because it is almost all on-line now and also part of the perldoc system.

      [...] how do you iterate through an array of hashmap references [...]

      for my $hash_ref in (@Array_of_hash_refs) {
      ... $hash_ref->{$key} ...
      }

      IMO, with descriptive variable names this construct is both easy and clear. I think it is beautiful. If you want to access just one element then use:

      $Array_of_hash_refs[$index]->{$key}

      For nested data structures like this I prefer to make the top level structure a reference so this becomes:

      $Array_of_hash_refs->[$index]->{$key}

      Which I think is a little more consistent.

      I've taught Perl in college and I admit there are some (perhaps many) people who will never master it. OTOH, I once wrote a CSM system in Perl in the time the Java folks said they would need to come up with an estimate for how long it would take them to do it.

      --
      We don't see the world as it is, we see it as we are.
      -- Anais Nin
    13. Re:Infoworld... pass by marcosdumay · · Score: 1

      you can give a type to an arbitrary pointer, and do strongly typed enums that way?

      Strongly typed... C... Those things do not belong in the same sentence.

      The point is probably that there must be some behaviour, and it's better to define it. Thus, they defined. I hightly doubt it has any practical application, besides minimizing the damage in case of some kind of error.

      But yeah, it's amusing.

  5. cmp %rdi,%rax by ColonelPanic · · Score: 1

    Goddamn AT&T assembler syntax with its reversed operands. Quick, you want to compare two registers, and jump if %rdi %rax. Which order do you place the operands to the comparison, and what's the predicate to use on the jump? Drives me nuts.

    --
    "Skill shows through where genius wears thin." -Wittgenstein || Religion: uniting aviation and architecture.
    1. Re:cmp %rdi,%rax by bluefoxlucid · · Score: 4, Interesting

      I always liked the target-first approach of Intel. Like strcpy(dst, src). I know I'm mucking with (dst) string, and not doing anything with (src). The same with (MOV %eax, 0xdeadbeef).

      Imagine strcpy(src,dst), which many people would say is more logical because you're saying "Perform a string copy from (src) to (dst)." We say "Copy from source to destination" all the time--it's how we think, right? And then: strncpy(src,dst,32). So with strcpy(), the last argument is the thing we mess with; while strncpy() it's some argument in the middle.

      This is why strcpy(dst,src) and strncpy(dst,src,len) are set: the first argument is the target. These calls immediately tell you what they actually change. printf() changes nothing, but uses the first argument as its format--it emits a modified content of the first argument based on subsequent arguments; sprintf() changes the first argument to a modified copy of the second argument using all further arguments. If something is changed, it's the first things that are changed.

      In Intel assembly, a glance down the left side of the screen rapidly tells you what's roughly going on. You don't need to read the whole line; you just look at opcodes and targets, quickly recognizing which opcodes modify their targets. This immediately tells you flow; and attaching the source data for the modification provides you with logic. This is less decoding than trying to interpret an individual opcode, rearrange it in your head, extract its behavior, extract its logic, and build incrementally with that.

    2. Re:cmp %rdi,%rax by mferero · · Score: 1

      Hear hear! Those of us that learned assembler on the big iron (IBM mainframes) totally agree. Teaching new students to assembler in AT&T format was something I was NOT going to do.

      --
      Honor est omni
    3. Re:cmp %rdi,%rax by GbrDead · · Score: 1

      Or you can use the following argumentation:

      We say "assign the value of b to a" but write "a = b".

    4. Re:cmp %rdi,%rax by bluefoxlucid · · Score: 1

      That doesn't tell anyone why it's favorable to write 'a = [long equation]' than '[long equation] => a'. In mathematics, it's also the ability to rapidly assess flow in long, algorithmic calculations.

  6. Lua[0]? by ThisIsSaei2561 · · Score: 5, Interesting

    Lua's standard is, for things like arrays, to start counting from 1. The unlearning of old habits made this a hard adjustment.

    1. Re:Lua[0]? by Anonymous Coward · · Score: 5, Funny

      Bookkeepers, shepherds, scientists and mathemaitcians have for centuries counted starting with 1. It is recent computer scientists that started this crazy standard break, as if they knew better how to count.

    2. Re:Lua[0]? by Anrego · · Score: 1

      In general I found it difficult to twist my brain into doing things the lua way.

      It seems to go out of it's way to be slightly different.

    3. Re:Lua[0]? by nicolastheadept · · Score: 2

      I would say it's more a weird feature of C to count from 0 (and everything copied it). Fortran and COBOL count from 1 (in fact, Fortran counts from whatever the hell you want it to)

      --
      09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
    4. Re:Lua[0]? by angel'o'sphere · · Score: 2

      Most languages start array indices with 1 ... only coming from C later languages that adopted C "syntax" also adopted the start with zero paradigm.

      But of course, habits cause problems. In Pascal you count until 'i == end' in C/Java etc. you count while 'i < end' ... had the same trouble often enough in reverse transition :D

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    5. Re:Lua[0]? by Dagger2 · · Score: 1

      That's fairly unusual, but it's not quite as strange as Perl's $[, which you can assign to to select where arrays count from.

    6. Re:Lua[0]? by Uecker · · Score: 2

      there are some reaons why starting with zero might be better:

      http://www.cs.utexas.edu/users...

    7. Re:Lua[0]? by Anonymous Coward · · Score: 1

      Computing uses definitive or absolute numeric values, also known as cardinal numbers. These are typically used to state quantities or identifying values.

      People counting things in their heads for centuries have traditionally used relative-to-nothing numeric values, also known as ordinal numbers. These are typically used to state the order or position of things.

      So a shepherd counting sheep begins by counting the first, then the second, third, fourth, and so on until he has passed each sheep through his field of view or a counting chamber or funnel (there are many ways to do this, but basic gist is that each sheep is counted once, and is in a position in the count order). Then, when he is done, he converts that into a quantity. So everything you've just mentioned starts as an ordinal and is converted to a cardinal at the end of a batch process.

      Computers keeping an array of values are not counting. They're not keeping track of the order as such. They're simply identifying where something is located. At its most basic, an array is a pointer to the first item, and the array index is an offset to add to that pointer to find each item. This is a cardinal (identifying) number sequence, with a cardinal (quantifying) limit. It's pure cardinality. And cardinal numbering is absolute, not relative. You're not differentiating "has an array index" from "doesn't have an array index". Everything in an array has an index, and the array is positioned absolutely at the pointer address, and each item is identified absolutely by its index/offset.

      It's not that computer scientists "knew better how to count", it's that they recognized that counting isn't the answer to this problem.

    8. Re:Lua[0]? by Jamu · · Score: 1

      It kind of makes sense in C, as arrays are basically pointers. e.g. p[i] == *(p + i)

      --
      Who ordered that?
    9. Re:Lua[0]? by Framboise · · Score: 1

      The discussion is not on measuring continuous quantities
        but counting discrete objects. Physicists and mathematicians have indexed, say, vectors, starting with 1 for ages, except in recent times where sometimes they use 0 for very special reason (like chapter 0 in a book).

    10. Re:Lua[0]? by preaction · · Score: 1

      Deprecated, thank YHWH, in 5.20 or .22. To be removed "not soon enough."

    11. Re:Lua[0]? by david_thornley · · Score: 2

      If I'm counting three things, I say "one, two, three". If I'm counting events, I might count "first, second, third". You'll notice that the first example is cardinal and the second example is ordinal. If things worked like you seem to be thinking, I'd count events "zeroth, first, second".

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    12. Re:Lua[0]? by UnknownSoldier · · Score: 1

      One is an absolute total.
      One is a relative offset.

      i.e.

            *(pArray + 0) = pArray[ 0 ]; // same location

    13. Re:Lua[0]? by The+MAZZTer · · Score: 1

      The math tends to be simpler in many cases if you start counting at 0. In C's case, a[1] is == a + 1 if a is an array of bytes.

    14. Re:Lua[0]? by Bloke+down+the+pub · · Score: 1

      It's the natural way to index on a computer since the base address of an array points to the first element of that array.

      No, it's the natural way to do it for a computer.

      Isn't it the compiler's job to sort out shit like that?

      --
      It's true I tell you, feller at work's next door neighbour read it in the paper.
    15. Re:Lua[0]? by viperidaenz · · Score: 1

      If you have a list of items that start at an address, what number to you add to this address to get the first one?

    16. Re:Lua[0]? by wiredlogic · · Score: 1

      That and the global scope to variables is why I won't use Lua. Shame, It's a good language other than those warts.

      --
      I am becoming gerund, destroyer of verbs.
    17. Re:Lua[0]? by Half-pint+HAL · · Score: 1

      It's not that computer scientists "knew better how to count", it's that they recognized that counting isn't the answer to this problem.

      That doesn't really tally with what you said. Arrays were originally "pointer+offset". Fine. That was a technical solution in low-level languages. But in high-level languages that are specifically aimed at better matching humans' natural tendencies, counting is the correct answer to this problem.

      --
      Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
    18. Re:Lua[0]? by Half-pint+HAL · · Score: 2

      This is not about cardinal or ordinal numbers. Conceptually, to a human being, the elements of an array map to natural numbers. The conceptual difference between 0-indexed and 1-indexed arrays is best viewed as the argument over whether 0 is a natural number or not. I'm in the "not" camp, which says that if it wasn't for low-level languages needing the pointer+offset notation, 1-indexed arrays would be superior as an analogue of the programmer's natural thought process. All of us who code had to learn 0-indexing, and it took a fair bit of time to overcome the unnaturalness of it all. Which is why I consider 0 non-natural.

      --
      Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
    19. Re:Lua[0]? by Darinbob · · Score: 1

      This isn't wierd, it's perfectly normal for many languages. Back when C was new it was sort of the oddball by starting from 0. Fortran for example starts from 1. Quite a lot of languages let you choose your own starting index (ie, "array 10..20 of array 1..100 of float").

    20. Re:Lua[0]? by Greyfox · · Score: 1
      You can index negatively in C as well, if you want to.

      If you REALLY want your array to start at 1, why not just subtract one from its pointer? Then it'll start at 1 just fine!

      --

      I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

    21. Re:Lua[0]? by solidraven · · Score: 1

      Lua at least has a standard, can't say the same about Fortran where you just sort of decide whatever the hell you want to use at the time of writing your code. Oh, and you'll just love VHDL where you can make up array indices as you go, no questions asked.

    22. Re:Lua[0]? by T.E.D. · · Score: 3, Interesting

      It is recent computer scientists that started

      Not "computer scientists". Just C programmers. The first two languages designed, Fortran and Cobol, start at 1. Algol('68) and all the languages descended from or influenced by it let the programmer set the starting bound (this includes Ada, Pascal and all the other Wirth languages).

      Pretty much every language that uses 0 as the only allowable starting index is either descended from C, or borrowed large amounts of its syntax from it. (Some BASICs use 0, but that language is so egregiously unstandardized that its tough to say anything about it with certainty).

    23. Re:Lua[0]? by demonlapin · · Score: 1

      Well, crap. Posting to undo accidental redundant mod. This is insightful.

    24. Re:Lua[0]? by rasmusbr · · Score: 1

      The math tends to be simpler in many cases if you start counting at 0. In C's case, a[1] is == a + 1 if a is an array of bytes.

      Yeah, it's usually easier to start with 0 in pure math too. Remember that an N:th degree polynomial can be written as:

      sum from n=0 to n=N of c_n*x^n, where c_n are constants

      Here you avoid having to invent a special case for the constant (zeroth degree) term by exploiting the fact that x^0 = 1.

    25. Re:Lua[0]? by david_thornley · · Score: 1

      Most languages do not have a list of items that start at an address, formally, but rather it's an implementation detail and not part of the language standard. C does, and a lot of other languages have picked up on it.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    26. Re:Lua[0]? by Patman64 · · Score: 1

      This is exactly why there's no problem with Lua being 1-indexed instead of 0-indexed. It's not C, so you aren't doing pointer arithmetic on some address. If you want the first element in a table it's index is 1 and the second is 2. The first letter in a string is 1, second is 2.

      If anything, other high(er) level languages being 0-indexed is the oddity. I would imagine it's to make C programmers feel comfortable.

    27. Re:Lua[0]? by viperidaenz · · Score: 1

      Go have a look at Visual Basic.
      It's 1-based, unless you need to interface with any system libraries or other DLL's, then it's 0-based.

    28. Re:Lua[0]? by TeknoHog · · Score: 1

      Physicists and mathematicians have indexed, say, vectors, starting with 1 for ages, except in recent times where sometimes they use 0 for very special reason (like chapter 0 in a book).

      One common example of vector indices is in relativity. Since we traditionally used indices 1 to 3 for spatial dimensions, it made sense to keep them that way. The spatial dimension was given index 0 probably to denote its special/fundamental position (e.g. energy in the energy-momentum vector).

      The traditional programming language of scientists, Fortran, starts its arrays with 1 by default, but it can also be instructed to start wherever you want. For example -n to +n is sometimes quite convenient.

      --
      Escher was the first MC and Giger invented the HR department.
    29. Re:Lua[0]? by TeknoHog · · Score: 1

      The positional argument for starting with 0 makes sense in C, because it's such a low-level language. It makes sense to expose this low-level view on arrays so you can do things like pointer arithmetic.

      For anything higher-level, you'd think the language should make things easier for people who deal with everyday countable items. But even in an otherwise nice high-level language like Python you can find some thoroughly messy array logic, because it basically takes the positional idea even further. While a[0] is the first item, a[0:2] is a range of the first two items, instead of three. The logic is called slices: you start at position 0, which is just before the first item, and end at 2, just after the second one. You've spanned a distance of 2, over the first 2 items.

      --
      Escher was the first MC and Giger invented the HR department.
    30. Re:Lua[0]? by shutdown+-p+now · · Score: 1

      What we do not do is confuse cardinal numbers (which you use for counting) with ordinal numbers (which you use for coordinates, such as the position in an array).

      Last I checked, they still use 1-based addressing for vectors and matrices in math.

    31. Re:Lua[0]? by Salgat · · Score: 1

      But it represents an offset. An index of 0 represents no offset from the start, 1 is a single offset from the start, etc. It makes perfect sense. I'm not saying using 1 as the start doesn't make perfect sense either, it's just a different way of representing the data.

    32. Re:Lua[0]? by alexo · · Score: 1

      It is recent computer scientists that started

      Not "computer scientists". Just C programmers. The first two languages designed, Fortran and Cobol, start at 1. Algol('68) and all the languages descended from or influenced by it let the programmer set the starting bound (this includes Ada, Pascal and all the other Wirth languages).

      Pretty much every language that uses 0 as the only allowable starting index is either descended from C, or borrowed large amounts of its syntax from it. (Some BASICs use 0, but that language is so egregiously unstandardized that its tough to say anything about it with certainty).

      That's because C does not have arrays, they are just syntactic sugar for pointers. array[index] is another way of writing *(pointer + offset)
      Therefore: a[5] == *(a+5) == *(5+a) == 5[a]

    33. Re:Lua[0]? by angel'o'sphere · · Score: 1

      I don't want C++ arrays to start at 1, I either want them to start arbitrary like in Pascal
      myNumbers : Array of Integer [-7 .. +13]
      or at 0, as in Java they start at zero as well ... and I can not do neat tricks there :D

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    34. Re:Lua[0]? by Greyfox · · Score: 1

      Arrays in C++ start at 0. I'm pretty sure you can set a pointer into the middle of the array in C++ and do this by indexing the pointer. I know you can do it in C -- a couple companies ago I deployed something that did that into production code, mainly to keep the design review board on their toes. They weren't, and it got deployed that way. I thought it made more sense that way anyway, so I never mentioned it. It's entirely possible it's already confused the hell out of a code maintenance guy, but hopefully he'll think it makes more sense that way too.

      --

      I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  7. APL: A Programming Language by Anonymous Coward · · Score: 3, Informative

    Requiring a graphics card and special character set to program in the language:

    Because of the unusual character set, many programmers use special keyboards with APL keytops for authoring APL code. Although there are various ways to write APL code using only ASCII characters, in practice, it is almost never done.

    http://en.wikipedia.org/wiki/APL_%28programming_language%29

    1. Re:APL: A Programming Language by msauve · · Score: 1

      I used to have a Centronics 761 teleprinter with an APL keyboard/charset. I never used it for APL, but it sure looked cool.

      --
      "National Security is the chief cause of national insecurity." - Celine's First Law
    2. Re:APL: A Programming Language by Anonymous Coward · · Score: 1

      I used such a keyboard on a DEC teleprinter terminal for APL programming. You have no idea how cool the language is... I had a circuit synthesis class in college a long time ago that required us to write a matrix exponentiation routine. Fellow students were struggling with FORTRAN and the like. It was a one-liner in APL.

    3. Re:APL: A Programming Language by Misagon · · Score: 1

      I find it kind of weird that while APL requires you to use proper symbols from mathematics and various branches of logic (binary, predicate, etc..), it doesn't have operator precedence that we are used to from mathematics and logic.

      Most languages have some cases where the precedence between operators is equal, but in those cases the evaluation order is almost always left to right. In APL, it is backwards: always from right to left.

      --
      "We mustn't be caught by surprise by our own advancing technology" -- Aldous Huxley
    4. Re:APL: A Programming Language by Darinbob · · Score: 1

      When it was new it didn't require stuff that was necessarily weird, because every machine was unique and thus weird. At the time there were lots of unusual keyboards out there. No graphics card required at all, these were just characters and even ASCII characters required special support to be displayed on a CRT. For a teletype you just needed a different type head and no graphics at all.

    5. Re:APL: A Programming Language by tgv · · Score: 1

      And the fact that APL evaluates from right to left. APL is QBASIC on LSD.

  8. question colon by Ken+D · · Score: 2

    Since this operator exists in C/C++, Java and Perl at least, it's hardly obscure

    1. Re:question colon by nedlohs · · Score: 1

      Probably why no one except you seems to think anyone claimed it was.

    2. Re:question colon by tanderson92 · · Score: 2

      Since this operator exists in C/C++, Java and Perl at least, it's hardly obscure

      It's called the ternary operator.

    3. Re:question colon by nedlohs · · Score: 2

      ?: is not a trigraph, which should be obvious since it doesn't have three characters in it.

    4. Re:question colon by Ken+D · · Score: 1

      Yeah my bad. Damn slideshow wouldn't run and of course it was after I hit submit that I was thinking "wait.. is that called trigraph or some other cryptic operator?"

    5. Re:question colon by nedlohs · · Score: 1

      Well I stand corrected on the "no one except you" bit. Apparently more than one anonymous coward also doesn't know that tri means three. Or maybe that graph mean character. Or maybe that ?: is only two characters...

    6. Re:question colon by bluefoxlucid · · Score: 1

      A ? B : C;

      ABC, ?:;

    7. Re:question colon by Fwipp · · Score: 1

      Trigraphs aren't ternary operators. Tri-graph roughly mean three-characters, so "??!" = "|".

      If a statement seems obviously wrong, maybe you don't understand it well enough.

    8. Re:question colon by Quirkz · · Score: 1

      Sadly, ternary doesn't actually start with "tri."

      I think it comes from old Norwegian, based on a decision-making process akin to flipping a coin, except it was throwing rocks at birds, and the decision was determined by which arctic tern was hit first.

    9. Re:question colon by lgw · · Score: 2

      More specifically, trigraphs solve the problem that Stroustrup's keyboard didn't have certain punctuation characters. (OK, a keyboard he used some of the time had this problem, being a Scandi keyboard that replaced odd punctuation with needed letters.) It's not crazy at all to have a conversion from "??!" to "|" when you're writing the language on a keyboard that doesn't have a "|" character.

      I believe that AND and OR are trigraphs for "&&" and "||" too - I always meant to try that, but was too lazy to hunt for the command line switch to enable them.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    10. Re:question colon by 91degrees · · Score: 1
      Unless I missed something, the article was talking about trigraphs rather than ternary.

      The following is valid C (probably)

      ??=define DOUBLE(x) ((x)+(x))

      int func(int i)
      ??<
      int array??(10??) - ??<1,2,3,4,5,6,7,8,9,10??>

      return array??(i??) ??' 0xFF;
      ??>

    11. Re:question colon by david_thornley · · Score: 1

      Technically, it's called the conditional operator, but since it's the only ternary operator in most languages it gets called as such.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    12. Re:question colon by spitzak · · Score: 1

      In Python you write "a?b:c" as "b if a else c". I think that is pretty obscure, and hard to read too.

    13. Re:question colon by fisted · · Score: 1

      Ternary.

    14. Re:question colon by jrumney · · Score: 1

      Let me help YOU: search for trigraphs on Wikipedia.

    15. Re:question colon by shutdown+-p+now · · Score: 1

      I'll grant you that it is 1) unusual for a PL and b) does not respect order of evaluation. But it is very easy to read. Sans comma, it's almost exactly how you say those things in many natural languages, including English.

  9. The idea of variant (var) by randomErr · · Score: 1

    I understand in some learning languages (Apple ][e flavor of Basic comes to mind) it can useful for beginners. But why have it languages like C#, VB,NET and even JavaScript? It would make everyone's life easier and most code run faster if you pushed your objects to strongly type variables.

    --
    You say things that offend me and I can deal with it. Can you?
    1. Re:The idea of variant (var) by Anonymous Coward · · Score: 3, Informative

      The "var" in C# is not a variant. It's simply a syntactic shortcut to allow the developer to not repeat the type in the declaration if the type can be inferred from the initialization expression. The behavior is identical to C++ "auto".

      var x = 1; // x is an int
      x = "1"; // compiler error, x is an int and cannot be set to a string

      var y; // compiler error, the type cannot be inferred
      var y = null; // compiler error, the type cannot be inferred

    2. Re:The idea of variant (var) by TheDarkMaster · · Score: 1

      Because variants are useful when you want to (or most common, you need to) make a generic function to handle some information where you have no way of knowing if the input parameter will be a string, integer, long, etc. Of course it is slower than dealing with a defined type, but is usually more convenient than trying to create a separate function for each possible entry type.

      --
      Religion: The greatest weapon of mass destruction of all time
    3. Re:The idea of variant (var) by i+kan+reed · · Score: 3, Interesting

      I can tell you why C# has it.

      The normal way intellisense works, you often have to do the end of your line of code then go back to the beginning to type out what type of variable the method you're calling returns now that you know. Var obviates this task by going "oh, of course, it's the type returned by this method".

      As usual with language features, it comes from us developers being very very very lazy people.

    4. Re:The idea of variant (var) by randomErr · · Score: 2

      I realize that but its seems a waste. My point was that you should already know your data types. I like the readability of strongly typed code. You also make you compiler and debugger work extra. On small stuff no big deal. But on large projects those extra compiling seconds can become minutes easily. Also I've had a few cases where when I've done compares on C# compiled code the strongly typed program usually came out smaller.

      --
      You say things that offend me and I can deal with it. Can you?
    5. Re:The idea of variant (var) by ThisIsSaei2561 · · Score: 1
      var var = "binks";

      ...I'm sorry.

    6. Re:The idea of variant (var) by Megane · · Score: 1

      So, in other words, it's just like the new 'auto' keyword from C++, except that C++ re-used an existing keyword so that people who had variables named 'var' wouldn't have to change their code?

      --
      #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
    7. Re:The idea of variant (var) by PRMan · · Score: 1

      Yeah, but they just added dynamic. Javascript is all dynamic, and many programmers prefer it.

      --
      Peter predicted that you would "deliberately forget" creation 2000 years ago...
    8. Re:The idea of variant (var) by tibit · · Score: 1

      "My point was that you should already know your data types." And you do. And the compiler does. It's somewhat silly to have to repeat yourself and type in the type twice. A literal has a fixed, known type, by definition. Types are also known and fixed in other circumstances, such as function return types. This becomes especially handy when a method returns a parametric type that may be hard to write. I've personally written expression template code where the specialized concrete type is a few lines long.

      Do you really claim you'd rater write [4 lines of type] foo = bar(); instead of auto foo = bar()? Even for shorter types, it can be arduous.

      This for (std::vector::const_iterator a = b.begin(); a != b.end(); ++a) vs for (auto a = b.begin(); a != b.end(); ++a)

      --
      A successful API design takes a mixture of software design and pedagogy.
    9. Re:The idea of variant (var) by turp182 · · Score: 1

      Regarding "var": Our C# standard (which is part of a couple of actual standards, iDesign's is one off the top of my head) is as follows:

      Var is only used if it is explicitly clear what the data type is when the variable is defined.

      So these are fine:
      var aString = String.Empty;
      var someVariable = new TypeOfSomeSort();

      The variable should be explicitly declared otherwise:
      string aString = SomeMethodThatReturnsAString();

      Of course I ignore the standard and just explicitly state the type, it's how I've always done it...

      var is handy for non-fetched Linq queries as well. Do a ToString() on it (if it is for a database operation) and you get the SQL that will execute.

      --
      BlameBillCosby.com
    10. Re:The idea of variant (var) by david_thornley · · Score: 1

      The "auto" feature in C++ is similar. There's two problems with "you should already know your data types". First, when using template programming in C++, you don't already know your data types. You're writing the code that will be instantiated with different data types at compile time. Second, data types in C++ can get pretty long to type, and at that point are effectively not read by humans and merely provide a chance to mess up.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    11. Re:The idea of variant (var) by qbast · · Score: 1

      First of all you are confusing strong typing and static typing. The word you are looking for is static typing. Some languages which are strongly typed are not statically typed.

      Secondly, the var keyword is still statically typed. It simply infers types based on the code. It is quite helpful and I wouldn't mind if java had it. For example, suppose you want a dictionary with a key of type string and a value of an IEnumerable of Tuples of strings and ints. This: var dictionary = new Dictionary>>();

      is much more readable than this: Dictionary>> dictionary = new Dictionary>>();

      Check lombok library. It adds implicit typing ('val a=new HashMap();') and lots of other syntactic sugar like auto-setters/getters, autogenerated constructors, extension methods and more.

    12. Re:The idea of variant (var) by david_thornley · · Score: 1

      Pretty much yes, as I understand it. In C++, "auto" was already a keyword, so nobody could use it as a variable name, and nobody used it as a keyword, since unspecified variables were "auto" by default, so it was a logical word to repurpose.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    13. Re:The idea of variant (var) by Half-pint+HAL · · Score: 1

      This for (std::vector::const_iterator a = b.begin(); a != b.end(); ++a) vs for (auto a = b.begin(); a != b.end(); ++a)

      Congratulations. You've just highlighted the weakness of the three-argument "for" statement. A weirdness that Google went and made worse in Go.

      --
      Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
    14. Re:The idea of variant (var) by shutdown+-p+now · · Score: 1

      "var" is strongly typed code. You're confusing "strongly typed" with "explicitly typed". This:

      >> Also I've had a few cases where when I've done compares on C# compiled code the strongly typed program usually came out smaller.

      Is plainly false - literally impossible - if by "strongly typed" you mean explicitly typed vs var.

      If you're so fond of explicit typing, are you also inserting casts every time you chain function calls? E.g. when you write Foo(Bar()) or Bar().Foo() - note how these also completely omit the return type of Bar; yet everyone is seemingly fine with that. Because the type is there, and it is still checked against the parameter type of Foo. But that is not at all different from:

      var x = Bar();
      Foo(x);

      Except that you give the name to the result of intermediate computation. If you're fine with chaining, then you should also be fine with this.

    15. Re:The idea of variant (var) by shutdown+-p+now · · Score: 1

      In C#, "var" (just like all the other keywords added since v1.0 of the language) is a "context keyword" - in other words, it is treated as a keyword only when it is a position where it can be meaningfully parsed as such, and the grammar is designed in such a way that no old valid code that used "var" as an identifier could have a meaningful interpretation of it as a keyword under new rules. Consequently, the following is perfectly valid C#:

      var var = 0;
      var += var;
      var x = var;

      In fact, if you write it in VS, it will correctly highlight the keyword "var" as a keyword, and the identifier "var" as identifier.

      OTOH, in C++, they have actually reused the existing keyword in an incompatible way. It used to be legal to write something like "auto int x = 0" in C++03 - it was utterly meaningless, and there was no instance where adding "auto" would actually change the meaning of the declaration, so no-one did it - but it was legal, and in theory someone might have done it just cuz, and be broken by C++11.

      C# is actually one of the most backwards compatible languages that I know of. They do occasionally introduce true breaking changes (like foreach loop variable scope in C# 5.0), but this is extremely rare, and most additions are very carefully designed to allow the old code to compile with no semantic changes. Heck, even for breaking changes, it takes them ages to actually decide to change it... e.g. with the foreach change, the problem first appeared in C# 2.0 (when they first added closures, and with them the ability to close over the loop variable), and it took them three major versions to finally bite the bullet and fix it - and even then only after a thorough investigation showed that most code that is affected by the change, is in fact broken code (that people didn't notice is broken) that would be fixed by the change.

    16. Re:The idea of variant (var) by shutdown+-p+now · · Score: 1

      "dynamic" in idiomatic C# is rare, but still very useful for those cases where you do have to interop with some data structure with a dynamic schema (e.g. JSON). But the main reason why they added it was in fact easy interop with COM IDispatch, and dynamic languages like Python or Ruby. So you usually have it at the transitional boundary or at the site where you crack open the data, but from there you stick it into something strongly typed.

  10. Perl: TMTOWTDI by i_want_you_to_throw_ · · Score: 5, Insightful

    I used to think that Perl's feature of "There's More Than One Way To Do It" was great until I had to start modifying and maintaining the code of other developers, (several over the years). 20+ years I've been with Perl and I gotta say that through the years this has probably caused me more frustration than anything. Python, comparatively speaking, is a dominatrix and I'm starting to enjoy "There's Only One Way To Do It".

    1. Re:Perl: TMTOWTDI by mark-t · · Score: 2, Interesting

      I think I'd have to agree with this. I never nailed it down to that particular aspect of perl before now, but I can easily see how this characteristic of perl makes it very difficult to identify idioms in the language. With so many ways to do things that you can't always quickly identify what is being done simply by looking at the source code, unless it has been quite rigorously commented.

      Code written in an idiomatic style rarely needs much commenting, because people familiar enough with the language to do what the code needs to accomplish will also be familiar with the idioms in the source code, and in practice, only minute or two of examining the source code fragment is ever necessary, even for code that has never seen before, have a general understanding of what the code is trying to accomplish, even if they do not necessarily understand the bigger picture of how the code is being used.

      Of course, it's entirely possible, and not even particularly hard, to write obsfuscated code in almost any language, but with perl, my experience is that it takes a special kind of discipline to *NOT* write such code, while at least in other languages, in my experience, writing in a readable style tends to require only a modest amount of discipline.

    2. Re:Perl: TMTOWTDI by i+kan+reed · · Score: 4, Interesting

      You just haven't run into another python developer who's "clever" enough yet.

      for a,b,c,d in [x.q for x in y if x.z]+[x.r for x in y if x.z]:
              a.m=b or c and d

      (none of these variables are boolean)

    3. Re:Perl: TMTOWTDI by tompaulco · · Score: 2

      I used to think that Perl's feature of "There's More Than One Way To Do It" was great until I had to start modifying and maintaining the code of other developers,

      Maintaining the code of others? Heck, I have found in perl, that it was easier to rewrite a program than try to debug it even if I wrote the original program.

      --
      If you are not allowed to question your government then the government has answered your question.
    4. Re:Perl: TMTOWTDI by preaction · · Score: 1

      I thought someone would mention "lists" vs. "arrays" in Perl, and how @_ is really just an alias onto the current Perl stack. "list context". Types are declared by the operation being performed, not the data stored in the variable. The fluid definition of "compile time" and "run time" and how you can switch between the two.

      I'm sure I could come up with more reasons I love Perl, but they'd all sound like reasons to avoid it like the plague.

    5. Re:Perl: TMTOWTDI by david_thornley · · Score: 1

      Yeah. I tended to get confused by the fact that, say, element 3 of the array @A (you know A's an array by the "@") (I'm assuming you're over being confused by Perl's use of sigils to show whether a variable is a scalar, a list or array, a dictionary, a typeglob, and I may be forgetting one or two) is $A[3], which is a scalar from the $, and you know it's an array reference and not a dictionary reference because the 3 is inside square brackets rather than curly braces.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    6. Re:Perl: TMTOWTDI by schitso · · Score: 1

      Is it bad that that doesn't look all that confusing to me? Though it seems like having two list comprehensions that are exactly the same save for the property of "x" that they access is inefficient.

    7. Re:Perl: TMTOWTDI by i+kan+reed · · Score: 1

      Seems inefficient, but it's not really possible to reconstruct the exact behavior without more lines of code(i.e. less "cleverness")

    8. Re:Perl: TMTOWTDI by Darinbob · · Score: 1

      I found the Python style to be some what odd myself. Not only is there only one way to do it, but if you actually do it a different way there will be an army of purists to chase you down with tar and feathers. (technically not true, Python has many ways to do the same thing)

      A language with really only one way to do things is in my view, a limited language with no flexibility. Granted better than Perl, but the argument of "but Perl!" is not good enough to justify the rigidity of thinking.

    9. Re:Perl: TMTOWTDI by dotancohen · · Score: 1

      That list comprehension is actually very much the reason why Python is terrific. C# programmers will be familiar with the idea from Linq.

      for: This is a for loop
      a,b,c,d: Each value of the iterator is itself composed of 4 values. In Python this is called a tuple, but you can think of it as an array if it helps. The first value is bound to a, the second to b, etc. Thus, the variables a,b,c, and d are defined in the loop body.
      in: The next thing mentioned is the iterator
      [x.q for x in y if x.z]+[x.r for x in y if x.z]: This iterator is a mess, let's look at it's parts, which are:
      [x.q for x in y if x.z]
      +
      [x.r for x in y if x.z]:

      [x.q for x in y if x.z]: y is an iterator. Return only the q property of each item in y, only if the z property is defined. This results in a list (another Python datatype which you can think of as an array) being return, of q properties.

      [x.r for x in y if x.z]: y is an iterator. Return only the r property of each item in y, only if the z property is defined. This results in a list being return, of r properties.

      +: Combine the list of q properties with the list of r properties.

      Like learning another (human) language, it it incomprehensible at first. However, I'm no Pythonista and even for me it was very simple to figure out what this does.

      --
      It is dangerous to be right when the government is wrong.
    10. Re:Perl: TMTOWTDI by dotancohen · · Score: 1

      Maintaining the code of others? Heck, I have found in perl, that it was easier to rewrite a program than try to debug it even if I wrote the original program.

      I've often heard of Perl being referred to as a write-only language.

      --
      It is dangerous to be right when the government is wrong.
  11. java events by bumba2014 · · Score: 1

    Java Events, need a whole new class to handle them...

    1. Re:java events by ubersoldat2k7 · · Score: 2

      Not any more with lambdas:


      button.setOnActionEvent(e -> doSomethingWith(e));

    2. Re:java events by bumba2014 · · Score: 1

      still looks strange, but at least an improvement...

    3. Re:java events by viperidaenz · · Score: 1

      or a proxy, or an instance of any class that implements the event listener interface.

    4. Re:java events by shutdown+-p+now · · Score: 1

      Why does it look strange? It's the standard mechanism adopted by every single mainstream PL by now.

      And how would you handle them otherwise? Do you prefer just passing in a function pointer / method reference? You can do it too in Java 8, it would be something like SetOnActionEvent(this::eventHandler).

  12. Slideshows... by QuietLagoon · · Score: 1

    I think the trend on the web towards using slideshows when prose would work better is really quirky. Since each slide acts like a page hit, slideshows are a good way to drive up the ad revenue that is based upon page hits....

  13. Nastiest? by whitroth · · Score: 1

    The alter command in COBOL.

    Lo, these many years ago, when I'd just read it in a manual, and discussed it with my boss (who would have given Dilbert's a run for his money, but...) and asked him if he'd defenestrate anyone using it before or after firing them, and he told me before.....

                        mark

  14. C++03 had one that was corrected in C++11. by sconeu · · Score: 3, Interesting

    Namely, the >> symbol. Because templates use angle brackets for template parameters, if you had a nested template such as T<int, T1<double> >, you HAD to put the space between the two closing angle brackets. Otherwise the lexer would interpret the two angle brackets as the shift operator.

    --
    General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    1. Re:C++03 had one that was corrected in C++11. by Anonymous Coward · · Score: 1

      The behaviour is more quirky now. As >> is still a single lexical element, and not two (unless I'm mistaken, it's been a while since I looked at the C++11 standard). It's only two if you insert the space. However, the single lexical element, >>, can be treated by the parser as two angle brackets if it's used for a nested template. It makes sense for the preprocessor to take as many characters as possible for an object, as otherwise ab would be two identifiers, a and b, and >== would be three.

    2. Re:C++03 had one that was corrected in C++11. by david_thornley · · Score: 1

      Which means that, if you're using the right-shift operator inside a template heading (and that's legal because you can specialize on numbers), you have to parenthesize the expression to avoid syntax errors.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    3. Re:C++03 had one that was corrected in C++11. by Barlo_Mung_42 · · Score: 1

      I work in a shared code environment. Visual Studio has no issue with nested templates without the space. But I still have to add the space so my Mac friends down the hall stay happy.

    4. Re:C++03 had one that was corrected in C++11. by flargleblarg · · Score: 1

      Namely, the >> symbol. Because templates use angle brackets for template parameters, if you had a nested template such as T<int, T1<double> >, you HAD to put the space between the two closing angle brackets. Otherwise the lexer would interpret the two angle brackets as the shift operator.

      That's a really dumbass lexer. Glad that shit got fixed.

    5. Re:C++03 had one that was corrected in C++11. by flargleblarg · · Score: 1

      That's a really dumbass lexer. Glad that shit got fixed.

      Or should I say... a really dumbass parsing layer to go and use a lexer that doesn't understand the local context when it constructs a lexeme from the input stream.

  15. Column Position Requirements in FORTRAN 77 by EmagGeek · · Score: 1

    I'd say that the column position requirements in FORTRAN 77 take the cake.

    1. Re:Column Position Requirements in FORTRAN 77 by Anonymous Coward · · Score: 1

      That was fine and useful back in 1977 when people were still using Hollerith Cards.

      Those blank columns were used to number the cards in case you dropped the stack. And the first column was for a comment.

  16. Many languages and... by bobbied · · Score: 2

    That pesky ";" statement terminator... I guess you had to uses something, but it causes me the most trouble..

    C, C++, Pascal, Perl, Java, C#, bash/sh, ksh, JavaScript..... The list goes on..

    --
    "File to fit, pound to insert, paint to match" - Aircraft Maintenance 101
    1. Re:Many languages and... by the+eric+conspiracy · · Score: 2

      It's not a quirk if pretty much every fukin language does it.

    2. Re:Many languages and... by xvan · · Score: 1

      for bash / sh, the ; is not mandatory... What else do you propose to separate to commands in the same line?

    3. Re:Many languages and... by Megane · · Score: 3, Interesting

      Well, whether ';' is a statement terminator (like in C) or a statement separator is one thing.

      But Javascript takes it to a whole new level. You can decide not to put them in, and if you break your lines a certain way, you may get the effect of a semicolon where you didn't expect one. And this is part of the language specification.

      --
      #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
    4. Re:Many languages and... by Anonymous Coward · · Score: 1

      One of the few decisions which are known to be correct. Separator errors are far more common than terminator errors.

      (Separators are placed between statements, which means there's no separator after the last statement. Programmers tend to get confused what exactly counts as a/the last statement inside if-else statements. With terminators, all statements are equal)

    5. Re:Many languages and... by Megane · · Score: 1

      Grrrr, I meant to say "statement separator (like in Pascal)"

      Anyhow, if you prefer to not religiously bracket your if/else conditions, the behavior of semicolons in your language can cause problems.

      --
      #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
    6. Re:Many languages and... by fermion · · Score: 1

      The line terminator in C and C++ are pretty easy to find and fix. The conventions in FORTRAN are much more difficult to fix as the errors are non nonsensical. On of the first things I learned when I learned to code is a page of errors meant you had a mismatched type in a subroutine.

      --
      "She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
    7. Re:Many languages and... by jader3rd · · Score: 1

      That pesky ";" statement terminator... I guess you had to uses something, but it causes me the most trouble..

      C, C++, Pascal, Perl, Java, C#, bash/sh, ksh, JavaScript..... The list goes on..

      They should have used the '.' character to end a statement. It's the same one used in written language.

    8. Re:Many languages and... by jader3rd · · Score: 1

      It's not a quirk if pretty much every fukin language does it.

      Yes, but if you're learning your first programming language you wonder why the end of statement character differs from the same one that you use when writing.

    9. Re:Many languages and... by EmperorArthur · · Score: 1

      Anyhow, if you prefer to not religiously bracket your if/else conditions, the behavior of semicolons in your language can cause problems.

      Some people hate this because brackets "clutter" the code, but Apple's goto fail bug was caused by a developer accidentally duplicating a line, and not bracketing the if() statement.

      --
      So lets pretend that we've just completed writing this code, as opposed to having just completed sabotaging it -Altera
    10. Re:Many languages and... by The+MAZZTer · · Score: 1

      Oh JavaScript is fun with that, because it's optional, which means even if you want to continue onto the next line, if a line is a valid standalone statement it will imply the ; terminator.

      Example:

      function() { return
      true; }

      This stumped me for a bit.

    11. Re:Many languages and... by david_thornley · · Score: 1

      Two reasons not to do that. First, "2." in at least some of those is a floating-point 2, so "i = 2." by itself would be ambiguous: does this assign an integer 2 and end the statement, or assign a floating-point 2. (and writing 2.0 doesn't really clarify, but rather raises the question of whether the 0 starts another statement). Second, all the old COBOL programmers who escaped that ecosystem would have something like anti-LSD-style flashbacks, and that can be dangerous.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    12. Re:Many languages and... by david_thornley · · Score: 1

      If the line had been bracketed with the brackets on the same line, duplicating the line would have done the exact same thing. If not, it would have made the function longer and harder to read. Can't win.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    13. Re:Many languages and... by LanceUppercut · · Score: 1

      Well, it is your fault entirely. Real C programmers know how to write C programs without using `;` at all. Here's an example for you

      int main()
      {
            if (puts("Hello World!")) {}
      }

      See?

    14. Re:Many languages and... by jader3rd · · Score: 1

      Two reasons not to do that. First, "2." in at least some of those is a floating-point 2, so "i = 2." by itself would be ambiguous: does this assign an integer 2 and end the statement, or assign a floating-point 2. (and writing 2.0 doesn't really clarify, but rather raises the question of whether the 0 starts another statement). Second, all the old COBOL programmers who escaped that ecosystem would have something like anti-LSD-style flashbacks, and that can be dangerous.

      That's still workable. A period followed by an end of line, or whitespace is the end of statement. A period that's between two numbers is a floating point number. A period surrounded by non-numbers and non-whitespace is a compilation error. I realize that the ship might have sailed as far as this is concerned, but if done originally I think it would have helped a lot of people ramp up on how to code.

    15. Re:Many languages and... by Darinbob · · Score: 1

      Pascal used ";" as statement separator I thought, not a statement terminator. This is true for many from the ALGOL family. Which meant that having a final semicolon before a closing block would lead to a syntax error (though later versions certainly relaxed this rule).

    16. Re:Many languages and... by shutdown+-p+now · · Score: 1

      In Pascal it actually made some sense, since the main program was wrapped in begin .. end. - with a terminating period. So the entire program was the "sentence".

    17. Re:Many languages and... by shutdown+-p+now · · Score: 1

      You can also cheat it by introducing a null statement that consists of zero tokens; then "a;" is really the same as "a;null", and it's still a separator - even if it behaves as a terminator in practice.

      It's a useless trick in a statement-oriented language, but in expression-oriented ones, where it's all expressions and not statements, it's useful to be able to define";" as the sequencing operator that evaluates left side first and right side second, and then returns the right side.

    18. Re:Many languages and... by Gunstick · · Score: 1

      I love all languages which do not require the ;
      So why bash, ksh and javascript listed?
      If you do one liners, you need the ; but on separate lines the newline does the job as well.
      Probably a reason why I may try to lean python. No ; there.

      --
      Atari rules... ermm... ruled.
    19. Re:Many languages and... by Eunuchswear · · Score: 1

      Maybe you'd better stick to Cobol then.

      --
      Watch this Heartland Institute video
  17. golang: iota by bwhaley · · Score: 1

    The iota enumerator in Golang is elegant and unique. Writing idiomatic Golang code is so implicit in the language itself that I've been able to easily read almost any Go code I find.

    http://golang.org/doc/effectiv...

    --
    "I either want less corruption, or more chance
    to participate in it." -- Ashleigh Brilliant
    1. Re:golang: iota by shutdown+-p+now · · Score: 1

      How is iota any better than the conventional C-style enum syntax (or better yet, true ADTs), other than being quirky?

  18. Re:Prolog by CodeArtisan · · Score: 1

    Pretty much the entire language of Prolog..

    How many Prolog programmers does it take to screw in a lightbulb?

    Yes.

  19. + operator for string concat? by jfbilodeau · · Score: 3, Informative

    How is that a language quirk for JavaScript? The + operator has been used for string concatenation in a number of programming languages (C++, Java, Python...) long before JavaScript. It is still implemented as such in newer programming languages like C#.

    --
    Goodbye Slashdot. You've changed.
    1. Re:+ operator for string concat? by TheDarkMaster · · Score: 4, Insightful

      The difference is that the "+" operator in a strong-typed language works without causing nasty surprises for you.

      --
      Religion: The greatest weapon of mass destruction of all time
    2. Re:+ operator for string concat? by Jamu · · Score: 1

      "one" + "two" = "three"?

      --
      Who ordered that?
    3. Re:+ operator for string concat? by PRMan · · Score: 1

      Also in VB, although they have recently changed it to &.

      --
      Peter predicted that you would "deliberately forget" creation 2000 years ago...
    4. Re:+ operator for string concat? by Anonymous Coward · · Score: 1

      The + operator for JavaScript mentioned is for converting strings to numbers:

      typeof( '12' ); // prints "string"
      typeof( '1' + '12') // prints "string"
      typeof( + '12' ) // prints "number"

      Confusion such as yours is precisely why it was mentioned. :-)

    5. Re:+ operator for string concat? by phantomfive · · Score: 1

      Because of the lack of strong typing. It's fairly common for programmers to try something like this:

      total = price + tax

      And end up with total being a string like: "50.237.25"

      Then you start seeing code that forces it to numbers, like

      price = price + 0.0
      tax = tax + 0.0
      total = price + tax

      It's kind of funny, but not really a big deal.

      --
      "First they came for the slanderers and i said nothing."
    6. Re:+ operator for string concat? by ubersoldat2k7 · · Score: 1

      This is why I find JavaScript such a dangerous language. I mean, if you can fuck this up:


      var a = "1";
      var b = 1;
      a + b; // gives you "11"

      Imagine the crapfest a complex application would mean.

      P.S: For any JS fanboy, here's the Python way of handling this:


      TypeError: unsupported operand type(s) for +: 'int' and 'str'

    7. Re:+ operator for string concat? by heson · · Score: 1

      Yes "clever" operator overloading comes up high in my list.
      Scripting languages are full of it like in Pike: str/" " Divide a string by space to get an array of the words.
      But I dislike it way more when operator overloading abuse is done in user code than when it is a language construct.

    8. Re:+ operator for string concat? by evenmoreconfused · · Score: 1

      Actually IIRC '+' was used for string concatenation in the version of PC-BASIC included in the firmware of all the original (1980) IBM PCs. But apparently it wasn't in the original (1973) Wang 2200 BASIC that at least some of us first learned BASIC on.

      See the third example here: http://www.wang2200.org/basic_...

      I was trying to look up some of my earlier languages (WATFIV and IITRAN in my case), but I can't find any detailed documentation on the web.

      --
      No. Well...maybe. Actually, yes. It really just depends.
    9. Re:+ operator for string concat? by angel'o'sphere · · Score: 1

      C++ never used + as string concatenation.
      Except you write your own string class and overload the + operator (did they do tat in std::string? std::string is imho younger than JavaScript)
      It is a huge difference it if it is an operator in a class, like in a C++ String class or a feature handled by the compiler/interpreter as in Java/C# (compiler) and JavaScript (interpreter).
      For JavaScript it is a quirk as it is inconsistent and behaves completely different depending on what is left and right from the operator +.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    10. Re:+ operator for string concat? by asylumx · · Score: 1

      "1" + 1 in Java or C# will give you 11 just like it does in Javascript. I don't understand why Javascript is getting blamed for this one.

    11. Re:+ operator for string concat? by Yunzil · · Score: 1

      You missed the point. It's not just concatenating strings, it's concatenating strings and... things that aren't strings. In C++ you can't add a string and an int (well, you can but you have to go out of your way to do it). You will get a long-winded error about not having a '+' operator that takes arguments of those types.

    12. Re:+ operator for string concat? by Jaime2 · · Score: 1

      Also in VB, although they have recently changed it to &.

      Recently, as in 1995 (it was introduced in VB4)? Having a distinct string concatenation operator has been a strength if VB for a very long time, however it does the same type coercion that JavaScript does. But, at least you don't look at it and assume it's doing addition.

    13. Re:+ operator for string concat? by turp182 · · Score: 1

      Holy shit, you are correct. In fact there's more to it than what you described.

      Here's some C# code, the last examples (z, z2) really bother me (in those cases the string was cast to a number):

                              int i = 1;
                              string j = "1";
                              double k = 1.15;

                              var x = "1" + 1; // string "11"
                              var y = i + j; // string "11"
                              var x2 = j + i; // string "11"
                              var z = k + i; // double 2.15
                              var z2 = i + k; // double 2.15

      --
      BlameBillCosby.com
    14. Re:+ operator for string concat? by narcc · · Score: 2

      So, you think js sucks because, if you're a total moron, you'll do dumb things?

    15. Re:+ operator for string concat? by narcc · · Score: 1

      Randomly?

      Look like you don't understand the basics of how the language works.

      You can't blame that language for your gross incompetence.

    16. Re:+ operator for string concat? by david_thornley · · Score: 1

      Use the standard string class. That's what it's there for. Unless you have really special needs, don't write your own, it'll just make your program harder to read.

      And, yes, given std::string s1, s2;, you can write s1 + s2, s1 + "s2", "s1" + s2 and it'll be string concatenation, but "s1" + "s2" doesn't do anything useful (and is, I think, undefined behavior).

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    17. Re:+ operator for string concat? by david_thornley · · Score: 1

      On the other hand, "1234" + 2 is legal C and C++. It returns a char * that points to the 3, so if you print it you'll get "34".

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    18. Re:+ operator for string concat? by jfbilodeau · · Score: 1

      I beg to differ ;)

      int x1 = 10;
      int x2 = 20;

      String message = "Total: " + x1 + x2;

      --
      Goodbye Slashdot. You've changed.
    19. Re:+ operator for string concat? by Tablizer · · Score: 1

      I wonder what the heck the designers of JavaScript were thinking when they added that feature. Did they fail to consider to consequences in a dynamically typed language, or did they judge "matching Java conventions" to be more important than utility alone (for marketing and/or familiarity to reduce the learning curve)?

      I'd like to see the mental mistakes documented so that future language designers don't make similar mistakes.

    20. Re:+ operator for string concat? by wiredlogic · · Score: 1

      I would say it's more of a quirk in both Java and Javascript because they eschew operator overloading in the name of some notion of academic purity and then they go and implement special semantics for the '+' operator that you can't replicate with a user defined type. Same with C++'s abuse of literal 0 before the advent of nullptr.

      --
      I am becoming gerund, destroyer of verbs.
    21. Re:+ operator for string concat? by Darinbob · · Score: 1

      That was added I think mostly to whine that JavaScript isn't strongly typed. The "+" itself or its behavior is in no way weird or unusual in languages, except for those who feel only strongly typed languages should exist. And here I am defending a language I don't like...

    22. Re:+ operator for string concat? by angel'o'sphere · · Score: 1

      That where my words.
      "s1" + "s2" is not really undefined, in C it would add the two pointers (addresses) pointing to the tow literals. On C++ or modern C (ANSI C after 99) it might be a compiler error. (because it implicitly converts addresses into ints).

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    23. Re: + operator for string concat? by narcc · · Score: 1

      The language behaves in a non-deterministic way and this is my fault?

      The language does NOT behave in a non-deterministic way. That you believe it does IS your fault.

      Yeah, it's not language's fault that you didn't bother to learn it.

    24. Re:+ operator for string concat? by pspahn · · Score: 1

      Well, + is addition in PHP, not concatenation.

      I know it's kind of bastardy, but I would expect to get 2 from that in PHP, since the 1 might have come from a database type INT and the "1" might have come from user input as a string, and your intention is to add them.

      I will certainly agree that casting to a type in PHP feels like voodoo. Sometimes you need to, most of the time you don't. It's those "sometimes" that mess you up debugging since the type is often the last thing you think of as the problem.

      --
      Someone flopped a steamer in the gene pool.
    25. Re:+ operator for string concat? by viperidaenz · · Score: 1

      long before? Java and Javascript both came out in 1995

    26. Re:+ operator for string concat? by Carnildo · · Score: 1

      The problem isn't the lack of strong typing in JavaScript. The problem is the combination of dynamic typing and operator re-use.

      In Perl, I can tell you at compile time what "5 + $val + 5" will return: a number 10 greater than the numeric value of $val (and there are clear rules for converting strings to numbers). In JavaScript, I can't tell if "5 + val + 5" will be a string value or a numeric value, except by carefully tracking the possible data flows for "val" and seeing if it comes from a string source or a numeric source (or worse, both string and numeric sources).

      --
      "They redundantly repeated themselves over and over again incessantly without end ad infinitum" -- ibid.
    27. Re: + operator for string concat? by narcc · · Score: 1

      If you were better at interpreting text and had dealt more with the case described, you would have understood what I mean by random is that there is no way to say with certainty what the interpreter will do since there's no telling for sure if he will treat the "+" operator as a sum of integers or a concatenation of strings.

      It's like I'm talking to a wall.

      There IS a "way to say with certainty what the interpreter will do". You just haven't taken the few minutes required to find out how!

      It's happened to me more than once

      Then you're either ridiculously lazy or a complete moron. You'll find that if you actually learn the language before you use it, you won't struggle with simple things.

      Again, it's not the language's fault that you're unwilling or unable to learn how it works!

    28. Re: + operator for string concat? by narcc · · Score: 1

      No, you didn't. You still don't know how the + operator works. You just came up with a convoluted way to avoid learning how it works.

      If you had actually learned how the + operator works, you wouldn't say ridiculous things like "random" or "there is no way to say with certainty what the interpreter will do".

      Perhaps you shouldn't post about things you know nothing about. If nothing else, when someone points out how ridiculous you sound, you read the docs to make sure that you're not continuing to spread nonsense.

    29. Re: + operator for string concat? by narcc · · Score: 1

      So you rescind your claims that "the language behaves in a non-deterministic way" and "there is no way to say with certainty what the interpreter will do since there's no telling for sure if he will treat the "+" operator as a sum of integers or a concatenation of strings"?

      That's what this whole thing was about, after all. If you're willing to accept that those nonsense claims are total nonsense, then we're in complete agreement.

      If you're not, then you're 100% wrong when you claim to "know how the '+' operator works".

      I wonder, as you double-down on your lunacy:

      The ugly hack I mentioned earlier just makes sure that a given string variable will be interpreted as a string when I need it to be a string"

      You wouldn't need your "ugly hack" if you knew how the + operator worked, after all.

    30. Re: + operator for string concat? by narcc · · Score: 1

      Well, I try again: I said the behavior of the "+" operator in Javascript is non-deterministic because you have no way to guarantee the type of the variables involved

      Nice change. (You never said that! At least you're trying to learn from your mistakes.) Of course, all it does is make you look like an idiot. 1) because you don't know what the term "non-deterministic" means 2) because variables in JS don't have types, values do.

      Let me guess: You're an autodidact?

      (and therefore the hack to ensure that what should be a string remains a string so that the operation using the "+" return the expected result for a string).

      This has been driving me crazy. Since when is an explicit cast an "ugly hack"? How long have you been programming, half an hour?

    31. Re:+ operator for string concat? by shutdown+-p+now · · Score: 1

      JS sucks because it won't tell you that you're being a moron. Since that's where most people start their careers, using a language like JS (or PHP) leads to them believing that their moronic habits are really "best practices" and such, and results in heaps of unmaintainable code.

    32. Re:+ operator for string concat? by shutdown+-p+now · · Score: 1

      Of course JS knows what types A and B are, it just happens at runtime. The behavior is fully deterministic every time, it just so happens that it varies with inputs, and therefore can differ for subsequent evaluations of that same expression (but, again, every particular evaluation is still deterministic).

    33. Re:+ operator for string concat? by shutdown+-p+now · · Score: 1

      Your last two examples add together an int and a double - where did you see any string there, much less an implicit cast?

      C# will indeed let you apply + to an arbitrary object, so long as another operand is a string, and will convert that other object to a string by calling ToString on it (or using an empty string if it's null). This is the same behavior as Java. It is bad, but not so bad as JS, in which strings can also magically become numbers on the right context.

    34. Re:+ operator for string concat? by shutdown+-p+now · · Score: 1

      It's not undefined - it won't even compile. Pointer arithmetic does not allow the addition of two pointers - the operation is meaningless. You can subtract a pointer from another pointer (the result being an integer difference), or you can add an integer to a pointer. This is definitely true for any version of ANSI/ISO C (including those before C99). I think it's also true for K&R C.

    35. Re:+ operator for string concat? by shutdown+-p+now · · Score: 1

      Unfortunately, he's right in that many other languages have adopted the same rule, that if one operand of + is a string, the other can be anything and will be turned into a string. Java and C# are two particularly prominent abusers.

    36. Re:+ operator for string concat? by shutdown+-p+now · · Score: 1

      This is not what "deterministic" means, though. Deterministic means same inputs given same outputs. In your case, you're getting different inputs.

      The difference that you're describing is compile-time determinism vs runtime determinism.

    37. Re:+ operator for string concat? by flargleblarg · · Score: 1

      Yes "clever" operator overloading comes up high in my list. Scripting languages are full of it like in Pike: str/" " Divide a string by space to get an array of the words. But I dislike it way more when operator overloading abuse is done in user code than when it is a language construct.

      So, if you take that array of words and multiply it back by " ", do you get the original string? Because that would make it cool.

    38. Re:+ operator for string concat? by angel'o'sphere · · Score: 1

      You are right of course, I simplified to much.
      In K&R C however function arguments have no (enforced) types. Everything is considered to be a 'thing' that fits into a register. Never actually tried it, but with casts you certainly can add pointers or multiply them if you wanted.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    39. Re:+ operator for string concat? by shutdown+-p+now · · Score: 2

      In K&R C however function arguments have no (enforced) types. Everything is considered to be a 'thing' that fits into a register.

      I think you're confusing K&R C with B. It's B which doesn't really have types at all other than "machine word".

      Function arguments in all versions of C always had types. I think that what you're referring to here is that it is possible in C (ANSI as well as K&R, actually) to call a function without having it declared at all, or having it declared but without specifying the argument list (when parens are empty - this necessitated the later use of (void) argument list to declare true argument-less functions in ANSI). When you do that, there are some implicit promotions that happen before the call known as "default argument promotions" - e.g. any integral type shorter than int is promoted to int, and float is promoted to double. However, after those promotions, the formal argument types for the function that you're calling must match the types of the actual arguments you pass in there - even though there's no compiler diagnostic for it (since, well, it doesn't know the prototype at the point of the call), any mismatch is undefined behavior. The only exception is that you can pass signed int/short/long where unsigned int/short/long is expected, and vice versa, but only if the value you're passing is representable in both types; and you can pass char* in place of void* (+/- any cv qualifiers) and vice versa. Anything else is U.B. In particular, passing a char* where int is expected is U.B.

      With casts, you can of course cast two pointers to ints, and then do whatever you want with them. This makes sense, since you're not doing pointer arithmetic then, it's just the standard operator + defined for ints with appropriate semantics. But the original discussion was in the context of trying to concatenate two C strings (i.e., char* pointers), which will not compile with any version of C.

    40. Re:+ operator for string concat? by TheDarkMaster · · Score: 1

      *clap clap clap* What a big moderation system failure we have here... "The Dumb Guy" (a freak from another topic, nothing with the "shutdown now") seens to have friends with infinite mod points. Well done ./ well done. (sarcasm)

      --
      Religion: The greatest weapon of mass destruction of all time
    41. Re:+ operator for string concat? by angel'o'sphere · · Score: 1

      Function arguments in all versions of C always had types.
      I believe that is wrong, but I can later check my book.

      In K&R you wrote it more or less like this:
      func(arg1, arg2, arg3)
      int arg1, char arg2, tSomeType* arg3 // semicolon needed here?, don't think so
      { // your code here // the types in the second line of the function definition are only a reminder for the coder, they are not enforced by the compiler whatsoever and unknown to the outside world // headers did not have those types ...
      }

      But time to get home and get my book, funnily I had it my hands on saturday and considered if I should throw it away but kept it for historical reasons (it is a controversial "bad" german translation, if it was an original I would never had considered to throw it away)

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    42. Re:+ operator for string concat? by shutdown+-p+now · · Score: 1

      Yeah, the syntax was like that.

      I think you might be right in that the compiler didn't enforce the types at the point of the call. But I'm still fairly sure that a type mismatch was undefined behavior, and if you somehow got it working, it would not be guaranteed to be working henceforth. It was certainly not just one parameter = one word, since K&R already had long and float and double, and those would normally be wider than a word on most machines of that time

        So basically, types were always there, but type checks weren't.

      When they added ANSI-style function declarations, you could actually have parameters listed with their types, and that was checked... but for compatibility they still retained the old-style function calls without seeing the definition, where you had to match the arguments carefully.

    43. Re:+ operator for string concat? by angel'o'sphere · · Score: 1

      Well, I digged a bit into it last days. But I'm "on the road again"
      I used Aztec C on an Apple ][ at home (and school) in 1985/1986. Perhaps Atztec C was a bit more nasty, not sure.
      I only remember (and wanted to investigate over the next days) that there regulary where errors in my code, type related. However that as well can be because I was unexperienced.
      Later around 1989 I worked mainly with Ansi C, not sure if it was already called like that, on Sun 3 Workstations, we did not have Sparc yet.
      For historical reasons it is interesting to figure what exactly the differences where (besides promoting etc.)
      The 'problem' with Aztec C might have been, that it 'emulated' a 16 bit processor with 6502 code, don't remember if the sizes between short, int and long even differed, or in what extend. The generated 6502 code looked awfull :)
      The main reason why I stopped using it was that it was so slow in turn around times: it generated .asm files, assembled them to .o files, it in fact used .a files for libraries, erm, archives, it had .lib files, too! So a simple hello world took minutes to compile, obviously considering it was done on a 5 1/4" floppy disk.
      Pascal on the other hand (UCSD Pascal, not the shortly later introduced Turbo Pascal) was very quick with its 'integrated environment'.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  20. In VHDL you use loops to write code :) by Obscene_CNN · · Score: 1

    In VHDL and Verilog you use loops to write code :)

    --
    I don't want to do a sig now
  21. Ruby and string/symbols by Parker+Lewis · · Score: 2

    I started with Ruby about 1 year ago. And until now, work with strings and the symbols is not natural yet to me. I mean, most of the languages I handled until now have only strings.

    1. Re:Ruby and string/symbols by rwa2 · · Score: 1

      Heh, yeah, I'm surprised I haven't seen more Ruby yet in this thread, esp. with the proliferation of Chef and gems and rvm and other parts of that ecosystem to keep it puttering along.

      For a language that seems to pride itself on its complete OOP-ness, there's so much syntax and different ways of accessing that syntax. I had wondered where all of the PERL masochists had gone...

      In my limited experience wrangling with Ruby, it seems very schizophrenic... at once it's supposed to be very clean, yet it's so littered with syntactic sugar. The "best practices" guidelines always seem to be changing, so a common pattern one year will be an anti-pattern the next. There's a little cottage industry of dependency management that has grown up around it, so even as it has become something of a cross-platform glue language like PERL and python, it's such a pain to even maintain consistency among its own minor releases, so we have to use rvm gratuitously to spawn different ruby environments to run different "core" ruby utilities on the same box (chef, foodcritic, rubocop all needing different versions of ruby and libraries and gems, etc.). And it's so slow compared to its peers... for an automation language, I find myself taking a lot of coffee breaks while it goes out and does its thing, and of course that also means all of the code check tools like foodcritic spam me with warnings to do all of the little optimizations like converting my string objects into symbols, so much for the pure object-orientism.

      Anyway, I have yet to have an experience with Ruby where it does something that impresses me compared to something else. It seems to be used to write templates for config files a lot, so I suppose that might be its strength. But even there, it seems to be a combination of the worst parts of other languages... all the indeterminate pieces of XSLT, more verbosity than XML, much slower and resource-hungry than other interpreted languages, almost as ugly as PERL, scattered package management in competing and overlapping gems since a lot of the base functionality is somewhat broken ( http://stackoverflow.com/quest... ), and yet seems harder to debug and less accessible too noobs than even compiled languages.

      From my experience with Ruby, I'm not exactly sure why this language was developed, other than to provide job security for some devops types. Oh, and I suppose https://github.com/mame/quine-... is cool from an academic standpoint.

    2. Re:Ruby and string/symbols by Darinbob · · Score: 1

      This is a copy from Smalltalk. So it's not "weird" or unique at all. It's also something common in many Lisp dialects. Ie, symbols are immutable and unique, strings don't have to be unique and don't have to be immutable.

      There are many scripting languages where strings are all immutable constants so that's not strange (ie, changing a string makes a new string), and some others where strings are unique (ie if they're equal then they're the same object as well).

    3. Re:Ruby and string/symbols by slew · · Score: 1

      When programming Ruby, just wait until you try to figure out how to match the vertical bar block parameter delimiters in your editor...

    4. Re:Ruby and string/symbols by Concerned+Onlooker · · Score: 1

      I can say that I use Ruby because of the way it implements regular expressions. They are really easy to use, no need to import a library or compile your regex. Just put some stuff between a couple of slashes and you're off and running.

      Since most of what I end up using a scripting language for is parsing text I use Ruby instead of Python.

      --
      http://www.rootstrikers.org/
  22. Re:php for sure. heck, java too. by Warbothong · · Score: 2

    PHP's list of oddities is never-ending. From "catchable fatal error" to "unexpected T_PAAMAYIM_NEKUDOTAYIM".

    There are some nice collections at http://eev.ee/blog/2012/04/09/... http://phpmanualmasterpieces.t... and http://www.phpwtf.org/

  23. Grief? by sgunhouse · · Score: 1

    Does it have to be grief? One of the strangest features of XBasic is ragged arrays. It's sort of somewhere between a linked list and an array, as long as the types match you can access it as an array (as in, arrayname[x,y,z] ).

    Full disclosure: since all the other official developers seem to have run off, I'm technically the lead developer at this point.

  24. Ada and abstract generic tagged type instances by mekkab · · Score: 1

    specifically with regards to accidentally freezing types. You've got to declare stuff with similar signatures to get your instances all nice and defined. But if you put something on the wrong line or do things in a different order... YOU'VE BROKEN IT!

    --
    In the future, I would want to not be isolated from my friends in the Space Station.
  25. Re:PHP by tepples · · Score: 4, Interesting

    Many of us have read the PHP is a fractal of bad design article and a commonly cited rebuttal. I tried to reconcile the two and ended up with about a half dozen legit complaints.

  26. Actionscript Scoping by BenJeremy · · Score: 1

    Not crazy about scoping, or should I say, lack of scoping of local variables in ActionScript. If I bracket a chunk of code, and define local variables, they should stop being defined when I exit the scope.

    If I define a for statement in C, C++ or C#, I can go: for( int i=0; i10; i++) { something...; } and follow it up by another statement that looks the same.

    In ActionScript, the second for loop gets a complaint that I am re-defining a variable.

    Over the years of developing C/C++ applications, I had gotten into the pattern of using scoping, particularly in switch statements, to define local variables specific to that block of code.

    1. Re:Actionscript Scoping by Jamu · · Score: 1

      for (int i = 0; i < 10; ++i) { something(); }

      I remember when some compilers would treat this like:

      int i; for (i = 0; i < 10; ++i) { something(); }

      and others like this:

      { for (int i = 0; i < 10; ++i) something(); }

      As the standard, for whatever reason, decide to change it. So much for not breaking existing code.

      --
      Who ordered that?
    2. Re:Actionscript Scoping by david_thornley · · Score: 1

      If different compilers did different things, the standard had to change something. The pre-standard compilers I used all did the first version, so for all of them it was a change.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    3. Re:Actionscript Scoping by Jamu · · Score: 1

      The first version was the standard ANSI C behaviour.

      i.e. for (expr1; expr2; expr3) statement

      was basically the same as

      expr1;
      while (expr2) {
      statement
      expr3;
      }

      --
      Who ordered that?
    4. Re:Actionscript Scoping by Dragonslicer · · Score: 1

      I ran into one really bizarre bug in ActionScript several years ago. I can't remember all the details exactly, but I think that if you try to redeclare a variable as a different type in the same function, the redeclaration is ignored and the type stays the same.

      Integer a;
      ... bunch of code ...
      String b;
      b = "foo";

      That code would give an error about assigning a string to an integer variable. Of all possible ways to handle redeclaring a variable, ActionScript picked the worst.

    5. Re:Actionscript Scoping by david_thornley · · Score: 1

      At the time of C++ standardization, C was still C90, and required all variables to be declared at the beginning of the enclosing block. There was no declaration in a for statement.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    6. Re:Actionscript Scoping by shutdown+-p+now · · Score: 1

      This is actually a generic problem with JavaScript (of which ActionScript is a derivative). I don't know whose smart idea it was to introduce the notion of local variable declarations and code blocks, but then completely ignore the interactions between the two.

      And JS doesn't get a pass for being dynamic. I know of at least two languages which get this right. In Lua, "local" declarations are actually scoped to the block they are in. And in Python, all variables are local by default unless declared global, so there's no confusing local declaration that looks like it's scoped to something that it is not actually scoped to.

      The good news is that they're fixing it in ES6 with "let".

    7. Re:Actionscript Scoping by shutdown+-p+now · · Score: 1

      The standard didn't decide to change it - the old behavior predates the standard (assuming that we're speaking about the ISO one here). ISO C++ always required the second interpretation, but it came fairly late in 1998, and a lot of code was already written using the former, so many compilers didn't switch right away.

      It was particularly bad on Windows, where VC++ 6.0 (also shipped in 1998) was such a compiler, and it also happened to be the one on which many people stayed for many years to come, taking a strong dislike with newer versions shipped with VS 2002 and above. On the other hand, some people actually hacked the old compilers to make this work, by doing something like:

      #define for if(false);else

      Then every for would implicitly be inside an else-branch, which guaranteed its own scope. But doing that before including any third party headers would break them if they had inline functions, so you had to be very careful...

  27. Best feature ever: Intercal (and others) COMEFROM. by lowen · · Score: 3, Interesting

    Heh, all of Intercal is strange.... but COMEFROM is just.... elegant.

    It's been implemented for Python, of all things.....

    See: https://en.wikipedia.org/wiki/...

  28. Assignement in Python by Framboise · · Score: 2

    Assigning a number or a list in Python and many other languages (Julia) is a different operation. Such as

    >>> a = 2
    >>> b = a
    >>> a = 1
    >>> b
    2

    >>> a = [2]
    >>> b = a
    >>> a[0] = 1
    >>> b
    [1]

    Octave (Matlab) is more consistent on this point, every assignement is a memory copy.

    1. Re:Assignement in Python by Warbothong · · Score: 2

      Assigning a number or a list in Python and many other languages (Julia) is a different operation. Such as

      >>> a = 2
      >>> b = a
      >>> a = 1
      >>> b
      2

      >>> a = [2]
      >>> b = a
      >>> a[0] = 1
      >>> b
      [1]

      Octave (Matlab) is more consistent on this point, every assignement is a memory copy.

      I'd find it alarming if Python *didn't* act that way! In Python, everything is an object and objects are passed by reference; hence altering the contents of "a" in your second example is clearly going to alter the contents of "b", since they're references to the same object. In the first case, you're altering *which object* "a" points to. It's completely consistent.

      The alternatives would be crazy (from an OO perspective).

      To make your second example act like your first one, we would need to *pass* everything by value. This means we couldn't, for example, use a "Logger" to collect messages from different parts of the program. Instead, each method would end up with its own copy of the Logger, containing only those messages from function activations which are still on the stack. As soon as any method returns, its Logger would be lost, along with all of the messages, unless we bypassed the language via the filesystem or a DB. This is *exactly* the situation you describe, except with "Logger" instead of "List" and "message" instead of "number". Note that this is exactly the situation in Haskell, which is why it needs things like the Writer Monad.

      To make your first example act like your second, we'd need to *assign* everything by reference, in which case your first example would replace the "2" object with the "1" object, which is a pretty bad idea ( http://everything2.com/title/C... )

    2. Re:Assignement in Python by Framboise · · Score: 1

      Observe that one needs two operators, memory copy, and "point to".
      What is wrong is to use only one symbol for the two, and change the meaning according to operator content.

    3. Re:Assignement in Python by bluefoxlucid · · Score: 1

      Python's list comprehension is extremely strange when you really get into it, but also one of my favorite features of the language. It's possibly the best single feature of the language.

    4. Re:Assignement in Python by LoneTech · · Score: 1

      No, these are not different operations; you just altered references in different places (first in your locals, second in a list that you held two references to). I see people getting similarly confused about vector or elementwise operations in Matlab, frequently resorting to blindly slapping on a period.

    5. Re:Assignement in Python by JesseMcDonald · · Score: 1

      Observe that one needs two operators, memory copy, and "point to".
      What is wrong is to use only one symbol for the two, and change the meaning according to operator content.

      No, the problem is in how you're thinking of the data. There is only one operation: "point to". When you execute "a = 2", you're making the variable "point to" the number two (which you can think of as an immutable object). Storing small, immutable objects directly inside pointers instead of allocating memory for each instance is an implementation detail, nothing more. So long as the data is immutable, it doesn't matter whether you're making a copy or a reference.

      Note that larger integers (like 2**80) are actually allocated as regular objects on demand rather than stored inside the pointers. Python breaks referential transparency a bit here through the "is" keyword, since the program can observe that equal numbers are actually separate objects in memory ("2**8 is 2**8 ==> True"; "2**80 is 2**80 ==> False"). If it kept a cache and reused the objects the program wouldn't be able to tell the difference.

      --
      "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
    6. Re:Assignement in Python by shutdown+-p+now · · Score: 1

      I actually prefer to think of it in reverse: there's only one operation, and that is "copy", but there's also only one data type for storage locations (like variables, list elements etc), and that is a reference. So you're copying the references around.

      By the way, (C)Python doesn't do any kind of fancy tagged pointer representation for integers regardless of their size - they're always pointers to an actual PyLongObject value. However, it does preallocate a bunch of "small integer" values in a static array, and for many (but not all) code paths it will give you a cached value. From the language spec point of view, the meaning of "is" for integers is basically implementation defined (and not really useful at all, since, them being immutable, there's nothing meaningful that you can derive from comparing them for identity).

  29. Python False = True by underqualified · · Score: 4, Interesting

    False and True are variables and you can assign one to the other. False = True print False Not that anyone sane would do this in real code, but the thought is still scary.

    1. Re:Python False = True by LoneTech · · Score: 2

      As of Python 3, True and False are keywords and cannot be assigned.

    2. Re:Python False = True by Just+Some+Guy · · Score: 4, Informative

      In Python 3, they're keywords:

      Python 3.4.1 (default, Aug 24 2014, 21:32:40)
      [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> True = False
      File "<stdin>", line 1
      SyntaxError: can't assign to keyword

      --
      Dewey, what part of this looks like authorities should be involved?
    3. Re:Python False = True by The+MAZZTer · · Score: 1

      In JavaScript it is perfectly valid to make a variable called "undefined" and assign it any value you want. Of course, to its credit, any assignment on the global scope (window.undefined is defined as undefined in Chrome) is ignored and it will still have the value of undefined, so it only works inside a function. Still odd though. null, true, and false are all keywords and thus cannot be assigned to.

    4. Re:Python False = True by Just+Some+Guy · · Score: 1

      Python didn't originally have True and False probably for the same reason C didn't: they already had well-defined truthy and falsey values. Besides, you don't often need them. Instead of writing if expr is True:, you'd just write if expr:. To this day, the most common use I see for them is as default values for keyword arguments.

      By making True and False variables with preset values, they could be added to the language without breaking code that already used those names for other things. By the time Python 3 rolled around, such code would probably have to be re-written for other reasons anyway and there was no longer a compelling backward compatibility story for not making them actual keywords.

      --
      Dewey, what part of this looks like authorities should be involved?
    5. Re:Python False = True by LordKronos · · Score: 1

      I'm not sure Id say this is "due to the nonsensical autoboxing syntactic sugar". This only works because you "hacked" the system.

      1) You aren't allowed to modify the value of an Integer object, as the value is both private and final. You worked around that by using reflection to get at the object's variables in the roundabout way.
      2) Even then, you wouldn't be allowed to modify it because of security restrictions. However, you also explicitly turned off the security restrictions.
      3) The only reason you were even able to turn off the security restrictions is because you were running in an unmanaged environment. In that situation, it is assumed you have full access to do pretty much anything you'd like. However, if you were running in any sort of managed environment with a security manager installed, you wouldn't have been able to do that.

      This is really not much different than C++, where it's assumed you have full access to everything. You can take a const, get a const pointer to it, cast that to a non-const pointer, and then modify it. Even if that constant value were stored in a non-writable code page, you could make the code page writable if you were running in an environment that allowed you to alter those permissions. I haven't done such a thing in a VERY long time, so I'm not sure if Admin access under windows these days gives you that level of access, but I'm almost certain linux root level would allow it.

    6. Re:Python False = True by LordKronos · · Score: 1

      OK, if autoboxing is crap, then you should just consider it invalid to assign a primitive type to an object type. Thus I guess you made a coding error when you wrote the code that did autoboxing. Shame on you.

      Now, back here in the real world, you went OUT OF YOUR WAY, even going so far as to explicitly circumvent 2 levels of security measure, just to FORCE the problem to occur. That's like claiming the scissors you bought are unsafe because they made you go blind when you jammed them into your eyes.

      Sorry, but the autoboxing is completely safe unless you take explicit measure to attempt to make it unsafe. Don't go whining just because the language didn't protect you from yourself. It actually tried, but you told it not to. If you can't trust yourself not to be an idiot, then just run all of your code with an appropriate security profile in place and you'll be all set.

  30. OPS5 by hedley · · Score: 1

    A rule based language. 1000's of productions can be waiting to fire by querying a database (lhs waits, fires, triggers rhs updates). In my mind, its a bit like a seeing a VHDL language meet a database wrt the parallelism that comes out from it.

    Programs written in it don't look at all like programs you normally would write in the life of a typical coder.

    1. Re:OPS5 by ubersoldat2k7 · · Score: 1

      Wow, I mean, I don't even...

      (object-class request
        ^action)

      (startup
        (strategy MEA)
        (make request ^action hello)
      )

      (rule hello
        (request ^action hello)
        (write |Hello World!| (crlf))
      )

  31. Some COBOL features I like by Nutria · · Score: 1

    - Variables can start with a numeric, since whitespace is the token separator. This has some distinct uses in a globally scoped language, when combined with PERFORM THRU.
    - "Concatenated OR". It lets you write code like IF 8 = A OR B OR C OR D OR E THEN ...
    - 88 Level variables

    --
    "I don't know, therefore Aliens" Wafflebox1
  32. Regexp by Z00L00K · · Score: 1

    Anyone coding in Regular Expressions knows that the whole language is extremely compact and is only built upon the understanding of strange features.

    If any code is "Write Only" that must be the top contender.

    --
    If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
  33. Move Corresponding by khb · · Score: 1

    Removed from modern versions of COBOL, the traditional "MOVE CORRESPONDING" was unique. Given two records with differing layouts, MOVE CORRESPONDING would shuffled the values based on the names (putting in default values where needed, or tossing aside unneeded ones).

  34. If you print a lot and want a ink spare language by NotInHere · · Score: 5, Funny

    use whitespace. Be warned, several problems have been reported when posting source code to the internet.

  35. PowerShell - the whole language by ErichTheRed · · Score: 1

    I'm not saying PowerShell isn't extremely cool -- it is, and I'm working on wrapping my brain around it. But I do have a lot of experience in multiplatform environments, and PowerShell's syntax is stitched together from so many sources that it gets very confusing.

    - You have extensive pipeline use a la UNIX/Linux, but those pipes don't necessarily contain text, they contain references to objects.
    - You have very long command syntax a la OpenVMS DCL. A line of PowerShell can perform lots of operations, but that line can be hundreds of characters long. Also, since it references .NET-style objects/properties, these names tend to be very long and add to the number of characters.
    - You have branching/looping/basic structure syntax from everywhere. A little looks like Perl, some like bash, some like Java/C#.

    Granted, VBScript and the various ways to interface with stuff like WMI and the XML parser were awful. I'm converting a lot of my old scripts now, and see hundreds of lines of wasted code doing stuff like opening a file, parsing fields, checking a WMI variable, executing some COM-exposed method, etc. etc. etc. It just takes a very long time to get used to the syntax, and the fact that Windows is basically doing everything for you and you're just gluing it all together.

    1. Re:PowerShell - the whole language by The+MAZZTer · · Score: 1

      The fun stuff is that you can use any .NET object in addition to PowerShell commands and syntax. And then you can also use command line apps as well (though there are annoying issues with delimiting arguments depending on which method of invocation you use).

    2. Re:PowerShell - the whole language by laughingskeptic · · Score: 1

      The first couple of chapters of this book explain the decision making behind the syntax which really helps. http://www.amazon.com/Windows-...

  36. IDL language by Khashishi · · Score: 3, Interesting

    Odd integers are true; even integers are false.

    Arrays can be indexed with () or []. This leads to namespace problems with functions which are also called with (). For example:
    x=a(1,2)
    error: undefined variable a.
    If you want to call function a, you have to forward declare it for this reason.
    There's a different syntax for procedures (which don't have a return value) and functions (which do).

    It is required to assign the result of a function to something. You have to write
    dummy = foo(1,2,3)
    as writing
    foo(1,2,3)
    will give an error.

    Most of the time, a single element array is treated the same as a scalar. But not always, and not being very careful will lead to weird errors.
    There are no zero length arrays.
    An array can be length 1; a multidimensional array can be length [1,2,2], but a multidimensional array cannot be length [2,1,1]. If the last dimension has length 1, it simply vanishes to a smaller dimension, unless already 1 dimensional. Example:
    a = make_array(1,2,2)
    ; a has dimensions [1,2,2]
    a = make_array(2,1,1)
    ; a has dimensions [2]
    This means special code must be written to handle any array operations that might end with last dimension 1.

    Array slices are weird.
    b = a[3,*,2]
    means to take a slice of a along the second dimension. I'd expect the answer to be 1 dimensional, since there's only 1 scan in the slice. But the result has dimensions [1,3]
    On the other hand, a[3,2,*] has dimensions [1,1,3], and a[*,3,2] has dimensions [3]. It makes sense in a convoluted way, but it sucks.

  37. assert side-effects and gcc fp optimizations by robbo · · Score: 1

    Gotchas more than quirks:
    - the day you realize you put a side effect in an assert() call.
    - the day you realize GCC, maybe it was V2, not sure this is still an issue, exploits extra bits of precision in the Intel FPU, *only if* optimizations are enabled, which causes certain iterative floating point algorithms (eg SVD) to fail to converge.

    In both cases everything works great in debug builds but goes to hell in release builds and it's incredibly painful to get to root cause.

    --
    So long, and thanks for all the Phish
    1. Re:assert side-effects and gcc fp optimizations by shutdown+-p+now · · Score: 1

      the day you realize GCC, maybe it was V2, not sure this is still an issue, exploits extra bits of precision in the Intel FPU, *only if* optimizations are enabled, which causes certain iterative floating point algorithms (eg SVD) to fail to converge.

      This is still normal behavior for most C/C++ compilers for IEEE platforms. It is also the expected behavior for Java and C# both. It's just much easier (and faster) to do floating point math if you don't have to truncate every intermediate result to fit the original precision on platforms where it is not normally the case.

  38. Head Scratchers? by Princeofcups · · Score: 1

    More like, "doesn't behave like I think it should." Nothing to see here. Move along.

    --
    The only thing worse than a Democrat is a Republican.
  39. Instantly thought of.. by TFlan91 · · Score: 1
  40. Duck typing by CODiNE · · Score: 1

    Yeah with Javascript being such a huge language these days a lot of youngsters don't know how entirely bizarre and hackish it's type system seemed back in the day.

    "Huh? NO type?? You just slap things on it?? But, but, what about classes??"

    --
    Cwm, fjord-bank glyphs vext quiz
    1. Re:Duck typing by narcc · · Score: 1

      It has types, and you really don't need classes. Prototypes are better in just about every way.

    2. Re:Duck typing by viperidaenz · · Score: 1

      Except for performance.

    3. Re:Duck typing by narcc · · Score: 1

      True.

  41. Ruby and the default blank array by mekkab · · Score: 1

    catches every newb screwing around with hashes!

    --
    In the future, I would want to not be isolated from my friends in the Space Station.
  42. VB6 and no copy deep. by Hussman32 · · Score: 1
    Old VB6.

    Foo has object property Foo2, which has object property Foo3.

    Dim aFoo as Foo

    Dim bFoo as Foo

    Dim b = Foo2

    Set bFoo = aFoo

    b = bFoo.Foo2

    Why is that object not referenced?

    Oh, no copy deep.

    Drove me crazy writing copy methods.

    --
    "Who are you?" "No one of consequence." "I must know." "Get used to disappointment."
    1. Re:VB6 and no copy deep. by shutdown+-p+now · · Score: 1

      It's not about "copy deep" - it's about the fact that your variables are references to objects, not objects themselves, so copying copies the reference. It's the same exact thing in any language with reference semantics, including C#, Java, Python etc.

      (Sometimes I wish we made it standard to make that referencing explicit in type declarations, even though it would have to always be there and so be redundant - but at least it'd remind people that they're dealing with references!)

      The real WTF in VB6 was the difference between "Let" and "Set" - the fact that you had to write "Set x = y" vs "Let x = y" (or omit the "Let", since it was the default) depending on the type of "y" - "Set" for object references, and "Let" for everything else. The double-WTF here is that the version with "Let" would in fact compile and run if "y" was an object and "x" returned an object, as well - it just wouldn't do what you expected it to do, but instead assign "y" as the new value of the property of "x" that was designated as a default (and only fail if there was no such property). The triple-WTF was that, when variants were involved, the behavior was decided based on the actual runtime type of the assigned variant. And on the other side of that equation, when defining a property setter, it was actually possible to define two separate methods handling the "Let" and the "Set" (I'm not actually sure if it was so in VB, but you could definitely do it when authoring a COM component in C++, and VB would then understand that).

      All so that people could write things like "textBox = 123" instead of "textBox.Text = 123".

  43. LISP by whitroth · · Score: 3, Interesting

    Ok, someone has to mention lisp.

    Item from 15 or so years ago: a guy posted online that he'd broken into the Pentagon's computers, and found the code for SDI, and it was written in lisp. He didn't want to break US security, but he did post the last five lines of the code.... (stupid slashdot edit filter - 5 lines of ) was not junk... at least, not in lisp....)

                      mark

    1. Re:LISP by Anonymous Coward · · Score: 1

      (was (see (I comment)) redacted)

    2. Re:LISP by david_thornley · · Score: 2

      That is why you NEVER EVER write Lisp code with an editor that's not parenthesis-aware. I've tried it. Don't make my mistake.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    3. Re:LISP by Gunstick · · Score: 1

      I put my closing parenthesis on a single line. Made the programs way shorter

      ( code
         ( more lisp
            ( some code
               ( finaly done
      )  )  )  )

      Funny code, but it worked. Never had errors related to rearranging parenthesis like that.

      --
      Atari rules... ermm... ruled.
  44. Stackoverflow's got a list by Tridus · · Score: 5, Informative

    http://stackoverflow.com/quest...

    That's a list of very strange language features. Unsurprisingly, Javascript makes many, many appearances.

    --
    -- "So they told me that using the download page to download something was not something they anticipated." - Bill Gates
    1. Re:Stackoverflow's got a list by Jaime2 · · Score: 1

      Apparently, that StackOverflow page is the source for the article. Even many of the comments that are in the article come from that page.

    2. Re:Stackoverflow's got a list by rasmusbr · · Score: 1

      But TFA apparently got it wrong. '1' + 1 does not yield 11, it yields '11' like one would expect in a modern language. The odd thing is that '1' - 1 apparently yields 0.

      Disclaimer: I don't write JavaScript, thank God.

    3. Re:Stackoverflow's got a list by Trailer+Trash · · Score: 1

      http://stackoverflow.com/quest...

      That's a list of very strange language features. Unsurprisingly, Javascript makes many, many appearances.

      That list is the source for the linked "article".

  45. Java Unsigned Int by Rob+Riggs · · Score: 1

    Lack of unsigned numeric types, especially when dealing with binary (octet) data streams. Drives me up the fracking wall.

    --
    the growth in cynicism and rebellion has not been without cause
  46. Re:Perl by Megane · · Score: 1

    For me one of the most annoyingly strange things about Perl is the post-if. (apparently the official name is "Statement Modifiers") You can do something like "statement if (condition); WHY? They just tend to make it harder to read the code flow.

    A lot of strange things in Perl have explanations in its origins, where it merges grep/sed/awk style with sh/ksh/bash style and C style, but I have no idea where post-if came from, unless it was just stunt programming. ("Hey, look at this, I put the if at the end of the statement!")

    I think the even more crazy part is that this language feature (and others, fwiw) can be disabled by code written in the same language. Yep, just include a few blocks of code, and the basic features of your programming language change.

    --
    #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
  47. if(allocation_succeeded) by tepples · · Score: 4, Interesting

    if (a = b) assigns the contents of b to a and executes the code following if b 0. Who the hell thought that would be a good idea?

    If b is an expression that returns a reference to a newly allocated resource, such as fopen or malloc, this if statement represents trying to allocate a resource and then skipping the following compound statement if the allocation failed. It's what they had before exceptions, and it's what they still have on microcontrollers too small to have the overhead of a full-featured exception handler.

    strings terminated by a binary zero rather than their physical size. Who the hell thought that would be a good idea?

    Probably the same way that most popular operating systems store text files as a list of lines separated by newline characters, encoded as 0x0A on UNIX or Windows but 0x0D on Apple II or classic Mac OS. VMS is an exception in that its "non-stream" text files have each line prefixed by its length.

    1. Re:if(allocation_succeeded) by ultranova · · Score: 1

      If b is an expression that returns a reference to a newly allocated resource, such as fopen or malloc, this if

      So it's a tradeoff: get neat one-liners for a thing most C programmers don't bother to do, at the expense of adding a hard to notice source of bugs to every if statement.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    2. Re:if(allocation_succeeded) by macs4all · · Score: 1

      Probably the same way that most popular operating systems store text files as a list of lines separated by newline characters, encoded as 0x0A on UNIX or Windows but 0x0D on Apple II or classic Mac OS.

      Bzzt! Wrong! Thanks for playing...

      Due to a hardware shortcut involving the Keyboard (Keyboard Strobe was expressed as the MSB of the Value when the Keyboard location ($C000) was Read, which extended to the Keyboard Input routines in the Monitor ROMs, Apple ][ systems used a unique "High-Bit ASCII" character-set (but not as "Unique" as the C-64 version of "ASCII"!!!), such that the MSB was ALWAYS "1".

      Therefore, in Apple ][ world, a CR was expressed as $8D (0x8D), rather than $0D (0x0D).

      Fortunately, this little peccadillo was NOT carried into the Lisa or Mac, which operate as the Parent noted.

    3. Re:if(allocation_succeeded) by tepples · · Score: 1

      in Apple ][ world, a CR was expressed as $8D (0x8D)

      This is true of DOS 3.3, not of the ProDOS and GS/OS that succeeded it.

    4. Re:if(allocation_succeeded) by UnknownSoldier · · Score: 1

      > but 0x0D on Apple II

      You mean 0x8D. :-)

      Castle Wolfenstein on the Apple ][ actually used C strings! There will be a post reverse engineering the game in c.e.a2 soonish once the next version of AppleWin 1.25 is ready ...

      Applesoft ROM used low-ascii, and a high-ascii as a end of terminator. The assembler directive was DCI for Merlin and official Apple Assembler.
      i.e.
      http://i.imgur.com/lD9Na9K.png

    5. Re:if(allocation_succeeded) by Half-pint+HAL · · Score: 1

      This was an early example of "good practice" vs "lazy programmers". The war rages on to this day.

      --
      Got them moderator blues I blieve I walk out the do', With these mod-points I been gettin', I 'most never post no mo'
    6. Re:if(allocation_succeeded) by davidwr · · Score: 1

      if (a = b) assigns the contents of b to a and executes the code following if b 0. Who the hell thought that would be a good idea?

      If b is an expression that returns a reference to a newly allocated resource, such as fopen or malloc, this if statement represents trying to allocate a resource and then skipping the following compound statement if the allocation failed.

      I think you are missing the point. The point is "Why use the '=' as the assignment operator instead of some other symbol, like Pascal's ':='?"

      If I could go back and whisper something into K&R's ears, I would tell them to make "=" the comparison operator and pick something else as the assignment operator.

      --
      Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
    7. Re:if(allocation_succeeded) by Sanhedran · · Score: 1

      If b is an expression that returns a reference to a newly allocated resource, such as fopen or malloc, this if statement represents trying to allocate a resource and then skipping the following compound statement if the allocation failed. It's what they had before exceptions, and it's what they still have on microcontrollers too small to have the overhead of a full-featured exception handler.

      That completely misses the problem of accidentally performing an assignment when you meant to do a comparison, and is also completely unallowable in safety-critical code, which is a good amount of what runs on microcontrollers in the first place.

    8. Re:if(allocation_succeeded) by tepples · · Score: 1

      That completely misses the problem of accidentally performing an assignment when you meant to do a comparison

      If you wrapped your assignment-that-was-supposed-to-be-a-comparison in one pair of parentheses, -Wparentheses will pick it up. If you wrapped it in two, then it wasn't quite accidental.

  48. Intransitive equality and comparison in PHP by Barandis · · Score: 1

    One of the many lovely things about PHP, though this time it's not the only culprit.

    $ php -r 'var_dump("foo" == TRUE); var_dump("foo" == 0); var_dump(TRUE == 0);'
    bool(true)
    bool(true)
    bool(false)

    $ php -r 'var_dump(NULL == 0); var_dump(NULL < -1);'
    bool(true)
    bool(true)

    Strange, and not in a good way. Makes the mathematical part of my brain explode.

  49. PHP's associativity of ?: is backward by tepples · · Score: 2

    By now, the only strange thing about the ternary operator condition ? value_if_true : value_if_false is how PHP has the operator's associativity backwards from everything else. Everything else interprets a?b:c?d:e as a?b:(c?d:e), where a chain of ternary operators means use the value associated with the first true condition. It's equivalent to SQL's case when a then b when c then d else e end. PHP, on the other hand, interprets a?b:c?d:e as (a?b:c)?d:e, which means using one condition to select which other condition shall apply. In my opinion, PHP's interpretation is less useful.

  50. Numeric equality in PHP by tepples · · Score: 1

    In PHP, 1 === 1.0 and 1 === '1' are both false, and 1 == 1.0 and 1 == '1' are both true. What operator should the programmer use if he wants 1 to equal 1.0 but not '1', where integer numbers are equal to float numbers but strings aren't equal to either?

    1. Re:Numeric equality in PHP by tibit · · Score: 1

      Just write a function that checks the argument types and does what you wish.

      --
      A successful API design takes a mixture of software design and pedagogy.
    2. Re:Numeric equality in PHP by amicusNYCL · · Score: 1

      What operator should the programmer use if he wants 1 to equal 1.0 but not '1', where integer numbers are equal to float numbers but strings aren't equal to either?

      How about just checking if you're dealing with a string and casting it if necessary?

      --
      "Our two-party system is like a bowl of shit looking at itself in a mirror." - Lewis Black
    3. Re:Numeric equality in PHP by MightyYar · · Score: 1

      My approach is generally to always use "===" and explicitly cast things. It makes your errors more explicit.

      --
      W..w..W - Willy Waterloo washes Warren Wiggins who is washing Waldo Woo.
    4. Re:Numeric equality in PHP by meloneg · · Score: 1

      In PHP, 1 === 1.0 and 1 === '1' are both false, and 1 == 1.0 and 1 == '1' are both true. What operator should the programmer use if he wants 1 to equal 1.0 but not '1', where integer numbers are equal to float numbers but strings aren't equal to either?

      Since (almost) no computer actually stores 1.0; your request is, at best, naive.

    5. Re:Numeric equality in PHP by tepples · · Score: 1

      What you say is helpful when one of the side is a literal constant. It's not so helpful when both sides are variables.

    6. Re:Numeric equality in PHP by beelsebob · · Score: 1

      You shouldn't. You should (in all languages), explicitly convert the type, and then compare things of equal type. For bonus points, you should only use languages that enforce that the arguments to == are of equal type.

    7. Re:Numeric equality in PHP by tepples · · Score: 1

      For bonus points, you should only use languages that enforce that the arguments to == are of equal type.

      Good luck converting all legacy software to meet bonus points, and good luck finding affordable entry-level web hosts that meet bonus points.

    8. Re: Numeric equality in PHP by tepples · · Score: 1

      I understand what === means. It's just that sometimes I want a middle ground between "exactly the same type" and "convertible to the same type even if it requires relying on behavior that depends on the default locale". I want to check whether they're equal and have similar types, with a useful definition of similar. For example, Python 2 allowed 8-bit strings and Unicode strings to compare equal, both being of type basestring, and allowed integers, long integers, and floats to compare equal, all being of type numbers.Number, which was informal initially but formalized in PEP 3141.

      That and PHP lacks an operator for object identity for arrays. I'm not aware of any practical way to tell whether mutating one array will cause another array to be mutated without (slowly) checking them element-by-element and (potentially unsafely) trying to actually perform the mutation.

    9. Re:Numeric equality in PHP by smellotron · · Score: 1

      Since (almost) no computer actually stores 1.0

      Since almost every computer nowadays implements IEEE floating-point, they can all store 1.0 exactly. From the link:

      Any integer with absolute value less than 2^24 can be exactly represented in the single precision format, and any integer with absolute value less than 2^53 can be exactly represented in the double precision format.

    10. Re:Numeric equality in PHP by shutdown+-p+now · · Score: 1

      There's no particular reason to not have comparable values of different types, especially where there's a clear subtyping relationship (even if it's not exposed directly in the language). For example, it's patently obvious that integer 1 should be equal to floating-point number 1.0 - they both represent the same abstract concept, "number", with the same value, and there is one and only one way to compare those for equality.

      The reason why 1=="1" is evil is because there's no useful unambiguous way to define such a comparison - should it convert the string to a number, or the number to a string? There's no universally good answer to that question, so the language must force the programmer to decide which one he had in mind (by casts, or by defining different comparison operators - it doesn't matter, so long as semantics is explicit).

      Ditto for overloading + for different types. With something like 1+1.0, the result is clearly 2 - the dispute is only over whether it should be float or int, and clearly in the most general case it has to be float. In a language where you can freely substitute one for the other so long as the value is the same (such as most dynamically typed language), it is largely irrelevant. On the other hand, something like 1+"2" can be interpreted in two different ways with no clear reason to prefer one over the other, so it should definitely be an error.

      It just so happens that PHP made pretty much all the wrong choices, while e.g. Python made mostly right ones.

    11. Re:Numeric equality in PHP by beelsebob · · Score: 1

      There's no particular reason to not have comparable values of different types

      Sure there is - they have different types, therefore they're not equal. It's a ridiculous, useless operation, because it doesn't actually do anything more than always return false.

      That said, there's good reason to have an "isSimilarTo" function, but that's not at all the same thing as equality.

    12. Re:Numeric equality in PHP by shutdown+-p+now · · Score: 1

      Types are an artifact of an imperfect system - what matters is the meaning. The only reason why we even have separate int and float types, for example, is performance, and legacy semantic differences (like different behavior for division by zero or overflow) - from a common sense perspective, the type should just be "rational number", and whether the underlying representation is integer, or floating-point, or a true rational, does not matter in the slightest. In languages which still choose to expose that difference in their typing system, it still makes sense for them to try and patch over that difference by at least making the values largely interchangeable (or even directly introducing some form of subtyping relationship to codify that, like Scheme's numeric tower).

  51. Flipping arrays by blueshift_1 · · Score: 1

    I occasionally do some work in Fortran (and even rarer with matlab) and arrays that begin with an index of 1. It's so subtle and simple that I have to take a step back and try to reroute my thought process. WHY U NOT START AT 0?!?

  52. Prolog by WindowPane · · Score: 1

    The whole language of Prolog. Only took a semester of it in college 20 years ago but what a strange recursive language.

    --
    No Brains, No Headaches
  53. I'll tell you something I love in AS3/AIR by GoodNewsJimDotCom · · Score: 1

    You can call objects with "this" as one of the parameters you pass.
    Then the class can then save it to a global to the class variable.
    Then that class has the ability to call functions in your main class :)
    I discovered this because Eclipse for AS3(Flashbuilder) has a bug if you go over 25,000ish lines that it slows down your typing.
    I started making separate classes which were just a place to put methods.
    Since a lot of people are coding with AIR for Android/iOS, I'm sure someone will love using this.

  54. Tabs in Make by gatkinso · · Score: 1

    Because why not base syntax on an invisible character?

    Blahblahblah show whitespace. Whatever. I was showing your Mom whitespace before she met your father, whippersnapper.

    --
    I am very small, utmostly microscopic.
    1. Re:Tabs in Make by Animats · · Score: 1

      The guy who made that mistake realized the next morning he'd made a serious design error. But by then, he writes, he already had three users. Really.

    2. Re:Tabs in Make by Darinbob · · Score: 1

      I interviewed with the author of make, Stu Feldman.

      I don't think it's that big a deal myself. I wish it used just any white space, but... If that's the big fault then it's doing great. It's a simple system but very powerful, and none of the many make replacements come anywhere near its usefulness.

  55. Python scope by Warbothong · · Score: 2


    def mkCounter():
            c = 0
            def counter():
                    c = c + 1
                    return c
            return counter

    count = mkCounter()
    print str(count())
    print str(count())
    print str(count())

    You'd expect "1", "2" and "3", right? Wrong!


    $ python test.py
    Traceback (most recent call last):
        File "test.py", line 9, in
            print str(count())
        File "test.py", line 4, in counter
            c = c + 1
    UnboundLocalError: local variable 'c' referenced before assignment

    When Python parses the definition of "counter", it sees the assignment "c = ..." and assumes that we must be defining a local variable "c", so it creates a slot in "counter" to contain "c". This local slot shadows the "c" inherited from "mkCounter", so when we get to evaluating "c + 1" we get this "referenced before assignment" error.

    Note that it's perfectly fine to *use* inherited variables, just not to *assign* them:


    def mkPrinter(s):
            def printer():
                    print s
            return printer

    p = mkPrinter("hello world")
    p()

    This prints "hello world" as we'd expect.

    1. Re:Python scope by shutdown+-p+now · · Score: 1

      It's kind of quirky, but at least it's better with JS where you have blocks and variable declarations inside those blocks, but for some mysterious reason the variable declaration is not scoped to the block in which it is declared, but to the entire function. You'd think that the sensible thing to do would be to either disallow "var" inside blocks and require it to be on top level (and, since it's visible throughout the function, at the beginning of it - like in C89), or else to do proper scoping like Lua did. In Python, the scope is implicit but it doesn't lie.

      And, of course, they did add "nonlocal" in Python 3 for those cases where you really do want to assign to an outer variable.

  56. That's called a function pointer by tepples · · Score: 1

    All that means is that the argument of a GOTO that has been ALTERed is a function pointer. I don't see how that's any stranger than the Lisp family's feature of assigning a function to a variable and then tail-calling the function through the variable.

    1. Re:That's called a function pointer by david_thornley · · Score: 1

      It's not really a function pointer. If the paragraphs in COBOL were separate functions, then yes. However, since they're executed sequentially it's a GOTO.

      Another interesting thing about paragraphs is that you can write "PERFORM PARAGRAPH1 THROUGH PARAGRAPH2" (if I remember the syntax aright), so the flow of execution is determined at the spot the PERFORM is written rather than anywhere around PARAGRAPH1.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  57. nodejs by slashdice · · Score: 1

    pretending synchronous code is magically asynchronous when you add a 10-story callback pyramid.

    --
    Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
    1. Re:nodejs by shutdown+-p+now · · Score: 1

      Callback pyramid is not a language feature, it's a framework feature.

      And it does actually make it asynchronous. I'm not sure what you even mean by "magic" - there's nothing magical about callbacks, it's a pretty obvious idea that just took a while to catch on. If you want actual magic in the same vein, that's C# "await".

  58. Re:Alter by tepples · · Score: 1

    Alter X to proceed to Y.
    Alter W to Proceed to X.
    Alter Z to proceed to F.
    Alter J to Proceed to I.

    Sounds like a primitive version of function pointers.

    void (*x)() = y;
    void (*w)() = x;
    void (*z)() = f;
    void (*j)() = i;

  59. Mixed arithmetic in Matlab by ClickOnThis · · Score: 3, Interesting

    This was a stunner for me when I first encountered it. When you mix double and int types in Matlab, it demotes the double to an int! Same with float and int.

    Of course, you must create the int explicitly as such (double is the default) but I mean, WTF Matlab??

    --
    If it weren't for deadlines, nothing would be late.
    1. Re:Mixed arithmetic in Matlab by Hotawa+Hawk-eye · · Score: 1

      Do you really want this:

          A = ones(10000, 10000, 'int8'); % 10000-by-10000 matrix each entry of which is 1, stored using the 8-bit signed integer type
          B = 1; % double precision
          C = A+B;

      to blow C up into a 10000-by-10000 matrix of doubles, requiring eight times as much memory as A?

      There's also the question of false precision.

    2. Re:Mixed arithmetic in Matlab by ClickOnThis · · Score: 1

      What I'm saying is this (pardon my Matlab, it has been awhile):

      a = int8(1);
      b = 1; % double;
      c = a + b; % c is type int8, not double

      --
      If it weren't for deadlines, nothing would be late.
    3. Re:Mixed arithmetic in Matlab by ClickOnThis · · Score: 1

      Do you really want this:

              A = ones(10000, 10000, 'int8'); % 10000-by-10000 matrix each entry of which is 1, stored using the 8-bit signed integer type
              B = 1; % double precision
              C = A+B;

      to blow C up into a 10000-by-10000 matrix of doubles, requiring eight times as much memory as A?

      Obviously not. But it should be my choice as to whether precision is thrown away, not Matlab's.

      --
      If it weren't for deadlines, nothing would be late.
  60. coffeescript by slashdice · · Score: 1

    It's just javascript! Plus the worst parts of python and ruby....

    --
    Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
  61. Null Terminated Strings by Comboman · · Score: 3, Interesting

    - strings terminated by a binary zero rather than their physical size. Who the hell thought that would be a good idea?
    Well, age old argument. Basically a matter of taste or sadly a historical "evolution".

    I'm pretty sure null-terminated strings come from the days of punch cards/punch tape where an unpunched area is read as null (binary zero). Wherever the data-entry clerk stopped typing was the end of the string and the string could be appended to latter (impossible with a non-zero end-of-string symbol or a string length in the header which can't be rewritten on card/tape).

    --
    Support Right To Repair Legislation.
    1. Re:Null Terminated Strings by BasilBrush · · Score: 1

      Interesting. It's a shame C wasn't abandoned at the same time as punch cards.

    2. Re:Null Terminated Strings by mferero · · Score: 1

      Nope. Punched cards was the era of fixed length fields . . . You described each field with a size, including packed decimal numbers.

      --
      Honor est omni
    3. Re:Null Terminated Strings by zephvark · · Score: 5, Funny

      Nonsense. C is a more elegant weapon for a more civilized age. It's a shame that mass-produced coders have to rely on blasters.

    4. Re:Null Terminated Strings by BasilBrush · · Score: 1

      If C were a weapon it'd be a wooden club.

    5. Re:Null Terminated Strings by KingMotley · · Score: 2

      Well it was also kind of important for being able to process data that you didn't know the size of until you actually hit the end, especially if you couldn't hold the whole contents in memory at one time, and you needed to be able to do something with it. Think streams where you can't just go back and write the size of the string at the beginning after you've already copied the string. NULL terminated strings are also smaller since it always only uses a single byte, even if the string is (or could be) longer than 255 characters. The size aspect typically isn't all that important today, but it still can be quite useful in memory constrained systems even today.

    6. Re:Null Terminated Strings by SpaghettiPattern · · Score: 4, Insightful

      I believe none of you actually programmed in C. A string terminated by \0 can be represented by a single pointer and an have any length. You can also easily let the string keep growing (until the allocated memory is finished.) That is the epitome of KISS. If you use an 8 byte character at the beginning then you are limited to a string length of 255. A structure with a length and a string pointer (or a character array) is much more complex and that would reflect in more complex library functions.

      C was invented by exceptionally bright people. For a language that was primarily designed to program kernels its remarkably versatile. If you are seeking a language to write administrative applications then you should look further. COBOL back in the days or Java nowadays would suit you better. And yes, there is a difference in programming prowess between kernel / library programmers and application programmers. The latter "just" have to get the business logic going and are allowed to use every trick in the book. The former must be very concise and consider that their code will be used by a huge amount of other programs.

      --

      I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
    7. Re:Null Terminated Strings by BasilBrush · · Score: 1

      I believe none of you actually programmed in C. A string terminated by \0 can be represented by a single pointer and an have any length. You can also easily let the string keep growing (until the allocated memory is finished.)

      You're missing something. You can't have a string longer than the amount of memory that is reachable by a pointer. Hence my comment that you wrongly think incorrect.

      C was invented by exceptionally bright people.

      A VERY long time ago. We've learned a lot about what makes good and bad language features since then. What made for a good language in the 70s, sucks now.

      And yes, there is a difference in programming prowess between kernel / library programmers and application programmers.

      You don't say. Sounds like this is relatively new to you.

      The former must be very concise

      That's complete nonsense. Source code size has nothing to do with object size, let alone suitability of a language for different problem domains. C's conciseness was useful in the 1970s and 80s, where memory used for source code whilst editing and compiling was a significant factor. Nowadays 10s or hundreds of K of source code is irrelevant in GB sized PC memories. The conciseness is worthless.

    8. Re:Null Terminated Strings by Darinbob · · Score: 1

      C++ is a wooden club with some nails stuck in it.

    9. Re:Null Terminated Strings by BasilBrush · · Score: 1

      Well it was also kind of important for being able to process data that you didn't know the size of until you actually hit the end, especially if you couldn't hold the whole contents in memory at one time, and you needed to be able to do something with it. Think streams

      They're typically handled in blocks, regardless of language. And blocks are either fixed size or store their length in a header.

      stdin and stdout are character streams but they come about as part of the philosophy of C, rather than C's null terminated strings being a good way to deal with them. And in any case they never actually hit their end, so neither termination nor length are relevant.

    10. Re:Null Terminated Strings by saigon_from_europe · · Score: 1

      I believe none of you actually programmed in C. A string terminated by \0 can be represented by a single pointer and an have any length. You can also easily let the string keep growing (until the allocated memory is finished.)

      The problem is that you usually don't know where the the allocated memory is finished.

      I understand the rationale behind the pointers like they are, but I'd still prefer if pointers could keep both address and size of the buffer. But it's too late now for such kind of redesign or upgrade.

      And yes, I do code in C every working day.

      --
      No sig today.
    11. Re:Null Terminated Strings by John_Sauter · · Score: 1

      - strings terminated by a binary zero rather than their physical size. Who the hell thought that would be a good idea? Well, age old argument. Basically a matter of taste or sadly a historical "evolution".

      I'm pretty sure null-terminated strings come from the days of punch cards/punch tape where an unpunched area is read as null (binary zero). Wherever the data-entry clerk stopped typing was the end of the string and the string could be appended to latter (impossible with a non-zero end-of-string symbol or a string length in the header which can't be rewritten on card/tape).

      Actually, an unpunched column on a card was a space. You are right about paper tape.

    12. Re:Null Terminated Strings by solidraven · · Score: 1

      I would like to add one thing: People forget that a kernel has to run on pretty much bare metal. If you're lucky you have BIOS there helping you a bit at the start, but not really. (Yay for obscure backwards compatibility tricks that the folks at Microsoft, IBM and Intel came up with.) So your standard libraries are usually quite limited, if you have them at all. And even then they're usually too slow to deal with anyway, so you end up rewriting everything in X86 assembly anyway.

    13. Re:Null Terminated Strings by Nutria · · Score: 1

      If you are seeking a language to write administrative applications then you should look further. COBOL back in the days or Java nowadays would suit you better.

      Too bad that Computer Scientists are a bunch of elitist Haters who only know COBOL from legend. Even back in the day, CompSci professors loathed/disdained it, and the most popular textbook series was from the grossly incompetent Shelly & Cashman.

      Once I re-learned it from people who grokked the language, I discovered how powerful it is at it's intended task.

      Finding people willing to write in it is hard, though, so -- before Java -- many managers decided that business apps would be written in C rather than the appropriate language.

      --
      "I don't know, therefore Aliens" Wafflebox1
    14. Re:Null Terminated Strings by Teckla · · Score: 1

      I believe none of you actually programmed in C. A string terminated by \0 can be represented by a single pointer and an have any length. You can also easily let the string keep growing (until the allocated memory is finished.) That is the epitome of KISS.

      And a written language with just two letters in the alphabet is simple too, right? So, let's do that!

      There's KISS and then there's KISS. C strings aren't the right kind of KISS.

    15. Re:Null Terminated Strings by davidwr · · Score: 1

      [kernel/library programmers] must be very concise

      That used to be but these days it's frequently okay or even desirable to add functionality like input-parameter-validation rather than be concise and skip the validation, leaving a gaping security hole in kernel or other code which may run with privileges high enough to be dangerous.

      Likewise, it may be desirable to have a larger piece of code that can test for the presence of hardware that may or may not be present and exploit it if it is there than to have smaller, simpler code that does things in a way that will work everywhere, but which will not take advantage of hardware that might be available.

      Notice that I said "may be." Part of the art and science of engineering your code is knowing the trade-offs between "smaller, simpler, but less feature-rich" and "bigger, more complicated, but more feature-rich" and knowing the intended and possibly-un-intended uses of your code and how much time and effort you and others have to create the code and maintain it later, then make the correct engineering choice for your particular situation.

      --
      Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
    16. Re:Null Terminated Strings by skids · · Score: 1

      I'd still prefer if pointers could keep both address and size of the buffer.

      Then use a struct with pointer and length. Use the right tool for the right job. ZTSs are for things that utilize the efficiency of knowing nothing is sending you strings longer than you can handle efficiently and can take advantage of not having to worry about syncing a length counter in RAM. If you use the functions that use ZTSs for multimegabyte content that you need to find the length of frequently, you're using them wrong.

      As crotchety as C is, at least they realized that a toolbox full of nothing but powered hammerdrivers is less than fully useful.

      (If only they had handled endianness better. Or at all.)

    17. Re:Null Terminated Strings by gnupun · · Score: 1

      When you're trying to make a hardware-agnostic language, it was probably deemed wise to stay away from the issue and just null terminate.

      Yeah, imagine null-terminating a 2 MB string and then trying to obtain its length in some operation... too much processor time wasted.

    18. Re: Null Terminated Strings by gnupun · · Score: 1

      Okay, but we're dealing with C and even in C++ you have to deal with null-terminated strings. Here's a case that is not extreme at all: copying a 100-byte string to another. Read below how inefficient the null char makes this very common and very basic operation.

      One example is FreeBSD's libc, where the bcopy(3)/memcpy(3) implementation will move as much data as possible in chunks of "unsigned long," typically 32 or 64 bits, and then "mop up any trailing bytes" as the comment describes it, with byte-wide operations.

      If the source string is NUL terminated, however, attempting to access it in units larger than bytes risks attempting to read characters after the NUL. If the NUL character is the last byte of a VM (virtual memory) page and the next VM page is not defined, this would cause the process to die from an unwarranted "page not present" fault.

      http://queue.acm.org/detail.cf...

    19. Re:Null Terminated Strings by bingoUV · · Score: 1

      I agree with the argument of having limitless strings - KISS principle is followed in C correctly, but only because limitless strings are desirable.

      It is not true that this is simpler than storing size separately. If storing size separately is a complication, inability to store \0 in a string is a limitation. We can work-around it by escaping, but then it adds complication, which was supposedly avoided by not storing size.

      So it was a choice between 2 kinds of complications, one of the complications was chosen because limitless strings were more useful than the ability to store evere possible byte in a string. Not an unconditional KISS.

      --
      Bingo Dictionary - Pragmatist, n. A myopic idealist.
    20. Re:Null Terminated Strings by SpaghettiPattern · · Score: 1

      You can't have a string longer than the amount of memory that is reachable by a pointer.

      Did you reread what you wrote? A pointer is nothing more or less than a memory address. A string pointer points to the first character in the string and the string can have any length (theoretically.)

      Do you mean, perhaps, that you can't have a C string that doesn't fit into memory all at once? Let's assume you do. That would be an academic limitation. I have never ever encountered a string so big. If you have the need to handle such enormous strings then you probably should study streaming (of characters or bytes.)

      You don't say. Sounds like this is relatively new to you.

      That's a silly tone you'd better ditch buddy.

      The former must be very concise

      That's complete nonsense. Source code size has nothing to do with object size, let alone suitability of a language for different problem domains. C's conciseness was useful in the 1970s and 80s, where memory used for source code whilst editing and compiling was a significant factor. Nowadays 10s or hundreds of K of source code is irrelevant in GB sized PC memories. The conciseness is worthless.

      I give to you that concise was the wrong word to use. However, well abstracted problems result in concise code and object, while at the same time the code remains readable. Beating the optimizer is foolish, but shouldn't be mistaken with well analyzed problems. Simply punching away in order to scratch the itch is a guarantee for revisiting the code unnecessarily.

      --

      I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
    21. Re:Null Terminated Strings by BasilBrush · · Score: 1

      Do you mean, perhaps, that you can't have a C string that doesn't fit into memory all at once? Let's assume you do.

      That would be a very bad assumption, both because it isn't what I mean, and because it's irrelevant to the issue. Every element of a C string is addressable by a pointer. Regardless of whether it is real or virtual memory addressing. If you're talking about a stream that isn't addressable by a pointer, that's NOT a C string. A C string is a char*. A stream is NOT a C string even if it happens to be null terminated.

      Think I'm wrong? Then tell me what the result of strlen(). It doesn't even make sense.

      However, well abstracted problems result in concise code and object

      That's a quality of the algorithms and patterns used by the programmer, not the language.

      Simply punching away in order to scratch the itch is a guarantee for revisiting the code unnecessarily.

      Well that's a whole different discussion, for which you are just stating your point of view. Agile development methods tend towards writing the minimum code for a limited feature set, and adding and refactoring constantly. I'm not advocating either here as it would take us down a different path, but I just mention it because it shows you're just presenting your opinion, not anything objectively right.

    22. Re:Null Terminated Strings by SpaghettiPattern · · Score: 1

      The problem is that you usually don't know where the the allocated memory is finished.

      I understand the rationale behind the pointers like they are, but I'd still prefer if pointers could keep both address and size of the buffer. But it's too late now for such kind of redesign or upgrade.

      I understand what you mean. For most projects I do I share your desire to be slightly more casual with memory management. Although I am in the fortunate position to be able to choose a different language (I'm happy to use Java's StringBuilder to append ad infinitum), I cherish the basics I learned when I programmed C. Being able to think in the most basic elements is yet another perspective.

      --

      I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
    23. Re:Null Terminated Strings by SpaghettiPattern · · Score: 1

      Too bad that Computer Scientists are a bunch of elitist Haters who only know COBOL from legend.

      It's cheap to knock a language with a huge installed base as COBOL, mostly because the syntax and the conventions are slightly awkward for "modern" eyes. (I say modern but the elitist dislike for COBOL I believe started in the 70ies.) COBOL is damn good at solving the kinds of problems it was designed for. I have even seen a shop that had/has a COBOL backend to the web applications it offered/offers.

      --

      I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
    24. Re:Null Terminated Strings by alexo · · Score: 1

      I believe none of you actually programmed in C. A string terminated by \0 can be represented by a single pointer and an have any length. You can also easily let the string keep growing (until the allocated memory is finished.) That is the epitome of KISS. If you use an 8 byte character at the beginning then you are limited to a string length of 255. A structure with a length and a string pointer (or a character array) is much more complex and that would reflect in more complex library functions.

      Some of us have been programming in C for 3 decades and have gained some sense of perspective. While the choice of using null-termination vs. explicit size may have been the correct one given the '60s and '70s state of the art, it is a poor one today.

      Null-terminated strings have several serious deficiencies:
      They cannot be used to store binary data, requiring another, redundant set of functions (with separate lengths)
      Similarly, they cannot be used to store UTF-16
      They are less efficient. In order to find the length of the string, get it's last character(s) or append to it, you must traverse it. If the string is long, parts of it may reside on pages that have been swapped out and touching them will trigger expensive IO operations.

      There is a reason that every OO library uses a length+data for string objects

    25. Re:Null Terminated Strings by angel'o'sphere · · Score: 1

      You got it all wrong, it is screws!
      Screws with a screw nut on the other side.
      Very carefully aimed holes to put the screw through. Very carefully arranged and finally fitted with a screw nut and finally made tight with a spanner!

      How can you mix that up with a mere baton spiked with nails?

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  62. Best feature ever: Intercal (and others) COMEFROM. by slashdice · · Score: 1

    I prefer Intercourse's COMEIN feature.

    --
    Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
  63. The C pre-processor by Chelloveck · · Score: 2

    The C pre-processor. The whole thing. The CPP is without a doubt the biggest WTF in language design. Hey, this C language is neat and all, but how about if we make it so that before you compile it you have to run it through a whole separate language processor with different syntax designed to do string substitution? And let's use that language to implement comments. And hey, how about using it to import common files? But since it's really just a string substitution, the import really just dumps a verbatim copy of the common file into the one being processed. If you have two identical include lines you get two copies of the common file inserted. Wouldn't that be *great*!?

    Okay, I understand the historical context and why it made sense at the time. I really do. But from a modern perspective it's definitely not in any way the sane way to do it.

    And for an honorable mention, how about the use of leading whitespace in Makefiles? Not only is leading whitespace significant, starting a line with spaces has a different meaning than starting a line with tabs!

    --
    Chelloveck
    I give up on debugging. From now on, SIGSEGV is a feature.
    1. Re:The C pre-processor by 91degrees · · Score: 1

      If you have two identical include lines you get two copies of the common file inserted. Wouldn't that be *great*!?

      The real beauty is that they can (and usually do) behave differently.

    2. Re:The C pre-processor by Jamu · · Score: 1

      The C pre-processor is the duct tape of C programming.

      --
      Who ordered that?
  64. csh by dskoll · · Score: 1

    csh is one big wtf. Those of you on Linux/UNIX boxes with csh active, start csh and then type:

    else

    Keep typing stuff in.

    breaksw does the same thing. Who wrote that parser?

    1. Re:csh by beschra · · Score: 1

      That's just evil.

      --
      It is unwise to ascribe motive
  65. Re:PHP by Anonymous Coward · · Score: 1

    I can’t even say what’s wrong with PHP, because— okay. Imagine you have uh, a toolbox. A set of tools. Looks okay, standard stuff in there.

    You pull out a screwdriver, and you see it’s one of those weird tri-headed things. Okay, well, that’s not very useful to you, but you guess it comes in handy sometimes.

    You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways.

    You pull out the pliers, but they don’t have those serrated surfaces; it’s flat and smooth. That’s less useful, but it still turns bolts well enough, so whatever.

    And on you go. Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. And there’s no clear problem with the set as a whole; it still has all the tools.

    Now imagine you meet millions of carpenters using this toolbox who tell you “well hey what’s the problem with these tools? They’re all I’ve ever used and they work fine!” And the carpenters show you the houses they’ve built, where every room is a pentagon and the roof is upside-down. And you knock on the front door and it just collapses inwards and they all yell at you for breaking their door.

    That’s what’s wrong with PHP.

    Yup. That sums it up for me.

  66. Re:Perl by dskoll · · Score: 2

    I actually like Perl statement modifiers; they can make code more readable if used judiciously. Something like:
    return unless $DEBUGGING;
    can be pretty useful. Obviously, something like:
    $a += $b * complex_function($c, $d, $e) unless ($x > 100.7 && pre_condition($d, $c, $e));
    is not good.

  67. R data.frame subsetting by pmarinus · · Score: 1

    A subset of a data.frame is a data.frame, unless you haven't set drop = FALSE, and "select" only one column.
    By default "the result is coerced to the lowest possible dimension. The default is to drop if only one column is left, but not to drop if only one row is left."
    When a result is reduced to 1 dimension its type changes, and R will throw an error if you use a data.frame method on the result.
    I advise anyone using R seriously to read The R Inferno to learn to avoid the many non-obvious features of R

  68. MSSQL by netsavior · · Score: 3, Interesting

    I love the various different parsers MSSQL uses, and how very wrong things can go. Run this in SQL management studio and it will work fine... run it from the command line and it will give the below error. It will find \r\nGO\r\n and treat it as a block terminator... even if it appears in comments. This is the only command that it will find and execute within comments.

    declare @var as int
    set @var = 10
    print @var
    /*
    this is totally in the comments
    GO
    */
    print @var
    ------------
    output -
    ------------
    10
    Msg 137, Level 15, State 2, Line 1 Must declare the scalar variable "@var".

    1. Re:MSSQL by shutdown+-p+now · · Score: 1

      This is because "GO" is not actually a feature of Transact-SQL (the language itself) - it's a feature of the command line REPL, to signify end of input and beginning of execution. So it's not parsing the SQL there, it's just looking for a line that matches "GO", and then takes all the preceding text and hands it over to the server - which then actually parses it as SQL.

  69. Array indexing in C behaves like pointer math by tboulan · · Score: 1

    "I don't see it as a feature - so much as exposing the core of what C is about. Its all about pointers and getting to the memory directly with as little indirection as possible. Kind of beautiful, really." Michael Neale

    You could replace "Michael Neale" with NSA or credit card black hats, and make the quote even better.

  70. Impossible triangle of string comparisons by tepples · · Score: 1

    My approach is generally to always use "===" and explicitly cast things. It makes your errors more explicit.

    What you suggest is helpful for equality but not inequality, as I'm not aware of any <<< or >>> operator that means "less than and of the same type as" or "greater than and of the same type as" in the same sense that === means "equal to and of the same type as". The following impossible triangle of comparisons returns true in PHP:

    var_dump('123' < '123a' && '123a' < '45' && '45' < '123');

    1. Re:Impossible triangle of string comparisons by MightyYar · · Score: 1

      Sorry, I didn't mean to accidentally defend PHP :)

      --
      W..w..W - Willy Waterloo washes Warren Wiggins who is washing Waldo Woo.
  71. Metapost by Required+Snark · · Score: 2
    Metapost is a part of Knuth's TeX suite of languages. http://en.wikipedia.org/wiki/MetaPost. It is a graphic language that emits Postscript and supports spline line drawing. It was derived from Metafont, the font generation language for TeX.

    First, Metapost is implemented as a macro language, so it is similar to C shell languages in the way it is evaluated. The symbols x, y, and z are predefined macros. For a location x the construct 3x is three times x. There are built in lengths, so 2cm and 1in are lengths. You can extend the language by defining you own macros for prefix or uinary and binary operations, which is the way that many of the operators are implemented.

    The if and loop syntax

    if boolean1 : expr1; else: expr2; elseif boolean2: expr3; fi

    for i=1 step t until n: statement; statement; endfor

    There are four levels of precedence. This is why multiplication by a constant can be expressed by putting a number in front of a value.

    These are just some of the syntax features. The data types include splines, transforms, colors and numeric pairs for points. Built in operations can find points where two curves intersect and sub-curve sections between intersections.

    It's fun in a strange fashion, and you can make some interesting geometrical pictures.

    --
    Why is Snark Required?
    1. Re:Metapost by NJRoadfan · · Score: 2

      Postscript itself can be fun and interesting. Many folks have taken it well beyond a page description language. Don Lancaster has been using it as a general purpose programming language for years: http://www.tinaja.com/post01.s...

      How about a Postscript web server? http://www.pugo.org:8080/

  72. gcc -Wall includes -Wparentheses by tepples · · Score: 1

    get neat one-liners for a thing most C programmers don't bother to do

    Not bothering to check whether an allocation succeeded is a problem.

    at the expense of adding a hard to notice source of bugs to every if statement.

    Several compilers display a diagnostic for if (variable=value) which is silenced with if ((variable=value)). GCC for example offers -Wparentheses to warn "when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often get confused about."

  73. Re:Perl by preaction · · Score: 1

    5.20 finally added proper subroutine signatures, so you don't have to unwind the @_ (alias to the Perl stack) yourself, but I'm glad someone else mentioned this one as "strange".

    It's less strange when you finally grok the technical details behind it, but I was doing Perl for 12 years before I finally got it.

  74. COBOL WHILE loops by hudsucker · · Score: 1

    Standard COBOL (COBOL-85) has both DO WHILE and DO UNTIL loops. But UNTIL loops are actually WHILE loops: they test the exit condition before executing the loop.

    If you really want an UNTIL loop you have to code extra syntax:

    perform until condition with test after
      statements...
    end-perform

    1. Re:COBOL WHILE loops by shutdown+-p+now · · Score: 1

      This seems perfectly logical to me. There's nothing about "UNTIL" that implies that condition will be tested after the loop - the only meaning that the word carries is the negation of the condition. I suspect that this confusion comes from Pascal, where "repeat .. until" was the way to write loops with condition testing after the body - but there it was more a quirk of a language, and "until" by itself still just meant negation of the condition; the order of evaluation was defined by the relative ordering of parts of the loop in the syntax:

      while condition do staement;
      repeat statement until condition;

      In your example, "perform until condition" comes before "statements", so it makes perfect sense to check the condition first.

      The best syntax for such loops was actually in MS dialects of BASIC (QBasic, VB etc) - it had WHILE, UNTIL and pre- and post-conditions in all the possible combinations, as well as infinite loop, all syntactically uniform and very obvious:

      DO
      ..
      LOOP
       
      DO WHILE condition
      ..
      LOOP
       
      DO UNTIL condition
      ..
      LOOP
       
      DO
      ..
      LOOP WHILE condition
       
      DO
      ..
      LOOP UNTIL condition

    2. Re:COBOL WHILE loops by hudsucker · · Score: 1

      Yeah, but remember that inline statements didn't come until the addition of explicit scope delimiters. The most common form actually is:

      perform routine-name
        until condition

      and in that case, the UNTIL really does come at the end. But it still is really a PERFORM ... WHILE.

      The fact is that this trips up programmers. They forget that they need to init the condition before the PEFORM, lest it never execute.

    3. Re:COBOL WHILE loops by shutdown+-p+now · · Score: 1

      Now that makes sense. Yeah, the way I'd read it is definitely by assuming that order of execution follows textual order.

      It sounds a lot like one of the quirks in ancient languages that slowly evolved over time. More recent BASIC dialects are also chock full of these (which is why it was very nice when QBASIC did a clean new syntax for loops).

  75. Re:Perl by preaction · · Score: 1

    Perl::Critic, the link you mentioned, doesn't disable things for you (but you're right in that you can get modules that disable core language things, like "no indirect"). Perl::Critic is a linter.

    Devel::Declare and now hooks into Perl's parser allow you to define your own parsing contexts! You can declare a keyword and say that inside here, I control the parsing, not perl. So many wild things one can do with that...

  76. Java iterators by tomhath · · Score: 1

    I never understood why an object has a method that returns an interator instead of having the methods themselves. There might be a good reason, but it has always escaped me.

    1. Re:Java iterators by Nedmud · · Score: 1

      It's because iteration needs to maintain state (namely, where you're up to in the collection). If this was stored on the object, then you wouldn't be able to have 2 iterations active at once. Things like this wouldn't work:

      // print all possible pairs
      for (Person x: people) {
      for (Person y: people) { // oops, now we're interfering with the iteration that's already happening over people
      System.out.println("Pair (" + x + ", " + y + ")");
      }
      }
      (Ugh, I forgot how to include code in a slashdot comment.)

    2. Re:Java iterators by shutdown+-p+now · · Score: 1

      Because iterator has iteration state, and you might want two parts of code to iterate over the same collection concurrently (it doesn't even have to be threads - it might be just nesting, e.g. a function is iterating over an array, and during one iteration calls another function which also iterates over the same array).

  77. Map multiple OpenIDs to a single account by tepples · · Score: 1

    The user is coming FROM those gatech.edu and whitehouse.gov domains to a third one.

    An OpenID relying party is allowed to map multiple identifiers to a single user account. So if gatech.edu and whitehouse.gov are OpenID providers, you can register using your identifier from gatech.edu, add your identifier from whitehouse.gov to the same account, and then get the same userid (which maps to the same grants) no matter which identifier you used. Stack Exchange supports this feature if I remember correctly, and I know the authentication system I wrote for PhilsHobbyShop.com supports it.

  78. Pascal boolean operators by chubs · · Score: 1

    FreePascal: logical and bitwise 'and' and 'or' are the same operator, it just chooses one for you based on the operands. Example: "if (i < 5 and j < 10)". The compiler tries to do a bitwise and of 5 and J, then compare it to i, and then it gets confused about how that result (a boolean) can be less than 10

    1. Re:Pascal boolean operators by shutdown+-p+now · · Score: 1

      This is standard Pascal, not specific to FreePascal. IIRC it was also the case for Modula-2, Delphi and other derivatives.

      It is actually fairly logical in a statically typed language. The only reason why C needs different operators for this is because it didn't have the boolean type originally, so you needed some way to tell whether these two integers are to be treated as bools or as collections of bits. Since Pascal always had proper booleans, it could just overload the same operator.

  79. Powershell by plopez · · Score: 1

    When I first saw PowerShell my first thought was it borrowed syntax from COBOL.

    --
    putting the 'B' in LGBTQ+
  80. Or things you can't do by phorm · · Score: 1

    I've always wished that you could do the following

        if ( a == b == c)
    or even
        if ( a c )
        etc

    But most languages you need

        if ( a == b && b == c)
    or
        if ( a b && b c )

    1. Re:Or things you can't do by phorm · · Score: 1

      UGH, htmlization ate my greater and less than signs!

    2. Re:Or things you can't do by david_thornley · · Score: 1

      In Lisp, you can do (= a b c) or (< a b c).

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  81. Python False = True by plopez · · Score: 1

    Programmers are rarely sane.

    --
    putting the 'B' in LGBTQ+
  82. Swift's ? and ! by Maury+Markowitz · · Score: 1

    No more needs to be said.

  83. Re:Everything in Objective-C by Maury+Markowitz · · Score: 1

    @sythesize MY_ASS

    When I first used it, circa '99, it was small, light, and looked great.

    Now, not so much.

  84. Re:Obvious answer by DeputySpade · · Score: 1

    +1 insightful! dark, dark evil.

    --


    This space intentionally left blank
  85. FORTH by david_thornley · · Score: 2

    : CELEBRATE FORTH LOVE IF HONK THEN ; and remember that : ? . ! ; is a straightforward part of the language definition.

    --
    "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  86. == operator in Java by vbguyny · · Score: 1

    The == operator in Java is similar to the == in C++ for strings where is compares the memory address and not the string value. I understand why this is in C++ because strings are pointers to chars but in Java the datatype is String. I was pulling my hair out in college on this one! Fyi, you need to use the equals function on Java to compare values.

  87. + operator for string concat? by HiddenL · · Score: 1

    '1' + 1; returns '11'. It's weird when you have javascript's type coercion.

  88. Re:Trinary by qbast · · Score: 1

    With states 0,1, 'whatever you say tovarisch!'.

  89. String concatenation operator in awk by Medievalist · · Score: 1

    In all the various awks the string concatenation operator is implicit. Brian Kernighan is quoted as saying "It seemed like a good idea at the time".

    Thus, awk literally has an invisible operator. Most coders make this a little more obvious with an explicit space, ASCII code 32 (decimal), but it's still invisible. Hijinks ensue.

    Other that this, awk is admittedly a great language for text processing. And the GNU awk is an exceptionally good version - it permits fixed fields and socket I/O and has numeric conversion operators.

    1. Re:String concatenation operator in awk by Gunstick · · Score: 1

      well, looks like awk borrowed stuff from everywhere.
      Like the invisible string concat reminds me of what echo does with it's parameters in the shell.

      and it's still my preferred way of doing things.
      I solved a lot of problems on codeeval.com with awk, and got quite good results. The code is really fast.

      --
      Atari rules... ermm... ruled.
  90. Quirk in MATLAB array syntax by jdagius · · Score: 1

    MATLAB was one of the first languages to allow lists of comma-separated numbers between square brackets e.g. [1,2,3,10] to be interpreted as indexed numeric arrays or vectors. A lot of languages do that now, but MATLAB was perhaps the first to do this in 1984. A little-known quirk is that the commas are optional! [1 2 3 10] etc. This was probably introduced as a 'convenience' feature (though typing a space isn't that much faster than typing a comma). But there is a glitch ("feature") in the syntax that interprets space-separated negative numbers differently than you'd expect. So [ 1 2 -3] is interpreted as [1,2-3] (value = [1,-1]) because the precedence of arithmetic operators is higher than list operations.

    MATLAB hasn't fixed this 'feature' yet, because it would undoubtedly break a jillion apps around the world. So you must be careful to type [1 2 (-3)] if you are allergic to commas.

    BTW it's been fixed by default in OCTAVE, MATLABS free-software clone, but you turn 'quirks' on, if you want to preserve the quirky behavior.

  91. Optional braces after if by eminencja · · Score: 1

    The parens in the condition should be optional instead. I think new languages (go, Perl6) do it like that.

  92. Platform lock-in by Shompol · · Score: 3, Insightful

    Platform lock-in is the strangest feature of some languages that purposely defeat all the progress we made since Assembler. This is why I will never C#

    1. Re:Platform lock-in by brystar · · Score: 1

      Actually I spent this week writing C# in Visual Studio for Android and IOS devices. The new Xamarin.Forms is fantastic, native UI but still cross platform C#. Microsoft doesn't seem to be locking anyone in and even standardized the platform enabling cross platform development.

    2. Re:Platform lock-in by Shompol · · Score: 1

      Beware of Greeks bearing gifts

  93. Sloppy typing in javascript by MichaelSmith · · Score: 1

    Pass the wrong type of object to a javascript library. The library happily accepts your crud, passing it through 14 levels of function calls and then says something useful like "a is not a function".

  94. Yes, there's only one right way - my way by raymorris · · Score: 1, Troll

    Perl is my preferred language for the majority of tasks that I do. I really like Perl overall. TIMTOWTDI annoys me, though. There is a right way to do it. Once is a great while, there are two correct ways, and still one best way.

    TIMTOWTDI seems more appropriate for PHP, "do it however, as long as it looks like it kinda works for now. It's not like we're actual programmers who know what we're doing".

  95. Checking enough? Careful programmers like post-* by raymorris · · Score: 1

    These two are very, very handy for careful programmers, who don't just assume that everthing always works, and that noone is trying to hack, or enter "weird" input like a name with a single quote, such as o'Malley.

    Examples:
    open(INPUT, $file) or die "Couldn't open input: $!");

    compare other languages, where being careful requires that every other line start with "if (!":
    if(!open(INPUT, $file) ) {
            die "Couldn't open input: $!";
    }

    Similarly:
    die ("That's an awfully long name") if (($name > 1024));
    vs:
    if ($name > 1024) {
            die("That's an awfully long name");
    }

    If you're regularly checking your assumptions, I think the syntax is very handy.

  96. magical extra parens by raymorris · · Score: 1

    I'm not sure how I ended up typing those extra parens. Odd.

  97. Objective-C by LihTox · · Score: 1

    No one's mentioned Objective-C's bracket notation for calling methods. Instead of obj->method(argument) or obj.method(argument), it's [obj method:argument]. Perfectly logical I'm sure, but the few times I've tried to write Objective-C code I've always had a hard time wrapping my brain around it.

  98. Tcl by LihTox · · Score: 1

    Tcl is strange in a number of ways. One is that you don't assign variables by saying "x=5", you write "set x 5" instead. Nor can you do any calculations outside of the expr command (in most cases), so instead of writing "x=5*y+3", you would write "set x [expr 5*$y+3]"

    I'm still fond of Tcl/Tk, in spite of that. :) What other language can give you a text editor in one line? "pack [text .t]"

  99. MUMPS by jdschulteis · · Score: 1
    MUMPS, where every keyword has a 1-to-3 letter abbreviation, resulting in code like this:

    %DTC
    %DTC ; SF/XAK - DATE/TIME OPERATIONS ;1/16/92 11:36 AM
    ;;19.0;VA FileMan;;Jul 14, 1992
    D I 'X1!'X2 S X="" Q
    S X=X1 D H S X1=%H,X=X2,X2=%Y+1 D H S X=X1-%H,%Y=%Y+1&X2
    K %H,X1,X2 Q
    ;
    C S X=X1 Q:'X D H S %H=%H+X2 D YMD S:$P(X1,".",2) X=X_"."_$P(X1,".",2)
    K X1,X2 Q
    S S %=%#60/100+(%#3600\60)/100+(%\3600)/100 Q
    ;
    H I X S %Y=$E(X,1,3),%M=$E(X,4,5),%D=$E(X,6,7)
    S %T=$E(X_0,9,10)*60+$E(X_"000",11,12)*60+$E(X_"00000",13,14)
    TOH S
    %H=%M>2&'(%Y#4)+$P("^31^59^90^120^151^181^212^243^273^304^334","^",%M)+%D
    S %='%M!'%D,%Y=%Y-141,%H=%H+(%Y*365)+(%Y\4)-(%Y>59)+%,%Y=$S(%:-
    1,1:%H+4#7)
    K %M,%D,% Q
    ;
    DOW D H S Y=%Y K %H,%Y Q
    DW D H S Y=%Y,X=$P("SUN^MON^TUES^WEDNES^THURS^FRI^SATUR","^",Y+1)_"DAY"
    S:Y
    [...]

    1. Re:MUMPS by brausch · · Score: 1

      It's even worse than you think! :-) White space is significant (reminds of makefiles and tabs vs spaces). The above source isn't quite right. There need to be TWO spaces after the Q:'X in the line beginning with a C.

      Having said that, I love programming in this language (well, Intersystems Caché actually). The database and language are fully integrated with a very powerful standard library.

      --
      "Almost every wise saying has an opposite one, no less wise, to balance it." - George Santayana
  100. C# GoTo statement by BladeMelbourne · · Score: 1

    The C# GoTo statement is pretty uncommon to see in use:

    http://msdn.microsoft.com/en-u...

  101. Total control by Horus1664 · · Score: 1

    Gotta love a BXLE or perhaps a CDS for those special occasions? Or what about a MVO? (You know who you are)

  102. end of line codes by John_Sauter · · Score: 1

    Probably the same way that most popular operating systems store text files as a list of lines separated by newline characters, encoded as 0x0A on UNIX or Windows but 0x0D on Apple II or classic Mac OS. VMS is an exception in that its "non-stream" text files have each line prefixed by its length.

    The conventions for line endings are based on history. DEC's operating systems and operating systems descended from them use CRLF because that is what you had to send to an ASR-33 teletype at the end of an output line. UNIX and its descendents use NL, which has the same code as LF, because they were targeted at later printers.

    By the way, the VMS record length field was 16 bits, avoiding the limitation of 255 characters in systems which used only 8 bits for the string length.

  103. Matlab is full of strange features by drolli · · Score: 1

    -Possibility to access the "parent" scope
    -Distinction between "workspace scope" and "global variables"
    -Really weird stateful behaviour when using/declaring global variables
    -Impossibility to redirect the output of commands under special circumstances
    -Lazy copy in combination with slices (yeah, awfully practical, but run a profiler to see what happens)
    -At least two different ways of associating data with "handle objects"
    -"handle objects" (feels like the early 80s)
    -weird scopes for function declarations
    -absence of a decent "map" operator
    -half-assed "function handles"

  104. Object Vs Primitive by Greyfox · · Score: 1

    In assorted languages. Java and vbscript being particularly problematic, if you're a library programmer. "Oh, I'd like to write this generic container of things but I can't make it generic because some programmer might try to store an int in it :-/" Java's introduced some features to address that, and it's quite easy to solve in vbscript by never programming in vbscript.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  105. Perl, PHP, Lingo, Transcript, TypoScript, Lisp by Qbertino · · Score: 1

    Perl is pretty bizar in a hilarious sort of way - almost every aspect of it. PHP, being Perls former template engine, sheds most of that just to add in it's own featureset from wonderland. Both get the job done, PHP a little more so.

    Coulnd't say that for Lingo though. As far as regular usage PLs go, Lingo is about as shitty as it gets. 'Please' is an actual Lingo keyword - with no effect other than to make the sourcecode more polite. No joke. And seriously - that is not even its crappiest feature. If you want to kill braincells and a mixture of crystal meth and crack isn't fast enough, check out Lingo. Gladly it's basically gone extinct since the demise of Director, its platform.

    Transcript is simular to lingo, without the outlandish crappyness - but still pretty bizar.

    TypoScript is Typo3s configuration language. Think of a total programmer n00b learning just enough PHP4 to do turing complete stuff then inmediately trying to implement Basic for his CMS with it and failing one 3rd it but keeping the ruins as main means of configuration. Typoscript is what happens when a guy who can't programm takes psychoactive drugs and then takes a shot at it.... Luckyly there are some good oreillys on it, which makes it bearable. Sort of.

    Perhaps the language with the most bizar appearance is Lisp./eLisp. How anyone could come up with that syntax is totally beyond me. It must be realy powerfull if it is still around. ... Then again, emacs is a very strange programmin itself, so no supprise here.

    --
    We suffer more in our imagination than in reality. - Seneca
  106. wat by spyke252 · · Score: 1

    I'm surprised no one has posted wat yet. Even though it's a video, I really found it interesting and funny.

  107. C has bigger problems than that trivia by bzipitidoo · · Score: 1

    The "if (a = b)" syntax is among the first things newcomers to C are warned about. It's not a big problem.

    Null terminated strings are a bigger problem. What do you do if you want to embed nulls in a string? Not use the entire string.h library for starters, have to write your own routines. It really is better to store the length in a simple integer, as long as it's not stupidly small like in Turbo Pascal where they set aside one measly byte, thus making the maximum length a paltry 255 characters. There are simply too many use cases where length information is needed. Having the length makes a strlen function trivial and run in constant time, instead of a time dependent upon the data. We now have the String class in the Standard Template Library which addresses these problems.

    Bigger yet are the limitations of the function call syntax. This is not just C, but most programming languages that originated in those times. Most functions have a fixed number of parameters. If it's known how many parameters there are, it is not necessary to enclose the list. Basic math is done without that, eg. c = a +b instead of something gross like equal(&c,add(a,b)), Why can't functions be done the same way? Because they decided to allow variable numbers of parameters, with the printf function being the most prominent example of such a function. This was done in a very awkward manner. Consequently, most programmers avoid it. But we still have to include the parentheses even for functions with a fixed number of parameters. C enshrined parentheses as basically a sigil to distinguish function names from variable names. What does C gain from this? The ability to curry? No. Recursive functions? No, don't need variable length parameter lists for that, it does recursion anyway. The good in C's function syntax is that the programmer doesn't have to use a key word like "call" to call a function, and C has no unnecessary distinction between a function and a "procedure" as in Pascal. Can sort of do some functional style programming by passing pointers to functions. But they didn't get functions good enough. Operator overloading is an ugly hack that tries to address these inherent deficiencies. It doesn't succeed, can't go far enough. Same with polymorphism and name mangling. And C++'s addition of prefacing a parameter with an ampersand is nice, but merely a syntactic shortcut. The latest C/C++ standards also nibble at this problem with things like the introduction of "auto". But it still has the fundamental problem of excessive parentheses, like in LISP. C is all about brevity and economy, in both syntax and compiled code, but in this, they didn't do as well as they could have.

    Then there's parallel programming. C wasn't designed for it, and can't do it clearly and cleanly. To be fair, there isn't a general purpose language that really nails parallel programming. Does it make sense to have to clear an array by using a loop, as in "for (i=0; i<MAX; i++) a[i] =0;"? Not if you're trying to use the massive parallelism of current commodity graphics cards. To this day, parallel programming remains a sort of black art, to be attempted only by the most skilled and intrepid programmers. Similar to the reputation that assembler still has in some programming circles, or that network programming used to have (sockets, ooh, scary!) Just include the magic library and call the magic functions, let them handle the complexities.

    And that brings me to the next point, the libraries. The language designers didn't put enough consideration into libraries, or they would have realized how huge the entire set of libraries could get and made some provisions for that. Instead, years later namespaces were added. The next problem with the libraries is related to the problems with function calls. The library interface is too language specific. Those header files are a mess that makes it much harder for another language to use the related functions. A common solution is to resort to "wrappers", like m

    --
    Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
    1. Re:C has bigger problems than that trivia by skids · · Score: 1

      Null terminated strings are a bigger problem. What do you do if you want to embed nulls in a string? Not use the entire string.h library for starters, have to write your own routines.

      Yes. Because those are different constructs. Live with the fact that both are useful.

      Having the length makes a strlen function trivial and run in constant time

      And having a hash makes ==/=! run in constant time most of the time. And then you could also add an indicator for encoding. And some flags for the garbage collector or if not that at least a COW flag. And then suddenly you find you're using more than a cache line for just one variable in a critical code section even when you're pabsolutely sure the string can only contain "TRUE" or "FALSE". And that is part of why my applications seem to run slower and slower every year despite my hardware being upgraded.

      Personally I prefer functions to use parens. Like in math. It makes sense visually and keeps things organized. Are you allergic to the shift key or something, or do you just enjoy the mental challenge of parsing things in your head. You'd seriously prefer this:

      thingA thingB thingC,4,7,thingD thingE

      to this:

      thingA(thingB(thingC(4,7)),thingD(thingE))

      ?

      For which one do you have to consult the documentation, if even extant, to figure out the arity of things?

    2. Re:C has bigger problems than that trivia by bzipitidoo · · Score: 1

      Ever used a Reverse Polish calculator? Or postfix or prefix notation? It does work. Yeah, I seriously would prefer prefix notation to superfluous parentheses.

      Maybe you feel it's unclear? There's an answer to that too. Whitespace, as in Proper Indentation.

      thingA
      . thingB
      . . thingC 4 7
      . thingD thingE

      Before you ask, no, the whitespace is not required, This isn't Python. It is merely there to aid coders, same as any other indentation in C source code.

      --
      Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
    3. Re:C has bigger problems than that trivia by skids · · Score: 1

      Well
      you
      can
      go buy
      a
      500x65000
      resolution
      monitor
      then.

  108. Article is clickbait wank... by Aardpig · · Score: 1

    ...none of its examples are in anyway WTF. I can't believe nobody has mentioned Fortran's arithmetic IF yet...

    --
    Tubal-Cain smokes the white owl.
  109. MUMPS by brausch · · Score: 1

    In MUMPS, now mostly used in Intersystems Caché, white space is significant in a strange way. There are places where one space is required and other places where two spaces are required.

    --
    "Almost every wise saying has an opposite one, no less wise, to balance it." - George Santayana
  110. no by fisted · · Score: 1

    > if (a = b) assigns the contents of b to a and executes the code following if b 0. Who the hell thought that would be a good idea?

    There are indeed times it is useful but I 100% agree, using the _same_ syntax as assignment was full retard.

    The same syntax as what exactly? = is just assignment, nothing else.

    They should of used:

    You should of used "have". And your proposal is utter crap.

  111. Re:C by jrumney · · Score: 1

    sizeof(string) (I may have got the name of the function wrong) returns the length of a single byte rather than the length of the entire string.

    Not quite, it should return the size of a memory pointer on the target machine, since that is what a "string" is in C.

  112. White space matters by xMonkey · · Score: 1

    FU makefile and the bastard who thought it was a good idea.

  113. Use Deslide! by antdude · · Score: 1

    http://deslide.clusterfake.net... d.com/slideshow/163234/head-scratchers-10-confounding-programming-language-features-434442 OR http://desli.de/11J3

    --
    Ant(Dude) @ Quality Foraged Links (AQFL.net) & The Ant Farm (antfarm.ma.cx / antfarm.home.dhs.org).
  114. JS by elbazo · · Score: 1

    Whole of javascript. absolute fucking mess.

  115. Maybe it is trying to preserve sig figs? by Marrow · · Score: 1

    Maybe it does not want to promote the number of significant figures that integer represents?

  116. Re:C by smellotron · · Score: 1

    it should return the size of a memory pointer on the target machine, since that is what a "string" is in C.

    A string literal in C is of type char[N] (where N is the minimum value required to store the whole string, including the null terminator). String literals degrade to pointers quite easily, so yours is a common error. So...
    const char direct[] = "string";
    const char *const indirect = "string";
    sizeof(direct) == 7;
    sizeof(indirect) == sizeof(char*); // 4 or 8 on most 32- or 64-bit architectures, respectively

  117. JavaScript parseInt base for leading 0 changed by Paul+Fernhout · · Score: 1

    http://www.w3schools.com/jsref...
    "Note: Older browsers will result parseInt("010") as 8, because older versions of ECMAScript, (older than ECMAScript 5, uses the octal radix (8) as default when the string begins with "0". As of ECMAScript 5, the default is the decimal radix (10)."

    --
    A 21st century issue: the irony of technologies of abundance in the hands of those still thinking in terms of scarcity.
  118. Re:Perl by benthurston27 · · Score: 1

    Lol I guess that's why they don't have an obfuscated perl contest it would be too hard to decide who won.

  119. Re:C by jrumney · · Score: 1

    If you think all strings can be defined as const char arrays, then your experience with C programming must be very limited. The vast majority of strings in use in real world programs are neither const, nor defined as arrays.

  120. Re:C by smellotron · · Score: 1

    If you think all strings can be defined as const char arrays

    Lucky for both of us, that's not what I think. I specifically said "string literal", which is a const array and not a pointer. This is relevant for the sizeof discussion because the operator is evaluating the size of the array (therefore the entire string) and not just evaluating the size of a pointer.

  121. Re:Alter by shutdown+-p+now · · Score: 1

    Well, except labels don't necessary point to the function entry.

    But the craziest version of this that I've seen is in Algol-60. There, "label" is actually a data type of sorts - while you cannot declare variables of that type, you can use it to declare procedure (function) arguments. At runtime, the procedure can then goto such a label argument, which allows for a nonlocal exit to the point designated by the caller (in effect, this is setjmp/longjmp - devised in 1958!).

    They also had the notion of a "switch", which is basically an array of labels - either locally declared, or also passed as a procedure argument in a similar fashion.

  122. A language with only one operator by descubes · · Score: 1

    XLR (http://xlr.sf.net) has essentially a single operator, -> which reads as "transforms into". The rest is defined in the library.

    (OK, to be honest, that's the theory. In practice, the current language implementations take many shortcuts).

    --
    -- Did you try Tao3D? http://tao3d.sourceforge.net
  123. Malbolge's useless encryption by grewil · · Score: 1

    I find Malbolge's encryption an interesting and nice feature. After an instruction is executed, the value of the current instruction (without anything added to it) will be replaced with itself mod 94. Then, the result is encrypted with one of two methods.

    http://en.wikipedia.org/wiki/M...

  124. Re:Best feature ever: Intercal (and others) COMEFR by cold+fjord · · Score: 2

    Elxsi Fortran had it long ago.

    Richard Maine in FORTRAN IV program illustrating assigned GO TO on web site

    The Elxsi compiler in the mid 80's actually implemented the comefrom
    statement (and several variants) as a continuation of this spoof. It
    wasn't documented, but I found out about it when Ralph Merkle (one of
    the developers) suggested that I might be amused by looking at a certain
    area in the compiler executable file. When I did so, I found a list of
    strings containing mostly familliar Fortran keywords. Amidst those, I
    spotted comefrom. A quick check verified that the statement actually
    compiled and worked as "expected".

    I later heard that the statement was pulled from the compiler after a
    customer submitted a bug report (I think it was a
    performance/optimization issue) related to the comefrom statement
    implementation. The joke wasn't worth actually investing scarce support
    resources on.

    --
    much of left-wing thought is a kind of playing with fire by people who don't even know that fire is hot - George Orwell
  125. Haskell by rdnetto · · Score: 1

    The following is perfectly legal Haskell, and does exactly what it looks like:

    x = 2 + 2 where 2 + 2 = 5

    --
    Most human behaviour can be explained in terms of identity.
  126. Python's whitespace is a feature! by strombrg · · Score: 1
    I'm completely serious. Once you get over the initial "Ew, how FORTRAN77!", it's very nice.

    http://stromberg.dnsalias.org/...

  127. Self-modifying BASIC by PhilHibbs · · Score: 1

    My dad and I wrote a BASIC interpreter for the IBM PC in the '80s called BBasic, based on the Acorn BBC Micro dialect. BBC BASIC had an "EVAL" function, where it took a string and interpreted it as an expression. I persuaded dad that we should expand this functionality to an EXEC statement, that would take a string and interpret it as BASIC commands. If you put a line number at the start of the string, it would insert the code in the string into the program that was running - so you could have self-modifying BASIC code. There was one restriction, that if any of the points in the call stack were prior to the inserted statement, then it would fall over in a very untidy heap.

    It actually turned out to be pretty useful, the one used that I can remember was to store persistent data within the program itself, and you could save a program as an executable that included a runtime interpreter.