26

No matter how much you love a programming language, there are always a few details in it that aren’t quite as nice as they could be.

In this question, I would like to specifically focus on syntax elements. In a programming language that you use frequently (perhaps your favourite programming language, or perhaps the one you are forced to use at work), which syntax element do you find most unreadable, unclear, inconvenient or unpleasant?

Tamara Wijsman
  • 8,259
  • 14
  • 58
  • 94
Timwi
  • 4,411
  • 29
  • 37
  • @Nathan Taylor, not for this question, but for [another question](http://programmers.stackexchange.com/questions/2846/which-language-do-you-really-hate/2878#2878). – finnw Sep 11 '10 at 23:49
  • Did this question get modified? Because when I answered, it wasnt focused on "syntax elements"... I will have to modify my answer now. – Talvi Watia Sep 20 '10 at 00:08
  • @Talvi: No, it was about syntax right from the start. – Timwi Sep 20 '10 at 11:35
  • @Timwi weird, it must be a case of 'answering a question thinking it was a different one' then. – Talvi Watia Sep 21 '10 at 11:27
  • If you can vote and think this is a useful question or it have useful answers below, please vote up. StackExchange sites need votes to build a good community. You can give 30 votes per day, don't waste them. Specially users with high reputation and low counting votes given please read this: http://meta.programmers.stackexchange.com/questions/393/asking-better-questions – Maniero Oct 05 '10 at 19:30
  • It's amusing that the first answer containing C++ is about `switch` when everyone generally has only horrid stories to recount about it :) – Matthieu M. Feb 27 '11 at 20:47

36 Answers36

39

Semicolon insertion in JavaScript.

I haven't really been bitten by it often, but it's just such a phenomenally bad idea it makes my head spin.


Here's the rules (from ECMA-262 Section 7.9)

  1. When the program contains a token that is not allowed by the formal grammar, then a semicolon is inserted if (a) there is a line break at that point, or (b) the unexpected token was a closing brace.
  2. When the end of a file is reached, if the program cannot be parsed otherwise, then a semicolon is inserted.
  3. When a "restricted production" is encountered and contains a line terminator in a place where the grammar contains the annotation "[no LineTerminator here]", then a semicolon is inserted.

Example:

return 1; // returns 1

return
1; // returns undefined
Tim Goodman
  • 2,644
  • 2
  • 28
  • 25
  • 2
    JavaScript:The World's Most Misunderstood Programming Language ~Douglas Crockford – pramodc84 Sep 09 '10 at 04:20
  • Yes, many expect JavaScript to be a "free-form language", but it isn't. – Andreas Rejbrand Sep 13 '10 at 15:23
  • 13
    It makes sense once you realize that JavaScript was designed for creating HTML, which also has a long history of trying to interpret what your code "really means" when it isn't syntactically valid. (Look up the Robustness Principle sometime--the biggest disaster in the history of computing.) – Mason Wheeler Sep 17 '10 at 18:18
  • I don't actually think this was a mistake. The robustness principle is a good idea for languages that target non-programmers, who are more used to the flexible syntax of real world languages. A decent programmer's editor will prevent you from getting bitten by semi-colon insertion. – Joeri Sebrechts Sep 18 '10 at 12:37
  • 7
    These types of errors, to me are a code-smell that the programmer is sloppy and has never worked with most formal "strict" languages that would normally cause a syntax error for leaving the semi-colon out. – Talvi Watia Sep 20 '10 at 00:06
  • 7
    Wohoo, finally someone else who also thinks Robustness Principle is a disaster that has made HTML the utter mess that it is. – Roman Starkov Nov 21 '10 at 10:10
  • I don't write the semicolons, at least given my coding style they make absolutely no difference. I agree that having both implicit semicolons, and implicit line continuation at the same time is a bad idea, but I would vouch for removing implicit line continuation. – aaaaaaaaaaaa Dec 10 '10 at 15:27
  • Semicolon insertion isn't a bad idea in itself. The bad idea was developing a syntax *almost* like C that would obviously mislead people into thinking semicolons should work like they do in C. – dan04 Jan 10 '11 at 05:28
39

Java-bean syntax due to lack of C# properties

/**
 * Name of user
 */
private String name;

/**
 * Gets name of user
 * @return Name of user
 */
public String getName() {
    return this.name;
}

/**
 * Sets name of user. 
 * @param name
 */
public void setName(final String name) {
    this.name = name;
}

GAH!!!

Issues I have with this

  • Too much code - Have a field that's documented, a getter method that's documented, and a setter method that's documented. This extremely basic example has 20 lines of code for a single property
  • Clutters method lists - "Let me find that method, hand on: getX, getY, getZ, getAnotherAnnoyingField, getWhyIHateJavaBeans, getThisIsVerbose, getGAH... ah there it is, hashCode.
  • Multiple area's of documentation lead to poor, outdated, or missing documentation - Annoying when trying to understand what code does
  • So annoying a 3rd party had to come up with a plugin to do this easily - Spoon, Shark, among others.
dusan
  • 105
  • 4
TheLQ
  • 13,478
  • 7
  • 55
  • 87
  • You can generate the beans easily with Eclipse. Just declare your attributes and go under "Source -> Generate Getters and Setters ...". Since eclipse is commonly used to program in Java, I don't see how "Too much code" and "So annoying a 3rd party had to come up with a plugin to do this easily" are a problem. – HoLyVieR Sep 04 '10 at 17:16
  • 9
    Once again when code is so verbose that it needs auto generating tools, something is wrong. I'm a NetBeans guy, but it also has the ability to auto generate getters and setters. But Javadoc falls out of syn, it's still verbose, it still clutters javadoc, etc – TheLQ Sep 04 '10 at 19:13
  • 11
    If you need getters for everything then something is wrong with the *client* code. – finnw Sep 10 '10 at 19:51
  • 7
    Having getters and setters breaks encapsulation. The field *might as well* be `public`. Members should be private and should be manipulated sensibly by the class with higher-level logic, *not* with getters and setters from client code. – greyfade Sep 18 '10 at 05:54
  • 6
    @greyfade: If it's public, you can't easily change what the setting code does (you'll have to change all code that sets the field from the outside). – Bart van Heukelom Sep 18 '10 at 10:41
  • @greyfade: In theory you might be right, but in practice you're going to need getters and setters, just use them sparsely. You could find a lot of them even in Fowler's books on patterns and refactoring. – Adam Byrtek Sep 18 '10 at 13:22
  • 1
    @Bart van Heukelom: If it's public, it's wrong. If client code is using a setter, it's wrong. Members *should* be `private` unless you've got a very good reason otherwise. – greyfade Sep 20 '10 at 15:36
  • Java has no metaprogramming, and that may be the reason Java looks "clean" – Ming-Tang Sep 21 '10 at 03:51
  • 1
    @greyfade I'm not saying you should automatically have getters and setters for all fields, but there are many valid use cases for other code directly setting the value of a field, in which case setters are obviously better than public fields. – Bart van Heukelom Sep 22 '10 at 09:18
  • @Bart van Heukelom: I would argue that if you have a setter or a public field *at all*, it's a sign that your class is doing *too much* or that it's holding on to information that it shouldn't have. Worse, if your client code is modifying the class' members at such a low level, it's abusing that class. Classes should do only and exactly one thing, and it should abstract all of its state from its interface. No client code should be aware of any portion of that class' state, except to explicitly break the encapsulation. – greyfade Sep 22 '10 at 17:00
  • 3
    @SHiNKiROU: Java looks clean? I've never heard that one before! My main gripe with Java is the fact that seemingly simple thing takes dozens of lines of code I need to mentally ignore. – configurator Sep 29 '10 at 06:31
  • @greyfade, you cannot specify public fields in interfaces - hence you must use getters and setters. –  Oct 28 '10 at 22:05
  • @configurator, have a look at Go. –  Oct 28 '10 at 22:05
  • @Thorbjørn: IMO, if you're using an interface that way, you're using it wrong. An interface should expose no knowledge of data, only an interface to logic. A concrete class should have data, but should not expose knowledge of it. – greyfade Oct 29 '10 at 18:01
  • @greyfade, at SOME point you need to provide a way to let one class access information in another class. If you dislike get/set, how would you do it then? –  Oct 29 '10 at 19:02
  • @Thorbjørn: *IF* I had one class that required access to a specific value held by another class, I would reconsider the design of my classes - I probably did something wrong; perhaps the other class should not be holding this value to begin with. If, on the other hand, it's specific functionality *relating* to a value that I require, then I'd consider adding this functionality to the other class *or* a new wrapper class. Very, very painfully rarely have I come across the situation where I needed to expose a value with a getter/setter. More usually, inheritance is the answer. – greyfade Oct 30 '10 at 16:36
  • @Thorbjørn: In general, when a class needs to hold data, the class' *job* is to protect that data from outside interference: Its interface exposes only functionality, not data; a setter implies that my class is missing needed functionality (like a function that mutates the stored value) and a getter implies that the class has too much responsibility (someone else should be holding this value). In all other cases, a simple class with no interface and public members is the only reasonable choice (that is, getters and setters are unjustified). – greyfade Oct 30 '10 at 16:42
32

Whitespace Sensitivity.

Python annoys me in this respect. I mean, I indent properly anyway, but it bugs me that I should have to. Making presentation part of the syntax irks me.

Fishtoaster
  • 25,909
  • 15
  • 111
  • 154
32

The switch statement (in C, C++, C#, Java, etc.)

Here is an example of why I find it highly inconvenient:

switch (someVariable)
{
    case 1:
        int i = something();
        doSomething(i);
        break;

    case 2:
        int i = somethingElse();
        doSomethingElse(i);
        break;
}

This doesn’t compile because the variable i is redeclared in the same scope. This seems like a minor detail, but it bites me really often. I can add curly brackets to mitigate it, but it would have been nice if the curly brackets had been mandatory part of the syntax, and there was no redundant extra level of indentation. I also really hate having to write the extra break. This would be much nicer:

switch (someVariable)
case 1
{
    int i = something();
    doSomething(i);
}
case 2
{
    int i = somethingElse();
    doSomethingElse(i);
}
default
{
    ...
}

This makes it look more like an if/else chain, which is a good thing because it is semantically similar too. At least in C# it would still not be the same thing however, because in a switch statement the order of the case labels doesn’t matter, but in an if/else it does.

Timwi
  • 4,411
  • 29
  • 37
  • 1
    Unfortunately, your improved syntax does away with what is, arguably, switch's biggest feature in most of these languages: Fall-through. "Duff's Device" in C is a perfect example of the value of this particular "mis-feature." It is also common in C-like languages to use fall-through in interpreters and similar programs. – greyfade Sep 04 '10 at 20:50
  • 7
    No, it doesn’t do away with it. It only requires that it be made more explicit (using a `goto` or similar), as is already the case in C#. – Timwi Sep 04 '10 at 21:06
  • 8
    @greyfade: Any code using duff's device in C needs to die a horrible death. Compilers make better decisions about these kinds of things than you do. – Billy ONeal Sep 18 '10 at 03:34
  • 1
    Yes, `goto` is waaay better than fall-through. Though both pale in comparison to the shear awesomeness of `longjmp()`... – Shog9 Sep 18 '10 at 03:54
  • 1
    @Billy ONeal: Yet I still find cases where complex logic is simplified by using fall-through. Cases where multiple values need to map to the same behavior. Cases where two values require the same behavior, but one with a preamble. Maybe the problem is that C and C++ only support switching on types convertible to `int`, but that doesn't change the fact that it's *useful*. Calling this a *bad* feature is short-sighted. – greyfade Sep 18 '10 at 05:42
  • 1
    @Mr. C: Be careful not to criticise someone for something they didn’t say. It is useful to be able to jump to another case label in a way that is *equivalent to fall-through*. It doesn’t mean that the language should allow you to use `goto` to jump anywhere you want. – Timwi Sep 18 '10 at 12:14
  • @Tirawi: I *think* what you're arguing for is explicit fall-through vs. implicit fall-through. However, that's not a fair description of `goto` in C#'s switch: you can jump backwards, skip over cases, etc... In short, it's a slightly-constrained form of the `goto` familiar to users of many other languages - so if you *wanted* to do the same in C, you *could*... Of course, if you want to be explicit, there are plenty of other ways to do so: code in function calls instead of case clauses, jump tables, polymorphism... So my first thought is that perhaps you shouldn't be using switch *at all*... – Shog9 Sep 18 '10 at 16:41
  • I so much agree with this answer, for C#. There is no fall-through in C#, so having all the case section be a single scope makes completely no sense, and often causes problems. I always place {} blocks inside my cases precisely for this reason, and would love it if that were enforced. (And then of course all the colons and other useless syntax removed.) For C, the existing form is fine. It fits the C style. – Joren Sep 20 '10 at 15:06
  • 1
    Because of the halting problem, C# compiler assumes that block is reachable. `switch { case }` is a bad construct overall. You must repeat `break;` many times. Except the Ruby version is better. I also hated about how switch cases are indented: switch {-->case: } or switch {-->case:-->-->break } – Ming-Tang Sep 21 '10 at 03:50
  • 4
    @greyfade: Delphi gets around the multiple value issue by simply allowing multiple indices in the case: `case Foo of 1,3: Result := 'odd'; 2,4: Result := 'even' end;`. – Frank Shearar Sep 24 '10 at 16:18
  • Switches are screwy, but insanely useful. Like others here, I use fall-through rather regularly (but always comment it), but I agree that the lack of a default case-level block is annoying. And that switches tend to give you rediculously deep indentation. – jkerian Sep 27 '10 at 00:08
  • 3
    @jkerian: Now imagine `break` was the default and only fallthrough needed to be specified. No more need to remember to comment it! :) – Timwi Sep 27 '10 at 18:54
  • 1
    @Mr. C: I don't really see what the problem is with a forward-jumping `goto` in a C# `select` statement. I mean, a `break` is already a form of jump statement anyway, much like goto. I do agree that backwards-jumping gotos should generally be avoided, but that's the programmers fault for writing messy code. I do think that C#'s way of dealing with switch statements is better than C++'s, because at least in C# you avoid accidental fallthrough. – Tim Goodman Oct 16 '10 at 16:57
  • You are missing the point of compound statements. Any branching construct in C can be followed by a single statement - this can be just a single semicolon, a simple statement terminated by a semicolon, or a copound statement enclosed in curly braces. If switch case construct mandated the curly braces, then it will become inconsistent with if-else, for, while etc. – aufather Oct 16 '10 at 17:31
  • @aufather: Obviously the curlies wouldn’t have to be mandatory for single statements. – Timwi Oct 17 '10 at 13:56
  • @TimGoodman: I'm not complaining about goto. It's useful, sometimes... And as you note, it's the responsibility of the programmer to avoid it when a cleaner solution exists. But goto in C# switch statements is largely orthogonal to fall-through: you can use goto in C to do the same thing, if you desire. I suggest that the bigger mistake is cramming so much code into `case`es that fall-through isn't immediately obvious, regardless of whether implicit or explicit. – Shog9 Oct 17 '10 at 19:23
27

Array Declarations in VB.NET

I always manage to forget that when initializing fixed arrays in VB.NET, you're specifying the upper bound of the array and not the number of elements like in C/C++, PHP, or Java. Besides VB6 (we won't go there...), I can't think of another language that does it this way:

Dim myArray(20) as Integer  '# Creates an array with 21 elements,
                            '# indexed from 0 to 20
24

VB6 - Separate Variable Declaration and Assignment

Most languages let you declare a variable and assign it in one line of code; VB6, on the other hand, forces you to use two.

Dim i as Integer
i = 0

Dim derpderp as Collection
Set derpderp = new Collection

You can use a colon to put two commands on one line, but it quickly turns messy in actual code.

Dim i as Integer: i = 0
Dim derpderp as Collection: Set derpderp = new Collection
derekerdmann
  • 528
  • 9
  • 14
  • 7
    +1 for having to use VB6 as your most frequent language. – Walter Sep 02 '10 at 23:10
  • 9
    I use it daily..sob. – systempuntoout Sep 03 '10 at 18:19
  • Doesn't Pascal have a similar syntax? I always thought it was nasty. – greyfade Sep 04 '10 at 20:59
  • 1
    There's a special case: if you `Dim Hurp As New Collection`, if you access `Hurp` when it refers to `Nothing`, it will be magically initialized before the access. If you explicitly set it to `Nothing` and touch it again, it gets resurrected... gasp! – Jeffrey Hantin Sep 18 '10 at 04:04
  • @Jeffery Hantin - That's actually completely different. You then have VB6 checking to see if your object actually exists every time it's called (it's declared as a `New Collection`), which could lead to significant overhead on large applications. I'd much rather manage everything myself. – derekerdmann Sep 28 '10 at 04:09
  • It's been years since I used VB6, but I thought you could do something like `Dim x = 0, y = 1, z = 2 as Integer`, no? – Carson Myers Dec 07 '10 at 03:44
  • @Carson Myers: No. – Foole Feb 27 '11 at 11:00
  • 1
    +1million for Derp. Derp de derp de tiddly tum de derp. – MVCylon May 26 '11 at 19:21
24

Commenting in CSS

// doesn't comment out lines of code like it does in many other languages, like PHP and Javascript. Although /* this is commented out */ works, I prefer to use //.

Its a nuisance, because half the time I forget I am editing CSS and then have to go back and fix the error.

Talvi Watia
  • 768
  • 5
  • 19
  • You would of thought in this day and age that raw CSS would be considered object code. – Tom Hawtin - tackline Dec 07 '10 at 14:35
  • // works just fine to comment out CSS. I do it all the time. All I'm really doing is typing garbage. but it seems to work by skipping the unparseable line. – MVCylon May 26 '11 at 19:22
  • 1
    @MVCylon If you use // to comment out a line, anything after that following line also is skipped. {within that specific style} In other words, it FAILS because those lines should not be skipped. – Talvi Watia Oct 02 '12 at 01:26
20

PHP - consistent ordering of arguments

PHP has a number of handy functions for doing pretty much every operation you could think of on an array or string. Many of these operations require using both a $needle and a $haystack, but different functions take them in different orders. Which function requires which arguments is one of those facts my brain refuses to absorb, no matter how often I come across them!

Take the functions in_array and strstr:

// Check whether $needle occurs in array $haystack
bool in_array (mixed $needle, array $haystack [, bool $strict])

// Check whether $needle is a substring of $haystack
string strstr (string $haystack, mixed $needle [, bool $before_needle=false])

Funnily enough, PHP seems to be internally consistent with these orderings in that all string functions seem to use $haystack, $needle while array functions are the other way around, but this can take a bit of getting used to for someone new to PHP. There's a good post on ExpressionEngine talking about this particular quirk in more detail, as well as a discussion on the PHP bugs list, which features a very short response from the PHP team!

helly@php.net
Use a decent IDE then.
ConroyP
  • 795
  • 8
  • 10
  • 2
    It's easier to remember the order `$needle`, `$haystack` as it reminds the way of saying _find a needle in a haystack_. – apaderno Sep 03 '10 at 01:40
  • 3
    Protip: in array functions, needle comes first. in string functions, haystack comes first. – GSto Sep 09 '10 at 02:05
  • 17
    I love the name `strstr`. So beautifully meaningless. – configurator Sep 29 '10 at 06:32
  • 5
    Just read the linked entry in PHP's bugtracker. Seriously, wtf? oO Imho consistency is a valid issue for any API and just responding with "use a decent IDE then" is just not a valid reply. At least it could have been worded less inflammatory by the devs. – Baelnorn Oct 01 '10 at 16:08
  • @configurator: PHP got that name from C. – dan04 Feb 08 '11 at 03:51
  • 1
    @dan04: You say that like it makes it a better name. – configurator Feb 13 '11 at 16:30
  • This is actually not a syntax element. Since they are just functions... I've found such inconsistencies in almost every language, they are almost impossible to avoid I think. – Inca Feb 27 '11 at 10:53
  • @Inca: I disagree - PHP is especially bad about this. Most of the POSIX C functions that PHP imports (`str*`) are self-consistent. But then PHP mixes and matches with all other functions, often nonsensically. – greyfade May 26 '11 at 19:56
  • 2
    Honestly, what drives me crazy about this is that it shouldn't be a function at all! It should just be a method: $haystack->find($needle). Done deal. – riwalk May 26 '11 at 20:30
19

Python

self parameter in instance method definitions

  • In a classmethod, it's usually named cls and using self goes against convention. –  Sep 09 '10 at 03:25
  • It actually make sense if you think about it. It's the same as declaring a private method in other languages, the self parameter is just explicit in python where it's implicit in other languages. If you want it to be implicit add the @classmethod decorator before the method declaration. See http://docs.python.org/library/functions.html#classmethod. Learning the details of how this works will give you some insight as to how it's done in other languages implicitly. – Evan Plaice Sep 11 '10 at 13:48
  • 4
    I understand the reasons and why it is left there http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html but I still don't like it – Goran Peroš Sep 11 '10 at 21:23
  • @Evan Plaice: 'self parameter is just explicit in python where it's implicit in other languages' That's only one part of the story. The other part is python being weekly typed. Together it's terrible, forgetting `self` happens to easily and costs time. – maaartinus Apr 26 '11 at 22:04
  • @maaartinus Then add a classmethod decorator to your instance methods. Has nothing do with 'weakly typed'. It just makes the relationship between static methods/functions (no 'self' parameter) and instance methods (includes 'self') obvious. An instance method isn't aware of it's parent class unless you give it a reference to do so. In other languages the distinguishing characteristic I outlined is just hidden behind syntactic sugar. If I had a choice to do it all over I would have started learning OOP in Python first. – Evan Plaice Jan 17 '12 at 07:27
  • @Evan Plaice: I never said the two things are logically related. Just that together they lead to errors not happening in other languages. – maaartinus Jan 22 '12 at 18:23
18

Java

Period. Full stop. End of story.

Where to start? Oh, I know where to start: Java’s insanely complicated and ugly and stupid and inherently broken generics. Need I say more? :( Ok fine, then: type erasure.

Then there’s non-deterministic resource management. Kewl feetcher!

What’s next up? Oh yeah: Java’s stupid regexes are my most irritating, seething beef. I cannot count how many times I’ve been hosed by not having enough backslashes. This is even worse than not having access to any Unicode properties from this millennium — which is complete bull. Ten fricking years out of date!!! Completely useless. Trash it.

Then there’s the bug that the character class shortcuts don’t work on non-ASCII. What a royal pain! And don’t even consider using \p{javaWhiteSpace}; it doesn’t do the right thing with several very common Unicode whitespace code points.

Did you know there’s a \p{javaJavaIdentifierStart} property? Whatwhatatat wereere they thinkinking? So glad they got such smart peepers wurkin on dis tough.

Ever tried to use the CANON_EQ flag? Do you know that really does, and what it doesn’t do? How about so-called “Unicode case”? A bunch of normal casing things just don’t work at all.

Then they make it hard to write maintainable regexes. Java still hasn’t figured out how to write multiline strings, so you end up writing insane things like this:

    "(?= ^ [A-Z] [A-Za-z0-9\\-] + $)      \n"
  + "(?! ^ .*                             \n"
  + "    (?: ^     \\d+      $            \n"
  + "      | ^ [A-Z] - [A-Z] $            \n"
  + "      | Invitrogen                   \n"
  + "      | Clontech                     \n"
  + "      | L-L-X-X                      \n"
  + "      | Sarstedt                     \n"
  + "      | Roche                        \n"
  + "      | Beckman                      \n"
  + "      | Bayer                        \n"
  + "    )      # end alternatives        \n"
  + ")          # end negated lookahead   \n" 

What are all those newlines? Oh, just Java stupidity. They used Perl comments, not Java comments (idiots!) which go till end of line. So if you don’t put those \n’s there, you chop off the rest of your pattern. Duh and double duh!

Don’t use regexes in Java: you’ll just end up wanting to smash things, it’s all so painful and broken. I can’t believe people put up with this. Some don’t.

Then we can start talking about Java’s idiot nonsense with encodings. First, there’s the fact that the default platform encoding is always some lame 8-bit encoding even though Java’s charchars are Unicode. Then there’s how they don’t raise an exception on an encoding error. You’re guaranteed to get crap. Or how about this:

OutputStreamWriter(OutputStream out) 
          Creates an OutputStreamWriter that uses the default character encoding.
OutputStreamWriter(OutputStream out, Charset cs) 
          Creates an OutputStreamWriter that uses the given charset.
OutputStreamWriter(OutputStream out, CharsetEncoder enc) 
          Creates an OutputStreamWriter that uses the given charset encoder.
OutputStreamWriter(OutputStream out, String charsetName) 
          Creates an OutputStreamWriter that uses the named charset.

What’s the difference? Did you know that only one of those will raise an exception if you have an encoding error? The rest just muzzle them.

Then there’s the idiocy of Java chars not being sufficient to hold a character! What the hell are they thinking? That’s why I call them charchars. You have to write code like this if you expect it work right:

private static void say_physical(String s) { 
    System.out.print("U+");
    for (int i = 0; i < s.length(); i++) {
        System.out.printf("%X", s.codePointAt(i));
        if (s.codePointAt(i) > Character.MAX_VALUE) { i++; }  // UG!
        if (i+1 < s.length()) { System.out.printf("."); }
    }
}

And who ever thinks to do that? Next to nobody.

How many characters are there in "\uD83D\uDCA9"? One or two? Depends on how you count them. The regex engine of course deals with logical characters, so a pattern ^.$ will succeed and a pattern ^..$ will fail. This insanity is demonstrated here:

String { U+61, "\u0061", "a" }  =~ /^.$/ => matched.
String { U+61, "\u0061", "a" }  =~ /^..$/ => failed.
String { U+61.61, "\u0061\u0061", "aa" }  =~ /^.$/ => failed.
String { U+61.61, "\u0061\u0061", "aa" }  =~ /^..$/ => matched.
String { U+DF, "\u00DF", "ß" }  =~ /^.$/ => matched.
String { U+DF, "\u00DF", "ß" }  =~ /^..$/ => failed.
String { U+DF.DF, "\u00DF\u00DF", "ßß" }  =~ /^.$/ => failed.
String { U+DF.DF, "\u00DF\u00DF", "ßß" }  =~ /^..$/ => matched.
String { U+3C3, "\u03C3", "σ" }  =~ /^.$/ => matched.
String { U+3C3, "\u03C3", "σ" }  =~ /^..$/ => failed.
String { U+3C3.3C3, "\u03C3\u03C3", "σσ" }  =~ /^.$/ => failed.
String { U+3C3.3C3, "\u03C3\u03C3", "σσ" }  =~ /^..$/ => matched.
String { U+1F4A9, "\uD83D\uDCA9", "" }  =~ /^.$/ => matched.
String { U+1F4A9, "\uD83D\uDCA9", "" }  =~ /^..$/ => failed.
String { U+1F4A9.1F4A9, "\uD83D\uDCA9\uD83D\uDCA9", "" }  =~ /^.$/ => failed.
String { U+1F4A9.1F4A9, "\uD83D\uDCA9\uD83D\uDCA9", "" }  =~ /^..$/ => matched.

That idiocy is all because you can’t write the perfectly reasonable \u1F4A9, nor of course do you get any warning that you can’t do that. It just does the wrong thing.

Stoooopid.

While we’re at it, the whole \uXXXX notation is congenitally brain dead. The Java preprocessor (yes, you heard me) gets at it before Java does, so you are forbidden from writing perfectly reasonable things like "\u0022", because by the time Java sees that, its preprocessor has turned it into """, so you lose. Oh wait, not if it’s in a regex! So you can use "\\u0022" just fine.

Riiiiiiiight!

Did you know there’s no way in Java to do an isatty(0) call? You aren’t even allowed to think such thoughts. It wouldn’t be good for you.

And then there’s the whole classpath abomination.

Or the fact that there’s no way to specify the encoding of your Java source file in that same source file so you don’t lose it? Once again I demand to know: WHAT THE HELL WERE THEY THINKING‽‽‽

Stop the madness! I can’t believe people put up with this garbage. It’s a complete joke. I’d rather be a Walmart greeter than suffer the slings and arrows of outrageous Java insanity. It’s all broken, and they not only can’t fix it, they won’t fix it.

This by the same foxy-grapey people who prided themselves on a language that made it illegal to have a printf() function. Gee, that sure worked out real well, didn’t it though!?

Sheer numbskulls. Bitch-slapping is too kind for them. If I wanted to program in assembler, I would. This is not a salvageable language. The emperor has no clothes.

We hates it. We hates it forever. Let it die die die!

tchrist
  • 341
  • 6
  • 11
  • Haha, good one, I don't touch java because it's too unpolished like you describe. As for \uD83D... well I suppose a better way of saying this is that you'd rather strings were not UTF-16 but UTF-32 instead. If you accept UTF-16-ness then the regex do the right thing; it's the .length call that fucks up. – Roman Starkov Nov 21 '10 at 10:07
  • 4
    -1. With the exception of regexp comments and Unicode escapes, not a single one of the things you mentioned is a syntax element. – Jörg W Mittag Nov 21 '10 at 11:25
  • 3
    @Jörg, you want syntax? Ok fine: Java allows you to put control characters, include ESC and NUL, in identifiers. WTH were they thinking??? – tchrist Nov 22 '10 at 22:12
  • 4
    @tchrist: Wow! If I ever write a Java program again, all my variables will have names consisting of varying numbers of backspace characters (`^H`) :) – j_random_hacker Nov 29 '10 at 12:44
  • So not handling Unicode characters above 0x10000 to your liking is in your top five list of Java problems? I think you're giving Java too much credit, there are bigger issues than that. – Jaap May 26 '11 at 22:37
  • @Jaap, no, you’re right — those were just what was bothering me at that point in time. Insanity with generics is a much bigger problem, and there are of course lots and lots and lots of others. It’s also wicked that you need an `int` for arbitrary characters, not a `char`. – tchrist May 27 '11 at 00:13
  • 1
    @tchrist, feeling better now? –  Jun 23 '11 at 09:25
  • +1 I would have also mentioned random/urandom bug on unix platforms to make whole picture more complete – altern Jun 12 '12 at 16:07
16

Function pointer declaration syntax in C and C++:

(int)(*f)(int, int);

That declares a function pointer named f whose pointee can take two ints and return an int.

I'd much prefer a syntax like this:

f: (int, int) => int

Say you want to declare a function pointer g whose pointee can take two ints and a function from int and int to int, and return an int.

With C or C++ notation, you'd declare it as:

(int)(*g)(int, int, int(int, int));

With the above-proposed notation same thing can be declared as:

g: (int, int, (int, int) => int) => int

Latter is much more intuitive IMO.


Aside: The programming language called OOC fixes this syntax (and various other syntactical issues in C and C++). Check out its homepage here.

missingfaktor
  • 3,906
  • 1
  • 24
  • 31
  • Agree, some "plain C" / "C++" doesn't support it, or support it with different syntax. A special syntax, helps indicate when a programming language feature is supported. That's why C# added "delegate" syntax. – umlcat Mar 15 '11 at 18:32
  • Delegates are not only syntactic sugar because they also store the object (contrary to C++ member function pointers, that have even worse syntax than regular function pointers) – Tamás Szelei May 26 '11 at 20:13
14

Verbosity in Java.

ie:

public static final int 
OscarRyz
  • 1,675
  • 3
  • 15
  • 26
12

\we\wouldnt\fix\our\parser namespace syntax in PHP

The syntax is not only ugly, it leads to confusion when newer developers have to think about namespaces in strings. (PHP interpolates backslashes in double-quoted strings as escape sequences. Trying to represent a namespace like \you\should\never\do\that in a double-quoted string instead of a single-quoted string will lead to newlines, tabs and disaster.)

Charles
  • 1,411
  • 12
  • 13
  • Yeah, someone thought of a better::way to do this, but PHP insist that every operator must be different. I am curious as to what the misuse issue is here though. – Alan Pearce Sep 24 '10 at 17:20
  • Agree. PHP require namespaces, but that syntax screw it up – umlcat Mar 15 '11 at 18:35
9

I despise the fact that curly braces can be optional after an if/while/for statement.

Especially when I see code like,

if (...)
    for(...)
        ... One line of stuff ...

Please just put the braces in and be done with it.

Jim A
  • 119
  • 4
  • 6
    Hmm.. this depends. For "Abort Ifs" which merely check a condition and return an error code (or throw an exception), I'd much rather not see the braces. – Billy ONeal Sep 18 '10 at 03:48
  • Or `if (condition) while (...) { /* multiple lines here */ }` – Bart van Heukelom Sep 18 '10 at 10:47
  • 4
    I would agree if you limited yourself to extreme multi-level cases, but your statement is too blanket. There is great utility in the ability to have short forms for simple, single-statement ifs and loops. – Timwi Sep 18 '10 at 12:12
  • 2
    My rule: only if a statement requires multiple substatements *or if it contains such a statement* should it be wrapped in braces. Thus `for (...) while (...) if (...) { x(); y(); }` is better rewritten as `for (...) { while (...) { if (...) { x(); y(); } } }`, with appropriate indentation, of course. – Jon Purdy Sep 20 '10 at 12:10
  • 6
    I'm rather the opposite -- I despise people who insist on putting in braces when they're completely unnecessary. Just learn to program. – Jerry Coffin Oct 16 '10 at 18:42
  • If you're nesting constructs like that, there's a case for refactoring to a method anyway. – Steven Evers Oct 17 '10 at 06:12
  • 3
    I really like the brackets even in single if statements. It makes me follow the flow of a program better. – Ricardo Santos Dec 29 '10 at 16:32
  • +1. Missing brackets lead sometimes to terrible mistakes. Like when once, refactoring the code `if (IsDirectoryEmpty(directory)) Delete(directory);`, my colleague thought that it would be wise to log the directory removal first, like this: `if (IsDirectoryEmpty(directory)) Log("Message here..."); Delete(directory);` It was fun when it removed a non-empty directory with some useful files, requiring to spend an hour restoring incremental backups. – Arseni Mourzenko Feb 27 '11 at 12:21
  • If you want one-liner `if`s, it's fine to leave the braces out, but only in that case, and you can have only **one** function in these. `if ($_POST['myform']) echo 'Form data: '; echo $_POST['myform']; else echo 'Form is empty!';` will echo `'Form data: '` if the form isn't empty, echoes the form data anyway, and `else` causes a syntax error. – alexia Mar 02 '11 at 10:01
  • @MainMa: If the original statement was in a single line, then it's his fault. Point. If it wasn't... well... use a proper editor which indents it properly. I never ever use braces in one-liner and it never happens to me. – maaartinus Apr 26 '11 at 22:10
  • @Jerry Coffin, AMEN! Finally someone who agrees. – riwalk May 26 '11 at 20:32
  • -1 This is a great feature. Removes 1-2 unnecessary lines of code without relying on whitespace. – alternative May 26 '11 at 20:35
9

VBScript Doesn't Have Logical Operators

Unlike nearly every sensible language, VBScript uses bitwise operators instead of logical operators. What does this mean in practice? Well, as Eric Lippert points out:

If Blah = True Then Print "True!" Else Print "False!"

and

If Blah Then Print "True!" Else Print "False!"

are NOT the same in VBScript!

Even worse, though, this means that there is no short-circuit evaluation in VBScript so that the following statement will crash your program if Blah is Nothing

If (Not Blah Is Nothing) And (Blah.Frob = 123) Then
...

That's right, VBScript will evaluate both parts of the AND comparison, even if the first one is false! Just let that sink in...

Dan Diplo
  • 3,900
  • 1
  • 27
  • 30
  • 3
    Until the day you've hunted a bug inside an `If x Then ... If Not x Then ... End If ... End If` and figured out that x is 2, you haven't really programmed in VB/VBScript. – configurator Sep 29 '10 at 06:54
7

EDIT: Following the discussion in the comments I decided to update this answer to explain myself better.

I really hate the way function pointers look in C. Usually any variable declaration looks like a tuple of: type varname; Function pointer declarations on the other hand look like a declaration of the function with * before the function name. I can accept this as a description of a pointer type, but in C this declares both the type and the name of a variable of that type. This looks inconsistent to me because type declarations are otherwise distinct from variable declarations. struct myStruct{int X; int Y;} only defines a type, it does not define a variable named myStruct. Likewise I see no reason for type declarations and variable declarations to be grouped into one atomic statement in function pointers, nor do I appreciate the deviation from the type varname; structure.

Someone pointed out that it's consistent with some spiral rule, and that may be the case, but the mark of a good syntax is that it is self explanatory and its internal logic is obvious. The spiral rule is not obvious by any means.

dusan
  • 105
  • 4
EpsilonVector
  • 10,763
  • 10
  • 56
  • 103
  • 1
    It's consistent with the rest of the language, so maybe your gripe is about the syntax of C declarators in general? Do you prefer the syntax used in [Go](http://golang.org/doc/go_lang_faq.html#declarations_backwards)? – finnw Sep 03 '10 at 05:10
  • Consistent in what way? Usually it goes: type varname; And when we create a new composite type, like a struct, first comes the declaration, maybe with a typedef, and then we create a variable of that type. When we declare a function pointer, it's int (*foo)(int arg1, int arg2), which is then used as the type of an argument passed to a function: void newFoo(int (*foo)(int arg1, int art2)).... and as a variable: foo=a_compatible_func; I think that a function declaration first, and then a var declaration next would be more consistent, like so: typedef int (*foo)(int, int) MyFoo; MyFoo myfoo; – EpsilonVector Sep 03 '10 at 15:31
  • That's why you got `typedef`. – zneak Sep 03 '10 at 15:56
  • Yes, I'm just saying that it shouldn't be defining a variable name at the same time. struct myStruct{XYZ} doesn't define a variable called myStruct, only a type is defined. But int (*foo)(int, int) actually defines a variable along with the type. – EpsilonVector Sep 03 '10 at 16:20
  • 4
    @EpsilonVector: I tend to agree that function pointer syntax is nasty, but there is a simple rule to follow that makes it easier to read. The clockwise spiral rule (perhaps you've seen it?): http://c-faq.com/decl/spiral.anderson.html – greyfade Sep 04 '10 at 20:57
  • I've always seen it called "inside-out", but clockwise spiral works too. Function pointer syntax is consistent with arrays, which people rarely seem to have a problem with. –  Sep 09 '10 at 03:28
  • 1
    EpsilonVector: I'm not sure what you'd expect from a *pointer variable* declaration to declare other than the name of the variable. –  Sep 09 '10 at 03:29
  • @EpsilonVector: I realise it's an ugly syntax, but I don't think it's any more inconsistent than array declaration syntax: `int x[42];`. The `[42]` part comes after the variable name, just like the parameter type list does when declaring a function pointer. – j_random_hacker Nov 29 '10 at 12:33
  • @j_randon_hacker Hmm... I guess that's why Java made it int[] varname then. To be honest I never noticed that inconsistency, I always read it as "int x times 42"... but you have a point. – EpsilonVector Nov 29 '10 at 18:33
6

Array declarations in C and C++.

Typically, a variable declaration is of the format type variable_name. You can easily read those declarations in a left-to-right manner. But int foo[size] looks at first like it's declaring foo as an int, and then you read further and see that foo's of type "array of integers." int[size] foo reads much better.

And I also hate it when programmers declare pointers like this for a similar reason: int *foo. For some reason I haven't figured out, that's the typical way it's written.

Timwi
  • 4,411
  • 29
  • 37
Jacob
  • 382
  • 3
  • 14
6

In/out arguments. I'm all for in arguments (good thing I am), out arguments are fine too, but an argument that must convey these two states pisses me off.

What I target here are functions that take input from a parameter then overwrite that input with some output. It's okay to pass an object by reference to update it. But, mostly for primitive types, taking an object, use it, then change it completely, is not right by me. You shouldn't change the meaning of the argument through an inout.

zneak
  • 2,556
  • 2
  • 23
  • 24
  • What language do you have in mind? If C# then I would disagree that it's annoying because it's always explicit (unlike in C++.) Also I don't know of any mainstream language where your are forced to declare arguments as in/out. – finnw Sep 03 '10 at 05:07
  • @finnw I've never seen a language where you *had* to say `in` for `in` arguments either, I'm just talking about them. Also, in my opinion, _nothing_ can excuse an in/out argument, and making them explicit does not relieve the pain. There should be no reason to have to initialize a local variable with a value helpful to the function, and have this same variable then suddenly contain whatever the function decided to put there. These two should be distinct. Always. – zneak Sep 03 '10 at 15:52
  • Sorry I was not very clear there. I meant to say "I don't know of any language where all arguments are implicitly in +out" i.e. you are not forced to use that feature, but there are legitimate use cases (e.g. updating a `struct` where the new value depends on the value of another field of the same `struct`.) – finnw Sep 03 '10 at 19:52
  • @finnw Objects passed by reference (like instances of `class` objects in C#) being modified by a function are fine to me. Aside that I dislike non-constant structs, passing a `struct` with the `ref` keyword to update it is okay, too. What I really hate is when input is __overwritten__ with output. The best example I can think of is Berkeley socket's `accept` function: it needs a `socklen_t*` argument that, on input, must contain the size of the `struct sockaddr*` you've passed; and on output, will contain the number of bytes that have been written to it. This should be criminal. – zneak Sep 03 '10 at 20:12
  • I agree that is bad (IIRC some Win32 I/O functions do the same) but that is misuse of the feature (the function call changes the meaning of the passed-in variable, not just its value) and it does not mean the feature itself is bad. – finnw Sep 03 '10 at 20:20
  • This answer seems off-topic because it is not about **syntax**. – Timwi Sep 04 '10 at 18:36
  • @zneak: Just FWIW, in Ada you explicitly declare arguments as `in`, `out`, or `inout`. – Jerry Coffin Oct 16 '10 at 18:49
6

Semicolons in VBScript - or the lack thereof

I spend all day working in languages that expect semicolons at the end of each line. Add one to the end of the line in VBScript and your code doesn't run anymore.

Nathan Taylor
  • 1,598
  • 17
  • 20
  • 4
    up-voting this, not because I particularly like semicolons, but because I really *hate* the way VB encourages *really long lines* by making linebreaks so inconvenient. – Shog9 Sep 18 '10 at 03:57
5

Since people have already complained about = vs. ==, let me point out a much worse alternative. PL/I had both := and =, but when something was "obviously" an assignment, it would let you get away with using = to do it. Using := let you force something to be an assignment in a situation where the compiler would otherwise interpret it as a comparison.

Unfortunately, the compiler didn't always decided on things quite the way you might expect. Consider just one obvious example:

A = B = 0;

Now, to most people familiar with most "ordinary" languages, the meaning of this is pretty obvious -- assign 0 to both A and B. PL/I is just a bit...different though. For reasons known only to the (insane) designers of the language, the first = is interpreted as an assignment, but the second = is interpreted as a comparison. Therefore, this compares B to 0, and then assigns the result of that comparison to A (following the C-style convention that "false" results in 0 and "true" in 1).

So, if B was 0, then A becomes 1. Otherwise, A becomes 0. In other words, rather than assigning the same value to A and B, this actually ensures that A cannot have the same value as B.

Bottom line: even though the C/C++/PHP style initially seems like a pain, the alternative is much worse1.

1Well, technically, there's another alternative: Pascal style, where = always means comparison and assignment always requires :=. After using that for a while, it's pretty obvious (at least to me) that assignment is enough more common than comparison that if you're going to require extra "stuff" to disambiguate the two, you should definitely keep assignments clean and simple and require the extra "grunge" on comparisons, not vice versa.

Jerry Coffin
  • 44,385
  • 5
  • 89
  • 162
  • 1
    I'd even propose to use `==` for equality and `:=` for assignment. This way you have more to type, but avoiding the lonely `=` helps to avoid bugs. – maaartinus Apr 26 '11 at 22:20
  • @maartinus: at least to me, that sounds like the absolute worst possibility, but such is life... – Jerry Coffin Apr 26 '11 at 22:22
5

Redundant parameterization in Java:

HashMap<String,HashMap<String,String>> foo = new HashMap<String, HashMap<String, String>>();

What other type parameterization does the compiler think foo could have?

Hoa Long Tam
  • 1,635
  • 10
  • 12
3

The for ... in construct in JavaScript and the foreach construct in PHP when looping over arrays. Both of them make it easier to write bugs than correct code.

Joeri Sebrechts
  • 12,922
  • 3
  • 29
  • 39
  • If I have to write extra code to use them safely, they're easier to use wrong in my book. For ... in requires extra checks to make sure you're not iterating over objects from the prototype, and foreach requires you to clean up references afterwards or risk overwriting the last value in the array. – Joeri Sebrechts Oct 16 '10 at 07:47
  • the foreach with changing references (& operator) is a famous bug... – umlcat Mar 15 '11 at 20:41
  • 1
    I'm confused, I thought it was common knowledge that the "for..in" construct in javascript is broken... why is this offensive? – lvilnis Jan 15 '12 at 08:40
3

Perl

  1. I wish Perl let me write if($x < 10) do_something();. At the moment, you have to write that as either do_something() if($x < 10); or as if($x < 10) { do_something(); }.
Gaurav
  • 567
  • 5
  • 14
  • 9
    `do_something() if ($x < 10);` isn't that bad. – zneak Sep 03 '10 at 20:23
  • It isn't, and in many cases is much cleaner than `if(..) ...` to boot, as you can get all the expressions to line up on the right. But there's times I really want to say `if($x < 10) do_something();`, and it's unfortunate that Perl won't let me. – Gaurav Sep 04 '10 at 05:54
  • 7
    It's unfortunate until you write `if ($x<10) do_something(); and_call_me();` and then wonder why you never get a call. I wish C and family would require the braces, to prevent that type of error. – AShelly Sep 04 '10 at 17:13
  • @AShelly: Ah, I never thought of it that way! Thanks. – Gaurav Sep 05 '10 at 04:44
  • 2
    @AShelly: or why you always get a call, actually. – zneak Sep 10 '10 at 01:04
  • @zneak, you caught me. But the correct version doesn't flow so nicely. Call it poetic license. – AShelly Sep 10 '10 at 14:43
  • 1
    @zneak Except no `else`s. (I wish it has `EXPR1 if COND else EXPR2` like Python has) – Ming-Tang Sep 21 '10 at 03:53
  • @SHiNKiROU: Perl seems to have a ternary operator, though. – zneak Sep 21 '10 at 11:19
  • `$x < 10 && do_something();`. Also, sometimes you can nice things with a `when` construct. – tchrist Nov 21 '10 at 02:47
3

reinterpret_cast<unsigned long> in c++. This operation is useful in dealing with foreign APIs and ensuring numerical precision, why should it be such a pain to type and so ugly to look at?

AShelly
  • 5,793
  • 31
  • 51
  • 17
    It's ugly to remind you that you should strive to write code that doesn't require it. :) – greyfade Sep 04 '10 at 20:58
  • To me that's a good theoretical computer science kind of argument, but in my experience, it's too useful to avoid (However, much of my experience is plain old C, so I probably have a bias). – AShelly Sep 07 '10 at 04:36
  • 5
    It's not really a theoretical CS argument: Using a `reinterpret_cast` in C++ is a very strong code smell. 99% of the time, when you are about to use it, chances are, you shouldn't need to - you probably did something wrong. The other 1% of the time, you're interfacing with C. `reinterpret_cast` breaks the type system to make something work when it otherwise can't. That's usually a bad thing. – greyfade Sep 18 '10 at 05:52
2

The fact that Python relies on text formatting.

Ashalynd
  • 264
  • 2
  • 6
2

Pointers of arrays or arrays of pointers in C/C++. I am still confused about these.

Casebash
  • 7,662
  • 5
  • 41
  • 62
  • 3
    Read the type backwards. `int[]*` is a pointer to an array of integers, and `int*[]` is an array of pointers to integers. Works well with `const`s too: `int* const` is a constant pointer to integers, whereas `const int*` and `int const*` are pointers to constant integers (or to integer constants). – zneak Sep 02 '10 at 22:42
  • @zneak: "Right to left" doesn't work, see the mentioned ["clockwise spiral" / "inside out"](http://programmers.stackexchange.com/questions/501/what-syntax-element-do-you-hate-most-in-a-programming-language-you-use-frequently/511#511) rule. –  Sep 09 '10 at 03:31
  • Or, just use *typedefs* and there's no confusion. – Billy ONeal Sep 18 '10 at 03:49
  • In modern C++ there is very little need for pointers and arrays. – fredoverflow Sep 26 '10 at 21:49
  • There's no such thing as a pointer to an array in C. – tchrist Nov 21 '10 at 05:15
  • 4
    @tchrist: Not true. `int (*p)[10];` declares `p` to be a pointer to an array of 10 ints. If `sizeof (int) == 4`, then `p++` will advance `p` by 40. – j_random_hacker Nov 29 '10 at 12:35
1

Verbosity in Java anonymous classes. Will hopefully be fixed soon.

alex
  • 2,904
  • 1
  • 15
  • 19
1

Javascript/Java etc, equals comparison, eg if(a==1)

How many times do I write if(a=1) ?

As a human I read that perfectly. But the darn interpreter/compiler says, "hey I'll assign 1 to a, then check if a is equal to 1, and would you believe it yes it is!

Drives me up the wall.

if(a==1) is far less readable, and the interpreter/compiler should know what I mean anyway; many other lesser languages (VB) have been working it out successfully for hundreds of years.

0

Scala multi-line code in brackets

For instance:

class Foo(
         val bar: String,
         val baz: Int,
         val bing: String,
         val bong: Boolean
 ) extends Model {
   // body here
 }

What you actually get from it is terrific. It generates the constructor and the getters and setters for you. But it sure is ugly and breaks all my mental models of how to indent code and basically leaves me feeling like I'm in a sort of bizarre sandwich with Java on one side and Lisp on the other. (Oh, wait... that is rather the point of Scala.)

Tom Morris
  • 231
  • 1
  • 7
  • I'm confused -- do you mean the portion in the parenthesis (`val bar` and so on) or the portion in curly braces (the part following `extends Model`)? (There are no brackets in that code) – Billy ONeal Sep 18 '10 at 03:36
  • 3
    The portion in the parentheses. I'm English. We refer to those as brackets, damnit, because in that situation they aren't serving a parenthetical role. – Tom Morris Sep 22 '10 at 11:39
  • 2
    It doesn't look all that bad if indented this way: http://pastebin.com/h9qC8XGg – missingfaktor Oct 15 '10 at 17:52
  • I find it more readable to write these constructor parameter lists horizontally, especially when I only have a few parameters. – MJP Jan 09 '11 at 21:08
  • Looks like a method to me. Like Simula. Good old school. – Tom Hawtin - tackline Feb 27 '11 at 14:21
0

REGEX / preg_match() in PHP

Firstly, its completely different syntax than PHP uses. While the preg_match() function emulates regex quite excellently, I have to completely switch my mode of thinking to work with it.

Secondly, its just plain obscurification half the time. I usually have to quite literally take out a scratch pad and figure out WTF its doing half the time.

Besides, I program in PHP, not Perl. If I liked Perl, I would program in Perl. (no, sir I don't like it.)

To make matters worse, with the new PCRE delimiter format, you can practically use any character, which includes having to escape that same nested character, making the pattern even more obscure.

Sure, its great if you want to be cryptic.. or even efficient... but holy hell the amount of time it wastes to normally perform simple tasks.

Htbaa
  • 1,004
  • 1
  • 10
  • 10
Talvi Watia
  • 768
  • 5
  • 19
  • 5
    The fact that you have your answer written with `PERL` in all caps tells me that you've never actually looked into the language at all and don't know anything about it. – Daenyth Sep 17 '10 at 19:06
  • PHP is sometimes too slow to do parsing any other way than with regexes. – Joeri Sebrechts Sep 18 '10 at 12:54
  • @daenyth you are right, I haven't much, however I wouldn't say don't know *anything*. But what Joeri said is correct.. it is needed occasionally and is the one thing that throws a monkeywrench in coding PHP without having to reference docs much. – Talvi Watia Sep 20 '10 at 00:03
0

structPointer->member in C/C++ . May be good for reading someone else's code, but I don't like it. Two characters instead of one... what a waste of space!

Federico klez Culloca
  • 3,092
  • 24
  • 24
  • 2
    Unfortunately, it must be distinguished from `.`, which applies to members of a non-pointer object. Ambiguous syntax is bad, mmmkay? – greyfade Sep 04 '10 at 20:54
  • 2
    @greyfade: Yep! Because the compiler can't *possibly* use its type system rules to tell when you're using a pointer-to-struct type and apply the dereference implicitly. Nope, that's crazy talk! (And yet it can still somehow give you an error message when you get it wrong.) There's nothing ambiguous about the syntax. It's just C being a braindead mess, as usual. Delphi does implicit dereferences just fine, if you're actually working in dark corners that require pointers-to-records, so it can certainly be done without confusing a parser... – Mason Wheeler Sep 17 '10 at 18:33
  • 5
    @Mason: What about cases like `shared_ptr`, where `->` accesses the contained type and `.` accesses properties of the `shared_ptr` itself? I'm sorry, but I completely disagree here. – Billy ONeal Sep 18 '10 at 03:50
  • `X->Y` is (read: ought to be) sugar for `(*X).Y` anyhow. – Jon Purdy Sep 20 '10 at 12:15
  • 2
    could be worse. Could be PHP, where you have to use `->` to access members of _anything_. – Carson Myers Dec 07 '10 at 04:11
  • @Billy ONeal: I disagree. It's C++, not C. First, in C there should never have been `->` as it's useless there. Second, for your special case another syntax could be invented. --- @Mason Wheeler: Agreed, but Delphi is much more confused (just try to overload a function on DOUBLE and TDate and call it). – maaartinus Apr 26 '11 at 22:27
  • @maaartinus: The answer says C/C++. – Billy ONeal Apr 26 '11 at 23:18
  • @Billy ONeal: I mean, there's no `shared_ptr` nor anything else in C, where both `.` and `->` could apply. So dot alone would be sufficient for C. – maaartinus Apr 27 '11 at 02:39
  • @maaartinus: Has there been anything I said contrary to that? I believe my comment clearly applies to C++ only. Personally, I find `identifier->` easier to read than `(*identifier).`, but that's more a matter of opinion. – Billy ONeal Apr 27 '11 at 14:31
  • @Billy ONeal: I'd suggest to always write `x.a`, no matter if dereferencing happens. For C it's sufficient, for C++ not always, but nearly always, and there could be a special syntax for such cases. – maaartinus Apr 27 '11 at 16:14
  • 1
    @maaartinus: Any code which relies that heavily on non-obvious order of operations is not code I will be writing. – Billy ONeal Apr 27 '11 at 18:27
0

I know this is an older question, but how come no one mentioned.

CODE NUGGETS

<% %> <-- Regular

<%= %> <-- Buffalo style

<%:%> <-- extra crispy

MVCylon
  • 597
  • 4
  • 15
-1

$this->... in PHP ... unnecessary, looks bad and considerably slows down "quick-grasp-on-short-glance" (my closed thread on SOF).

Raffael
  • 505
  • 3
  • 14
-1

SSIS - SQl Server I hate everything about the Expression Builder. I already know how to write these types of conditions in t-sql. Why can't they Expression builder use the same syntax t-SQl would use (especially The equivalent to the CASE statement)? Or let me write t-sql statements instead of creating stupid wierd expressions. And why am I stuck doing complex conditions in a form that only allows me to use one line so I am in scroll bar hell?

HLGEM
  • 28,709
  • 4
  • 67
  • 116
-2

& && | || in C

C++ has rectified it to some extend with explicit "and" "or" keywords. Many a bugs and torn hair could have been avoided in C if logical operations and bitwise operations weren't so hard to differentiate.

aufather
  • 4,449
  • 2
  • 26
  • 24
  • 1
    The `and` and `or` keywords are provided by ``. `#include` that your C programs and that's a complete non-issue. C++ is also required to provide the same header. – greyfade Oct 29 '10 at 18:16
  • 4
    I've never ever had trouble distinguishing the two... – Carson Myers Dec 07 '10 at 04:13
  • 1
    That's nonsense, it's trivial to remember and optically very different. Using the keyword `and` is even a bigger nonsense. Without reading the definition, what does `and` mean? Is it logical or bitwise? People confused by the difference between `&` and `&&` probably need something like `logand` and `bitand`. – maaartinus Apr 27 '11 at 03:04
-5

Ternary statements. They are generally much harder to read yet only save a few lines of code.

if (myCondition) {
    return firstAlternative();
}
return secondAlternative();

versus

return myCondition ? firstAlternative() : secondAlternative();
Garry Shutler
  • 641
  • 4
  • 8
  • 1
    Ergh. If you are going to write it longhand, at least use an `else`. – Tom Hawtin - tackline Feb 27 '11 at 14:28
  • 4
    Your example saves 3 out of 4 lines of code, i.e. 75%. This means that significantly more code will fit on my screen at a time. I think that is a pretty clear benefit. If you find statements involving the conditional operator “harder to read”, you probably just need to train yourself a bit more, and then you’ll have no trouble with them :) – Timwi Feb 27 '11 at 16:16
  • 1
    In addition, there is no such thing as a "ternary statement". It's an expression and he who doesn't recognize the difference should go look for another job. – Ingo Sep 06 '11 at 11:32
  • Perhaps this is better rectified by if expressions, ie `return if myCondition then firstAlternative else secondAlternative`, a la haskell/functional languages. – alternative Oct 31 '11 at 01:49