4 ms·
I've moved to Swift as well. It's much better, for much the same reasons as stated in the article. Particularly stronger typing is useful. Code that uses the A
by lordnacho 11y ago
I've moved to Swift as well. It's much better, for much the same reasons as stated in the article.
Particularly stronger typing is useful. Code that uses the Any object (or Object if you're in c#) tends to look horrible and have runtime errors, or it (what class it really is) has to occur to you as you're coding, which sadly doesn't happen 100% of the time for me.
I also find it's easier to not do [obj msg] everywhere. It just seems unnatural to have to go to the beginning of a token and put a [ in front. Much easier with a more ordinary syntax that's just obj.msg. ObjC had some of this, but mixing the two made it even weirder.
I did come across a compiler bug though, and that tends to take a long time to be sure of (don't want to write a bug report and find out it was your own code all along). I guess it's just a question of time before that sort of thing is stable.
Another pet peeve of mine is separating classes into .h and .m. I have to do this in c++ code as well, and I don't like it. Much better just to let the language take care of it for me. The interface is pretty clear anyway, so why separate it and have another file to keep consistent? I guess it's mainly a legacy issue.
One thing that needs to be done is XCode needs to be able to refactor Swift. Hopefully it's around the corner.
- s73v3r 11y agoI honestly don't get the hate toward header files. They're not great, but are they really that bad?
- pjmlp 11y agoI guess you never used module based languages. Why write things twice when the compilers are able to export text definitions from modules and IDEs can show them as well.
- vonmoltke 11y agoMaybe I am misunderstanding, but I thought the point of headers is to avoid writing things twice (or more).
- pjmlp 11y agoOn the header file you write the function interface and class definitions. On the implementation file you have again to repeat those plus the actual implementation. On many languages with module support, you just mark whatever symbol with public, that's it.
- vonmoltke 11y agoOK, you meant specifically the source/header split on classes in languages like C++. Yeah, there is definitely redundancy there that gets eliminated by headers. I also think I may have been conflating "header" with "include file" to a greater degree than is appropriate.
- s73v3r 11y agoI have. And while nice, I honestly don't see what's so bad about writing headers. I like being able to export a set of headers and a binary library.
- pjmlp 11y agoWhy write them if tools can do it automatically for us?
- mjcohen 11y agoBecause the tool may include more information than is needed or wanted. The tool may also not be able to detect (without being told) that some information should be included.
- pjmlp 11y agoI fail to see what one can different. Public types are visible, which are the only ones that matter to the module user. Many languages with modules support public and private comments as well.
- coldtea 11y agoThey're not bad. Just redundant.
- mkesper 11y agoAnd redundancy _is_ bad.
- coldtea 11y agoDepends. Other times we call it "backup". Or "failover".
- astrange 11y agoRedundancy is not always bad. It allows concurrent evolution in your code, specialization, and info hiding, because each copy is in a more specific context and you know just what you want from it there. Related: http://yosefk.com/blog/low-level-is-easy.html http://yosefk.com/blog/low-level-is-easy.html In Objective-C writing headers by hand gives full manual control of what your library's users get to know about your class, including comments. Internal things just don't appear in the first place. C++, of course, makes it impossible to hide anything from your users because they need to allocate your class themselves, you need to put all your private ivars and methods in the public class definition, and you can't add ivars to the class later. But that's its problem.
- GFK_of_xmaspast 11y ago> C++, of course, makes it impossible to hide anything from your users because they need to allocate your class themselves, you need to put all your private ivars and methods in the public class definition, and you can't add ivars to the class later. On the other hand, actual practice: http://www.gotw.ca/gotw/024.htm http://www.gotw.ca/gotw/024.htm
- astrange 11y agoOh, but Objective-C does the right thing using the standard and simplest way to write it, and you can subclass other people's classes and everything! http://stackoverflow.com/questions/12522053/what-is-a-non-fragile-abi http://stackoverflow.com/questions/12522053/what-is-a-non-fr...
- DubiousPusher 11y agoYes, they are. 1) They add fragility. It's all too easy to take a dependency on code without explicitly stating it. I'm using objects from "b.h" by including "a.h" which include "b.h" but I don't realize it. 2) They bring extraneous data into the code. A #include says more about the structure of your files than it may about the logical relationships between objects. Where to get things for the build is a job for the build config/system, not your business logic. 3) They're easy to use poorly. From your first circular include to the time you have to sort out a crawling build brought on by a bloated include tree, you'll swear there's gotta be a better way. They are good for some people though; there's a small cottage industry that's built around resolving the myriad irritations headers bring.