7 ms·
To me, it's easy to see what needs to be done with objective-c when you write a tiny class that creates a dictionary: @interface MyClass - (NSDictionar
by ZitchDog 13y ago
To me, it's easy to see what needs to be done with objective-c when you write a tiny class that creates a dictionary:
@interface MyClass
- (NSDictionary *)createSimpleDictionary;
@end
@implementation MyClass
- (NSDictionary *)createSimpleDictionary
{
return @{
@"keyForNumber": @1,
@"keyForBool": @YES,
@"keyForArrayOfStrings: @[@"one", @"two", @"three"]
};
}
@end
How much cleaner could this be if we dropped C backwards compatibility! We could remove the header file, and get rid of all the *'s and @'s:
class MyClass
- (NSDictionary)createSimpleDictionary
{
return {
"keyForNumber": 1,
"keyForBool": YES,
"keyForArrayOfStrings: ["one", "two", "three"]
}
}
end
This new language would get rid of many warts of Objective-C, bringing it up to speed with modern languages, while keeping performance and interoperability with the Cocoa toolchain.
There may be some perfect, completely new idea for a programming language out there, but Apple would never go for it. Developer experience is a distant third to the User experience and the Apple experience, and the only thing they will go for is an evolutionary, backward compatibile change such as this.
- jbrennan 13y agoHeh, which is similar to what I drew up a year ago, and even linked to https://github.com/jbrennan/ObjectiveNext/blob/master/language.md https://github.com/jbrennan/ObjectiveNext/blob/master/langua... :)
- K0nserv 13y agoWhy would we want to get rid of the .h/.m separation? It's a nice feature, Java's single file format is far worse in comparison.
- bwindels 13y agoHow is it worse?
- K0nserv 13y agoSeparation of interfaces and implementation is a core component of pre compiled code distribution, .h files + compiled library. By simply glancing over a header file one can achieve a quick idea of the interface without consulting the documentation. It's self documenting, reading a Java file in the same way is impossible. Forward declaration in header files and imports in implementation is also a huge benefit in compilation speed and complexity.
- frou_dh 13y agoThe point is that writing and maintaining such files by hand is a tremendous waste of time. When I last used C#, I remember Visual Studio would extract and display such public overviews directly from compiled .NET assemblies. Even if no IDE is involved, something could just auto-generate a text file for distribution. It could even be adorned with a .h file extension for faux-retro appearance!
- K0nserv 13y agoI do agree partially about the repetition issue, but with a language such as Objective-C you'll auto complete every definition the second time which hardly takes a second, especially with fuzzy auto completion. If time saving is the goal the naming convention for methods is a far better candidate for change
- frou_dh 13y agoZapping the entirety of an unnecessarily manual practice is going to be objectively better than providing some typing assistance for it.
- K0nserv 13y agoThere are still use cases for header files which would require additional syntax if headers are to be generated from .m files. Also the use case of forward declaration comes to mind which would totally lost with an implementation only system
- necubi 13y agoI, and basically every language designer since the 80s has disagreed with this. It's needless repetition: all of the information contained in the .h file is duplicated in the .m file. If you really want a nice listing of the exported methods, it's easy to generate that from the .m file.
- frou_dh 13y agoStockholm syndrome from too many years in the company of archaic compilation models: it's real and it's scary!
- pjmlp 13y agoIt is incredible how C based compilation models become so widespread, that younger programmers are completely unaware of sane module systems in other languages with ahead of time compilation toolchains.
- K0nserv 13y agoI agree that there is some merit in the repetition argument, but when discussing a language like Objective-C we must consider that any Objective-C programmer is surely using auto completion to the fullest extend due to the extremely verbose nature of Objective-C naming conventions. The point being that the repetition time is negligible
- i386 13y agoOnly worth doing if there are some directives added for public/private directives. Exposing internals is still bad design.
- muaddirac 13y agoThe separation is nice, but does it need to be done manually? Couldn't a simple compiler take in .m files and output compiled code + .h files?
- K0nserv 13y agoIn C/C++/Objective-C the .h files are not use solely for declaring the public interface of a class a lot of times this is where one exposes enums, typedefs, defines which are related to the class in question. The obvious argument against this is using static class members, but I would argue that it adds unnecessary verbosity.
- muaddirac 13y agoTrue, but that's nothing that couldn't be done in either a separate file or in the .m?
- gfodor 13y agoWhy should the on-disk format of a programming language have anything coupled to a specific use-case for browsing that code? If viewing just the definitions of a method is useful (ie, viewing the header file) then your editor should just let you do so. Letting that bleed into the way the files are organized on disk at the cost of DRY seems a terrible design choice as it serves no purpose other than to make up for poor tooling.
- mmerickel 13y agoOn the contrary, Objective-C is one of the only languages that actually gets header files right and subsequently they are a wonderful feature. They are very readable since it's now possible to write them to perfectly describe your public interface. All implementation details are kept in the .m where they should be.