4 ms·
This seems a little creepy from a code archaeology standpoint? Haven't written any D so I don't know if it's an improvement over what came before, but this look
by jfb 14y ago
This seems a little creepy from a code archaeology standpoint? Haven't written any D so I don't know if it's an improvement over what came before, but this looks a little magical for my tastes.
- tomjen3 14y agoI imagine it would be a relatively simply matter of getting used to it. Objective C and C# both have extension methods, which are very useful when done right. Ruby has allowed you to reopen classes since forever.
- WalterBright 14y agoThe point is to not have to reopen classes.
- grn 14y agoBut is there an essential difference between these methods?
- Someone 14y agoExtension methods can only use the public API of objects. Opening a class and adding methods allows one to access the private API, too. That, of course, is only a difference in languages that have the public/private distinction.
- grn 14y agoBut it doesn't make reopening classes bad. You have a choice: you can use a public API or mess with implementation (for example for performance reasons).
- tomp 14y agoThe essential difference is that extension methods are visible only in compilation units that explicitly import them, while adding a new method to an existing class makes it visible everywhere.