by grishka · 6y ago · 0 comments
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.
Associated values with enums are very powerful features of the language.
To me, it's all just abstractions that get in the way more than they help, tbh.
> I prefer C++11
C++ is like the prototypical example for "languages that require encyclopedic knowledge" so this seems like a weird comparison
To me it sounds as if your problem is purely lack of familiarity with modern languages, rather than them lacking some specific property that your usual languages have.
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.
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.
That's still a massive language; the part you removed makes it basically be C++03 but even worse :/
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. 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?
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.
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.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.