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

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

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

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

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

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

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

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

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

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