7 ms·
> It has a very expressive syntax and uses modern idioms you see in JS, Kotlin, Rust, Scala, C#, etc. Yeah and that's exactly what I would call a disadvantage.
by grishka 6y ago
> It has a very expressive syntax and uses modern idioms you see in JS, Kotlin, Rust, Scala, C#, etc.
Yeah and that's exactly what I would call a disadvantage. I prefer dumb programming languages like Java, C++11 without the auto keyword, and Objective-C. They're much easier to understand because there are fewer ways to achieve the same thing and they don't require keeping as much context in your head while reading the code.
IRL example with Swift: I wanted to fix a logic bug in someone else's code and spent an hour trying to get a field from an object. I could see it in the debugger but every way to get it I could think of produced an uninformative syntax error. There was nothing to google because there were no keywords around it, even. Then the author of the code in question came online and explained that it's an "enum with associated value" (wtf?!) and you have to use this `if let` or `case let` abomination to extract the fields into local variables.
Another IRL example with Swift is that this whole immutability-by-default thing was just driving me insane because I'm too used to the fact that I can overwrite function/method arguments but Swift won't ever let me.
- saagarjha 6y ago> C++11 without the auto keyword That's still a massive language; the part you removed makes it basically be C++03 but even worse :/
- grishka 6y agoHow worse? How would you even begin to understand this line without an IDE? auto something = someObject->someFunction(); // and then 10 lines of various operations on "something" // also imagine that someObject is also auto and returned from somewhere I've had to deal with code like this. It wasn't pleasant, even with an IDE. There are very few cases where type inference is good and doesn't make your code an unreadable mess.
- vips7L 6y agoYou just need to use auto properly. auto/var/val etc are best used when you can tell the type from the rvalue. var m = new HashMap<String, List<Pair<X, Y>>>(); var m: Map<String, List<Pair<X, Y>>> = obj->someFunc(); All of the examples you have should be caught in linting or code review.
- grishka 6y ago> You just don't know how to use auto properly. I do. The problem is, others don't necessarily do. A good-in-my-world language makes it take more effort to write unreadable code than readable. Everyone seems to only be judging languages by the code you write yourself, totally oblivious to the fact that reading and understanding someone else's code, including in projects you don't influence, is also an important part of being a software developer.
- saagarjha 6y agoBelieve me, we've read a lot of code written by other people. There's a point where you read HashMap<Integer, ArrayList<String>> mapping = new HashMap<Integer, ArrayList<String>>(); enough times that you start to get tired of reading stuttering code, too.
- vips7L 6y agoBy your logic we shouldn't program because someone else MIGHT mess it up. Should we remove every feature that someone might misuse?
- snazz 6y agoType inference is the usual tradeoff for being able to write statically-typed code efficiently. I think it's better than MyType something = new MyType(...); like in old-school Java, is it not? IDEs and LSP-enabled editors are pretty much the standard nowadays, although I agree that it's nice to be able to read code without one. Also, that code you mentioned seems like bad style with the auto keyword; the type should be obvious. Do you have a better solution in mind?
- grishka 6y ago> IDEs and LSP-enabled editors are pretty much the standard nowadays There are many places where you see code without IDE-like features. One that comes to mind is everything related to git. Web-based git tools like github, git GUIs, command-line git, you name it. Besides, it's nice to be able to read and understand the code without needing to download the entire project and importing it into an IDE just for that. My idea is that you almost always write in an IDE, but not necessarily read in one. Thus, for verbose languages, the IDE would generate most of that example for you (I know for sure IDEA does this exact completion) but it will be perfectly understandable in a git diff.
- dragonwriter 6y ago> There are many places where you see code without IDE-like features. One that comes to mind is everything related to git. Web-based git tools like github, git GUIs, command-line git, you name it. Both git and web-based git+ services like Github are frequently used through deep editor/IDE integrations, so, no, I disagree that “everything related to git” is a good example here.
- pjmlp 6y agoI use all such tools mostly from the comfort of my IDE.
- saagarjha 6y agoStep number one is not naming your things "something". I for one am glad I can use "auto" instead of "std::vector<int>::size_type" in my code–in this case the actual type this couldn't matter less; all you need to know is that it's some kind of unsigned integer. The same is true for Swift, where it's generally a lot more useful to know you have some type of sequence rather than "I have a LazyMapSequence<LazySequence<[Int]>.Elements, String>". Plus, C++ is one of those languages where certain things have types that you cannot write down, so auto is required to use certain parts of the language!
- julius_set 6y agoThat’s not a problem with the language that’s just you not knowing how to use it, two very different things. Associated values with enums are very powerful features of the language.
- grishka 6y agoAnother problem of these languages is that you have to actually learn them, and there's too much to learn. And good luck understanding anything without that encyclopedic knowledge. To me, it's all just abstractions that get in the way more than they help, tbh.
- julius_set 6y agoI mean you can say that for any language. If someone has to learn C or Java, you still need to learn how those languages work, build domain expertise and so on. Swift is a very nice general purpose language and I’ve been writing code decades in almost most mainstream languages. I much prefer writing Swift code, in face some of my back end projects have been written in 100% swift, this allowed me to reuse models and APIs with the iOS and MacOS counterparts.
- hajimemash 6y agoHow have you written backend code in Swift, were you able to use it in places you would normally use e.g. C++? I'm asking because I like Obj-C/Swift, and am wondering if it's possible through some clang/LLVM magic to be able to code Obj-C/Swift in environments that expect C or C++, for example like in Qt. Like, could I have a traditionally C++ app (Qt app) but have most of my code be in another LLVM-compatible language.
- julius_set 6y agoThere’s a very vibrant backend community for Swift, Vapor is growing and used in production for a lot of companies. https://vapor.codes https://vapor.codes
- 6y ago