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?"

88 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 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.

    2. 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.
    3. 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.
    4. 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.
    5. 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
    6. 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.

    7. 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. ;)

    8. 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.
    9. 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.
    10. 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
    11. 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.

    12. 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.
    13. 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.

    14. 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'.

    15. 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.

    16. 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!

    17. 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.
    18. 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.
    19. 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.

  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 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. -
    3. 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
    4. 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.

  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 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?

  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.

  5. 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 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
    3. 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.
    4. Re:Lua[0]? by Uecker · · Score: 2

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

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

    5. 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
    6. 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'
    7. 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).

  6. 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

  7. 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 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.

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

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

    3. 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.
  8. 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.
  9. 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

  10. 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.
  11. 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 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; }
  12. 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.

  13. 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?
  14. + 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 narcc · · Score: 2

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

    3. 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.

  15. 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.

  16. 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/

  17. 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.

  18. 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/...

  19. 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... )

  20. 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?
  21. 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.

  22. 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.

  23. 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 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
  24. 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
  25. 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.

  26. 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.

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

    Not any more with lambdas:


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

  28. 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.

  29. 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.

  30. 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.
  31. 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 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.

    2. 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.

    3. 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)
  32. 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.
  33. 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.

  34. 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".

  35. 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/

  36. 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
  37. 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#

  38. 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