• Edd (unregistered)

    Make an API that randomly chooses the format for its response.

  • Dennis (unregistered)

    TRWTF is clearly Objective C. How did anyone think that taking the worst parts of C and mix with Perls overuse of symbols was a good idea? The end result is barely readable and almost as ugly as Perl.

  • Fun With API (unregistered) in reply to Edd

    I have to use a REST service of this kind here. If it can answer our request it returns a response type. If it encounters a problem it returns an error type. But if it is an authentication problem it returns an OAuth error. And if you request to simulate an error situation it returns the error message as plain text.

  • my name is missing (unregistered)

    I used Obj-C for nearly 15 years before switching to Swift 6 years or so ago. It's not a terrible language despite the odd syntax on top of C. But it's extremely dynamic and especially in the old days was prone to incredible easy bugs. An NSArray before Apple added attributions could contain any data type, its really just a collection of object references and its up to the user to make sure it contains what you expect. A better way (without attributions) would be to safely check the type of what is in there instead of using try catch.

    Today I find using Obj-C over Swift a laughable choice, Swift is such a joy to work with, and writing quality code is really easy. But parts of Apple still insist on using Obj-C for some reason even when they could switch.

  • Brian (unregistered)

    I worked with a "veteran" C++ programmer once, who had apparently decided that strong typing was for chumps. He wrote his own collections library that stored all elements as char arrays. By which I mean you could pass in a value of any type (yes, including another one of these collections), and the library would copy it byte-for-byte into a char array. So, just like this example, you could have an array where every element is something completely different - all you had to do was remember what you put in and cast it to the right type when you get it back out. Simple, right?

    Oh, and the naming conventions of the library seemed to follow those of PHP. In other words, he took a language with a reputation for being complex and error-prone, and used that complexity to emulate an even worse one.

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered)

    Objective-C's type system can sometimes be pretty loosey-goosey. Lots of functions return id (e.g. [NSArray objectAtIndex:]), which is basically like a void* pointer to an instance of an unspecified NSObject subtype. id can be implicitly cast to any Objective-C class type, so it's very easy to end up with the wrong type in code that doesn't perform any unsafe casts or generate any warnings. E.g.:

    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:@"foo"];  // Insert NSString into array
    NSDictionary *dict = [array objectAtIndex:0];  // Ok, implicity casts id to NSDictionary*
    int x = [dict count];  // Raises NSInvalidArgumentException (unrecognized selector sent to instance)
    
  • 516052 (unregistered) in reply to my name is missing

    This man, I like the color of his thoughts.

  • (nodebb) in reply to Dennis

    I thought Objective C was C+Smalltalk, not C+Perl.

  • Trust Me I'm Not a Robot (unregistered) in reply to Edd

    Ah, that would be PHP.

  • Progress (unregistered)

    So we go from 1's and 0's up to assembly language, then up to high-level languages and then down to runes... I'm assuming this was because someone decided typing a '+' is far faster and denser than typing 'static'. Well, I only have one thing to say about that: %@&$*!

  • Best Of 2021 (unregistered)

    Objective C is a huge WTF. It is different from normal C family languages in ways that are completely unnecessary, I guess because Apple want to lock everyone into their ecosystem so they make the skills you need to write it not be that transferrable. And it seems they decided to throw away all the lessons learnt by modern managed and type safe languages (even modern C++, if they didn't want an intermediate IL+JIT compiler for some reason).

    You can trigger this same WTF in Java as its lists have type erasure, but you have to try fairly hard.

  • Loren Pechtel (unregistered)

    Of course it's cryptic! What else would you expect of spooks? It's right there in the type: NSA.

  • Torgo (unregistered)

    This looks like Obj-C written by a Java or C++ programmer. Any time you see @try/@catch blocks in Obj-C, it's a bad code smell, since up until recently, handling exceptions like this would more likely than not lead to memory leaks for autoreleased objects (although this code is so simple, it might not affect it here). Since there's no type attributes on anything, one would assume this code is old.

    A real Obj-C programmer would check the class of the value at index I to verify that it's an NSString. Exceptions are not used for flow control in Obj-C.

  • Naomi (unregistered) in reply to Best Of 2021

    You can trigger this same WTF in Java as its lists have type erasure, but you have to try fairly hard.

    Not really that hard - you'd just cast to List or Set or what have you. You just get a very clear warning and have to explicitly suppress it if that's really what you want to do (and there are occasionally reasons to do that, mostly related to reflection, occasionally related to not making a copy of an immutable collection just to placate the type checker - but List#copyOf and friends take care of that for you these days). It's the warning that makes it different, imo. It will let you; it just asks you to confirm you're doing it on purpose, unlike the Objective-C example up above.

    (One thing that is pretty cool - and that I don't think C-Octothorpe supports, but please correct me if I'm mistaken - is so-called wildcards, which let you discard type information without doing anything unsafe. You can cast any list to a List<?>, and that'll only let you use methods that don't involve the type argument. You can also do <? extends Foo> or <? super Foo> if you only need to partially specify the type argument.)

  • I dunno LOL ¯\(°_o)/¯ (unregistered) in reply to Brian

    library that stored all elements as char arrays

    Did he later go on to work on Enlightenment or Tizen?

  • I dunno LOL ¯\(°_o)/¯ (unregistered) in reply to Best Of 2021

    Objective-C came from NeXT, Apple just got it along with the rest of NeXTStep when they got bought out for negative 400 million dollars.

  • Naomi (unregistered) in reply to Best Of 2021

    I guess because [Microsoft] want to lock everyone into their ecosystem so they make the skills you need to write it not be that transferrable.

    This, more than any technical reason, is why I'm so unfavorably disposed to the Microsoft(R) .NET(TM) Visual(C) Framework(We own you)(TM).

  • Al Pine (unregistered)

    “ But please just put the same kinds of things in an array, for all our sakes.”

    Unless, of course, you’re using Python.

  • Filippo (unregistered)

    Objective C should be renamed to Objectively BS.

    Most languages are conceptually similar and fairly easy to understand: once you know any language, you can relatively easily pick up on the basics of the other ones. Reading Objective C on the other hand is like reading cypher code.

    That language is TRWTF...

  • Dennis (unregistered) in reply to Barry Margolin 0

    Oh, it definitely is, and it's a few years older than Perl, so no chance that it had inspiration from it.

    I just described what it looks like to me.

  • (nodebb) in reply to Fun With API

    And this is exactly what union types and match statements are made for. I am stuck in PHP right now for work and I'm reallllllly looking forward to moving to something that will help me out instead of just being a blank canvas that someone else scribbled on several years ago and now I have to figure out which line goes where.

  • Worf (unregistered)

    Obj-C came out at a time when C++ didn't exist. Yes, it's that old.

    It's basically C with objects, and unlike C++, it is completely compatible with C in every way, down to the calling convention (no extern "C" rubbish here).

    It's really dynamic. Just because you call an method on an object, doesn't mean some other object couldn't hijack the method call first. In this way, it's possible to overload functionality that wasn't available when the program was compiled. An example of this would be the spell checker - Apple integrated spell checking into text boxes so any application using a text box suddenly had spell checking functionality built in with zero work on the app developer. Sure, in some languages and OSes, you could do that by replacing the library handling the text box, but it's generally hard to do it universally.

    It's also how things like the screen reader and other accessibility things work - a little runtime work enumerating GUI objects. Or in this case, a thread in the screen reader sending messages to the text box in your application to highlight the text box of interest and even the word being spoke, without you writing a single line of code to support it. All that happened was the screen reader sent messages that your code handled.

    Basically, an Obj-C program is a bunch of classes that get made into objects at runtime, When you make a method call, it's effectively sending a message into the runtime, and the runtime figures out what objects from the system, language and your program are run.

    Of course, given it dates all the way back, it's not surprising it has a bunch of idiosyncracies. Swift is a modern language that was created over 30 years after Obj-C, so it's not unusual that it would have improved a bunch of things.

  • xtal256 (unregistered)

    Remy: "TRWTF is Objective-C's syntax. ObjC had some interesting ideas, but there was an expiration date on those ideas pretty much right away."

    I'm not sure which "interesting" ideas you are talking about, but most of Objective-C's features were taken from Smalltalk, which actually has a nice readable syntax instead of this abomination. As for expiration date, Smalltalk's features were way ahead of it's time and other languages are only now just catching up (e.g. lamdas / arrow functions, ).

  • Chris (unregistered)

    I find the readability of a language (especially for newcomers - anything is easy to read when you're used to it) depends on how many punctuation characters are needed within each statement, besides the usual math operators (including assignment that uses '='). E.g. C++ has lots of *, &, ::, and ->, which can make code harder to read. Compare that to C#, which either doesn't need those, or simply uses a '.' which is much smaller and easier to parse visually. But then you add in things like LINQ, lambdas, string and null operators, which add a whole lot of ?, $, @, {}, (), and =>, so it becomes harder to read again.

    But I'll take all of that over Obj-C any day.

  • (nodebb)

    Apple should immediately start using a language which is much better than Objective C - PHP.

  • Your Name (unregistered) in reply to Naomi

    You might want to update your outdated knowledge. .NET is open source, available on Windows, Mac and Linux.

  • Naomi (unregistered) in reply to Your Name

    That changes nothing.

  • (nodebb)

    Well you actually missed two WTFs.

    The first is using exception handling as flow control. This should never be done in Objective-C since quite a lot of Objective-C code is not exception safe and C, with which it interoperates seamlessly, hasn't even got the concept of exceptions.

    The second is returning the result of UTF8String. The storage it points to is not guaranteed to be valid beyond the scope in which it was created. It should, at the very least, be strduped before returning it.

    Objective-C, by the way, is a pretty good language. Criticisms of its syntax from people who do not understand it are not really useful.

Leave a comment on “Changing Your Type”

Log In or post as a guest

Replying to comment #:

« Return to Article