Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?

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

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?"
This discussion has been archived. No new comments can be posted.

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

Comments Filter:
  • by Anonymous Coward on Friday September 05, 2014 @12:29PM (#47835291)

    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.


  • Re:Infoworld... pass (Score:2, Informative)

    by sconeu ( 64226 ) on Friday September 05, 2014 @12:29PM (#47835293) Homepage Journal

    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.

  • by Anonymous Coward on Friday September 05, 2014 @12:36PM (#47835369)

    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

  • Re:Powershell (Score:2, Informative)

    by Anonymous Coward on Friday September 05, 2014 @12:40PM (#47835417)

    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.

  • by jfbilodeau ( 931293 ) on Friday September 05, 2014 @12:46PM (#47835483) Homepage

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

  • Re:Powershell (Score:5, Informative)

    by angel'o'sphere ( 80593 ) on Friday September 05, 2014 @01:16PM (#47835779) Journal

    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:

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

    The loop runs until a zero value is moved.

    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.

  • by Tridus ( 79566 ) on Friday September 05, 2014 @01:18PM (#47835811) Homepage

    http://stackoverflow.com/quest... [stackoverflow.com]

    That's a list of very strange language features. Unsurprisingly, Javascript makes many, many appearances.

  • Re:Powershell (Score:4, Informative)

    by MightyMartian ( 840721 ) on Friday September 05, 2014 @01:19PM (#47835825) Journal

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

  • Re:Powershell (Score:3, Informative)

    by LoneTech ( 117911 ) on Friday September 05, 2014 @01:37PM (#47836009) Homepage

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

  • by Just Some Guy ( 3352 ) <kirk+slashdot@strauser.com> on Friday September 05, 2014 @01:49PM (#47836141) Homepage Journal

    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

"So why don't you make like a tree, and get outta here." -- Biff in "Back to the Future"