3 ms·
The Swift naming convention makes it more difficult to learn, discover, and use large, complex APIs like AppKit and UIKit, so I'll often revert back to Objectiv
by thought_alarm 5y ago
The Swift naming convention makes it more difficult to learn, discover, and use large, complex APIs like AppKit and UIKit, so I'll often revert back to Objective-C when writing AppKit (and to a lesser extent, UIKit) when given the choice. It's common for me to still mix the two languages in a single app.
For example, this the AppKit API for pulling a URL off of the pasteboard:
+[NSURL URLFromPasteboard:]
It's easy to find, since it has both URL and Pasteboard in the name.
The Swift version gets melted down to this:
URL(from:)
which is obfuscated nonsense. Unless you already know that API exists, you'll never find it.
The Swift version of AppKit is littered with this kind of obfuscation. Since I don't code in AppKit very regularly, I usually just throw my hands up and switch to Obj-C whenever I start running into these kinds of road blocks.
The Obj-C naming convention has advantages and disadvantages, but has always been considered verbose. The Swift designers considered this a problem in need of a solution. As is almost always the case in software development and language design, the solution was a giant overreaction and overcorrection that just replaced one problem with another.
- matchbok 5y agoHuh? That makes no sense. The Swift API is init?(from pasteBoard: NSPasteboard) Which should autocomplete/hint while writing code. The documentation is in the type, not littered within the function name. Much more easier to read and write. The "pasteboard" is still very much in the function declaration. Compared to the obj-C version: + (NSURL *)URLFromPasteboard:(NSPasteboard *)pasteBoard; Not sure why they insist on no spacing, or sane formatting, for Obj-c. I still can't read most Obj-c - it's horribly designed.
- thought_alarm 5y ago> Which should autocomplete/hint while writing code It does not. Parameter types and alternate parameter names are ignored by Xcode autocomplete. If you want to use init(from:), you have to already know that it exists and does something good. Typically, you only find a method like that by looking at the Obj-C header. And that method is declared in the NSPasteboard header, not NSURL.
- Someone 5y agoSo, the problem is not the naming, but autocomplete in Xcode? Or is it impossible to write a good auto-completer for Swift because Swift is rather unique in splitting function names into multiple strings? IIRC, Xcode uses LSP; is that a bottle-neck?