by ZitchDog · 12y ago · 0 comments
@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.
Exposing internals is still bad design.
Couldn't a simple compiler take in .m files and output compiled code + .h files?
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.
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!
- Object Pascal
- Delphi
- Modula-2
- Modula-3
- Oberon
- Active Oberon
- Component Pascal
- OCaml
- Haskell
- D
- Ada
- Eiffel
- ...
All languages with native code compiler available, where the header files can bot the manually or automatically generated from the implementation.
Many of them have, or used to have, code browsers and auto complete by reading the metadata stored in the binaries.
C based toolchains are still at stone age, in terms of modular programming support.