6 ms·
The removal of prefix and postfix ++ and -- operators and the removal of C-style for loops are mistakes, IMO.
by DonFromWyoming 10y ago
The removal of prefix and postfix ++ and -- operators and the removal of C-style for loops are mistakes, IMO.
- deleted 10y ago[deleted]
- RotsiserMho 10y agoAs a C++14 programmer, I disagree. for..in syntax is so much clearer and being able to simply specify the range without having to manually increment makes more sense to me. I would love to see something like Swift's stride in C++.
- lanestp 10y agoI gotta disagree with this one. Those operators have always been confusing and unnecessary. j = i++ being different from j = ++i alone is enough to convince me it's gotta go.
- warmwaffles 10y ago++i and i++ have their uses. Just because it is confusing to you doesn't mean it is confusing to others. There are things about swift that are confusing to me, but I don't out right say that it has to go. Chalk this one up to shit hacker news says.
- whatever_dude 10y agoI believe something can be easy to understand (as is i++/++i) but also confusing. Things that require a double take to read and parse do not help. Additional solutions to the same problem do not help. There's a lot of cleverness that can come up in programming that may make for neat/short writing but that makes reading and purpose less clear. i++/++i helps with that with no special benefits. I like how the Swift team approached the decision to remove them: thinking on whether it would make sense to add them had they not been there. And it doesn't, as they solve no particular problem; they're just a special, (not much) shorter solution to something that's already solved.
- proyb2 10y agoToo easy to get errors for array or objects loop outside the boundary that can be confusing for any teams dealing with large scale and when the requirements change frequently.
- gagege 10y agoExactly. I am disappointed they're removing function currying/partial application syntax though :(
- thevibesman 10y agoThis was my first reaction as well, but then I realized I hadn't done much currying in Swift and half forgot it was a feature. Maybe you can bring it back when we get hygienic macros (Swift 4.0? fingers crossed)
- lanestp 10y agoThe currying was cool. I had to read the pull requests on that one and it seems that it was removed because it complicated language development. I'm hoping they bring it back in a modified more extensible way!
- andybak 10y agoWith regard to C-style for loops - other than familiarity - why? It always struck me as a fairly warty syntax. Consider Python where you usually do: for item in iterator If you want an integer sequence it's: for integer in range(1, 100) and for those rare occurrences where you need an integer index as well: for index, item in enumerate(iterator) Swift seems to have a similar approach. Why would you ever want the C-style iterators?
- DonFromWyoming 10y agoFor the simple case with a single iterator, yes the C-style for loop isn't as concise. However, there are lots of real-world situations where there is not a single iterator (e.g. looping through 2 arrays). Having to go back to 'while(boolean) { }' loops with initializers outside of the loop and incrementors at strange places inside the loop is much more confusing and error prone.
- joewillsher 10y agoYou can use the zip function to loop through 2 collections. `for (l, r) in zip(c1, c2) {` It is not simply motivated by making code concise, I would say `for num in collection.reverse()` is less error prone and clearer than `for (var i = collection.count; i >= 0; i--) { var num = collection[i] ... }` The reverse collection iterator is computed lazily too, so there is no little perf overhead
- bluecalm 10y agoSometimes having those counting variables available is needed. You can use enumerate now but it introduces a lot of noise as now everything is a tuple with a number. It just makes expressing some algorithms messier and less readable although in general for sure "new style" loop is more readable and less bug prone.
- riyadparvez 10y ago> prefix and postfix ++ and -- operators IMHO, these operators are the worst features of C. Particularly I never understand the necessity of both i++ and ++i operators in language at the same time.
- bluecalm 10y agoIt's to make code more concise. There are many idiomatic one liners to compare arrays for example or to find the first element which satisfies the condition etc. I don't mind removing them but their usecase is obvious: make the code more concise and more readable (and yes, if you program in C on daily basis you don't require a double take or thinking about what ++ does).