48

Since the unveiling of Swift, I've noticed a lot of iOS/OS X questions (both new and old) marked with the Objective-C tag receiving answers in Swift.

I've also seen in many cases users commenting on these answers or even downvoting because the question was marked as Objective-C.

My take on this is that an answer in Swift should still be acceptable (as long as the question is not too language dependent) because the APIs and development environment are still pretty much the same, it just means that people will have to take some time to convert the code (which shouldn't take much time anyway if you actually understand the logic behind the code). It also helps future readers who have the same question and want the code in swift for convenience. You can typically find both languages used in the answers anyway on hot/popular questions.

Now questions specifically about the Objective-C or Swift language should obviously be answered in their respective language. But when answering questions in general on iOS/OS X development I think as long as the answer answers the question, it should be acceptable, regardless of the language. It may not be the ideal answer the asker was looking for. But I don't see any harm in having both Objective-c and Swift answers on a question. Perhaps in such cases we should edit the question tag to include both Swift and Objective-C? Or just don't include either when the language is not significant?

This is just my opinion of course. I would like to see what others think of this question because I am still unsure.

19
  • 14
    A related, and perhaps more involved question: should questions asking for a way to solve something, tagged as Swift, be closed as duplicates of questions that have answers for how to do that in Objective-C? See the debate around this question: stackoverflow.com/questions/28263403/… as an example. Do we want the older Objective-C iOS and Mac development questions to be re-asked in Swift?
    – Brad Larson Mod
    Commented Feb 3, 2015 at 18:17
  • 6
    I have downvoted many such answers, but only where the question is truely about Objective-C. Such a question would be of the "I have a problem when I try to do X" variety. I doubt anyone is going to rewrite their 10k line program into Swift so they can use an answer from SO. But there are other questions such as "How do you use API Y?" that would benefit from answers in both languages. Commented Feb 3, 2015 at 18:47
  • 7
    On the other hand, @BradLarson, we wouldn't mark a question about doing something with a third-party Android/Java SDK as a duplicate of the same task for the iOS/ObjC version of the SDK, even though (as you say) "what's important here is the API, not [the language]". I'm sort of split on this question. You're right that e.g., "How do I store an NSColor in NSUserDefaults... in Swift?" is probably not going to produce a substantially different answer than the ObjC version. But I also really don't think that replying in Swift to a question whose code is ObjC (or v.v.) is particularly helpful.
    – jscs
    Commented Feb 3, 2015 at 19:29
  • 1
    Of course, the basic competency of the asker is a part of this issue, too. Swift is a C-like language, whose syntax is even in part based on ObjC. For simple tasks -- like the two-line solution to the question @Brad linked -- it's not entirely unreasonable to expect the poster to be able to do the translation. But then again, as time moves on, there are likely to be developers who start with Swift, never really learning ObjC. What should we expect of them; is there any reason not to have Swift-specific artifacts on SO for them?
    – jscs
    Commented Feb 3, 2015 at 19:34
  • 2
    @JoshCaswell - The interesting aspect is that the APIs were defined in Objective-C, with Swift built in part to provide backwards compatibility to this, and we've grown a large knowledge base around Objective-C. For questions where the Swift implementation would deviate significantly from Objective-C (due to language features or things like pointer handling), I can definitely see these standing on their own. We might see a larger number of "translate this for me" questions as developers are brought up in a Swift-first environment, and I'm genuinely curious as to how we should handle these.
    – Brad Larson Mod
    Commented Feb 3, 2015 at 19:44
  • 10
    would posting answers in Groovy, Scala, Python, or JavaScript to a question tagged Java be appropriate just because the JVM can execute those languages as well?
    – user177800
    Commented Feb 4, 2015 at 16:43
  • @JarrodRoberson But the question wouldn't be about the language, but rather how to use the APIs. So that analogy doesn't really work.
    – Epic Byte
    Commented Feb 4, 2015 at 16:50
  • 3
    and do not go adding language tags if someone has already added one or the other, if a question is in C# and you want to provide a VB.net answer you do not get to just add the VB.net language tag unilaterally, that would be a harmful edit.
    – user177800
    Commented Feb 4, 2015 at 16:51
  • 1
    how is a question with the language tag java not about the java language? would a question tagged regex that was about parsing get a yacc/bison/antlr answer as a valid answer? No, it would not. Would someone be out of line adding those tags just so they could answer in that context? Yes they would. This is a ridiculous circular argument you are making about implied overly broad semantics. By your skewed logic, every thing can be answered in any language because it is all about programming or algorithms right?
    – user177800
    Commented Feb 4, 2015 at 16:53
  • 2
    @JarrodRoberson The problem is the Objective-C tag is often used in questions that are not about the language but about the APIs. People either use that tag accidentally, or maybe they use it because that is the language they are working with and want their response in.
    – Epic Byte
    Commented Feb 4, 2015 at 17:07
  • 7
    Are you a mind reader? if they tagged Obj-C then who are you to second guess that they do not expect an answer in Obj-C? If someone asks about doing something in Spring and adds the Scala language tag then they are expecting an answer in Scala not Groovy or Java or whatever. And changing, removing or adding a language tag unilaterally is vandalism. A question about finding if a Point lies inside a Polygon tagged with C would expect an answer in C and not in C++ or any other language.
    – user177800
    Commented Feb 4, 2015 at 17:07
  • 3
    @EpicByte If I'm following you correctly, I don't think I'd mind a swift answer to my Objective-C question (if it's broad enough, as you say, and not a specific to Objective-C problem), but as soon as someone comes along and posts your exact code translated to Objective-C, I would select their answer instead. I might even write my own answer of your Swift code translated to Obj-C and select it over yours. In other words, I'd say "You are being helpful, but your answer cannot be correct, fundamentally"
    – Patrick
    Commented Feb 4, 2015 at 17:08
  • 6
    This looks very similar to .NET VB/C#. It's kind of rude to answer in C# when someone asked a question about VB.NET, but if the question is about the framework in general then it doesn't mater.
    – the_lotus
    Commented Feb 5, 2015 at 20:28
  • 2
    @BradLarson Beleive it or not, there already are iOS developers who have learned only Swift: stackoverflow.com/questions/28357177/…
    – nhgrif
    Commented Feb 6, 2015 at 1:53
  • 1
    @nhgrif - Sure, I sit on an advisory board for a local college and watched them migrate their entire Mac / iOS degree program over to Swift last summer. That's the language their new students are learning, but they are still making sure these students can at least read Objective-C. There are far too many resources (like questions here) in Objective-C that without this literacy these students would be at a disadvantage. They may not be able to develop in Objective-C, but they at least can read and translate it to Swift.
    – Brad Larson Mod
    Commented Feb 6, 2015 at 16:54

7 Answers 7

50

The problem here is that Objective-C is a programming language that many people confuse with the standard framework (Cocoa and Cocoa Touch depending on the target platform). The result is that many questions that really regard the frameworks are (mis)tagged when they should be tagged or .

Had they been tagged with the proper tags from the beginning, then nobody would find it strange that answers provide examples in Objective-C, Swift, Python, AppleScript, etc.

If a question is clearly about the frameworks (a tableview and its relation to the data source and delegate, for instance), then I see nothing wrong with a an answer that uses Swift (or any other language) to show how to do it - along with an explanation that the issue is about the framework and not the programming language used to access it. Let the votes determine if the answer is good.

8
  • 4
    Very good point! This confusion between Objective-C, Foundation and Cocoa has always been a problem on SO.
    – idmean
    Commented Feb 4, 2015 at 15:44
  • 3
    And someone should re-tag the question appropriately.
    – OrangeDog
    Commented Feb 4, 2015 at 16:49
  • 5
    But what if they use that tag because that is the language they are working with and want to let readers know what language to answer in?
    – Epic Byte
    Commented Feb 4, 2015 at 17:09
  • 3
    @EpicByte If it is really necessary for the OP to get an answer with example code in Objective-C, someone else can provide such an answer. Then the OP can upvote and accept it and everybody is happy. SO will even have a question with two useful answers. Of course all this requires that people can move mentally between the framework and the related APIs for different languages - and some will have to learn that.
    – Monolo
    Commented Feb 4, 2015 at 18:06
  • 4
    Absolutely agreed. The objc tag excerpt in fact includes exactly this guidance: "don't use the tag if the language isn't essential to the post or its answers", but there's too many posts; as a practical matter it's unenforceable. I do what I can when I'm around, though.
    – jscs
    Commented Feb 4, 2015 at 21:48
  • 1
    @JoshCaswell So in the case where the objc tag is not used properly, a swift answer should be acceptable?
    – Epic Byte
    Commented Feb 4, 2015 at 22:15
  • 1
    Yeah, I don't see why not, @EpicByte, though a) I'd want to see the tag removed, not just ignored, and b) that does open the door to stuff like "here's an answer in Python using PyObjC/here's an answer in RubyCocoa/here's the MonoTouch answer/here's an answer in Nu!", which seems to be sliding slowly down a gradient of helpfulness. But that's probably a bit of a stretch, and those answers will be few enough that they can be dealt with individually.
    – jscs
    Commented Feb 5, 2015 at 20:34
  • 3
    @EpicByte In the case where the objc tag is not used properly, the objc tag should be removed.
    – nhgrif
    Commented Feb 6, 2015 at 1:48
83

If the question is tagged , you should do your best to answer it in Objective-C. It's the same throughout the website; Java questions typically don't get answered in Scala.

18
  • 1
    Would you say that the reverse holds as well? What do you think of the situation that Brad linked to above?
    – jscs
    Commented Feb 3, 2015 at 19:36
  • 15
    @EpicByte: In what way is my example not precisely like Objective C and Swift? You can still use Java libraries in Scala; that's kind of the whole point.
    – Robert Harvey Mod
    Commented Feb 3, 2015 at 21:01
  • I'm arguing that answering in either Swift or Obj-C makes more sense for iOS/OS X development. It is less about the language, and more about the APIs. Also you didn't really answer the question explicitly. The question is whether Swift can be an acceptable answer. You simply said, try to write in Obj-C when the Obj-C tag is present. Are you implying that code in swift is not acceptable when the Obj-C tag is present?
    – Epic Byte
    Commented Feb 3, 2015 at 21:20
  • 3
    Perhaps the bigger question is. Should the Obj-C or Swift tag be included on a development question in the first place. Let's say the Obj-C tag was included on a question about aligning a UILabel. Does that mean all answers should be in Obj-C? And that an answer written in Swift is unacceptable? If so, does that mean a new question should be created for Swift? Should instead the question be edited to include the Swift tag? Should the Obj-C tag simply be removed from the question? These are the problems with language specific tags on general iOS/OS X development questions.
    – Epic Byte
    Commented Feb 3, 2015 at 21:35
  • 6
    ...whether Swift can be an acceptable answer -- Generally, no, unless the OP has tagged with Swift. or there are no language tags at all.
    – Robert Harvey Mod
    Commented Feb 3, 2015 at 21:55
  • 8
    Should the Obj-C or Swift tag be included on a development question in the first place. -- Yes, if you expect to get an answer involving code. In what universe do you need answers that require code in both Objective C and Swift? If you need that, then just ask for it.
    – Robert Harvey Mod
    Commented Feb 3, 2015 at 21:56
  • Questions and answers are not just for the asker, but the community as a whole. The asker might use a code tag because that is the language he/she prefers the answer in, but why should it be unacceptable for someone to also provide an answer in Swift for convenience for those using Swift? I don't think we should separate the two if the question itself is not language dependent. The way I see it, if someone is asking a iOS/OS X development question, it shouldn't matter which language I use to answer in as long as the question isn't about a specific language.
    – Epic Byte
    Commented Feb 3, 2015 at 22:35
  • 17
    Do your best to answer in Objective-C, and if you're going to provide Swift then make sure it's done in the context of "you can also do it this way using Swift", after providing the Objective-C version.
    – aroth
    Commented Feb 4, 2015 at 3:54
  • 9
    answers in any other language than the one tagged should get your answer down-voted at best and flagged not an answer or both at worst.
    – user177800
    Commented Feb 4, 2015 at 16:47
  • @aroth Maybe you should make your comment into an answer to this question. I think you have a good point.
    – Epic Byte
    Commented Feb 4, 2015 at 16:52
  • Answering on Objective-C it's the way to do it, but contributing on helping the iOS ecosystem moving forward to a new way of doing things as it's Swift should be Ok too.
    – reixa
    Commented Feb 4, 2015 at 16:57
  • 1
    No. Incorrect tag usage and incorrect answering based on the tag being used incorrectly does not a correct situation make. The tags should be fixed to reflect the asker's intent, and then the question should be answered based on the correct tag usage.
    – Robert Harvey Mod
    Commented Feb 4, 2015 at 22:28
  • 3
    Aren't you over-thinking this a bit? Just use your common sense. I personally would ask which language they want the example to be in, and then add that tag to their question.
    – Robert Harvey Mod
    Commented Feb 4, 2015 at 23:00
  • 4
    All you need to know is already in my answer.
    – Robert Harvey Mod
    Commented Feb 4, 2015 at 23:10
  • 6
    @axierjhtjz Not sure I agree. Moving the iOS ecosystem to 'a new way of doing things' is Apple's agenda, and it's not our responsibility to further it. If the ecosystem does move, it should happen organically because it's what iOS developers want to happen. And in that case the questions will naturally trend towards asking for Swift more than Objective-C, without any deliberate action on the community's part.
    – aroth
    Commented Feb 5, 2015 at 0:49
8

Below is opinion of a n00b.

Answers should, first and foremost, answer the question posed by the asker. If someone posts a question asking for help on their Objective-C code -- and you give a response of how to achieve the result in Swift then you are not answering the question asked (although your contribution may well be useful for others).

Many (most?) questions will only get a single answer. People look at questions, and if they already see an answer with up-votes (or that doesn't look like complete crap) they're less likely to post their own. If you post an answer that doesn't help the user, which is the first answer, you're almost denying that user the help they seek.

For this reason, I think that -- unless there is already a good answer for the user in the asked-about language -- you should refrain from posting an answer. You could, however, comment and ask if the asker would be able to use Swift over Objective-C.

7

The iOS / Mac framework is typically more central to the question than the specific language.

For questions that relate primarily to iOS or OS X development ("Why aren't my auto-layout constraints working?") answers that cover both languages should be acceptable because the alternative is a slew of nearly-duplicate questions that can't get marked as duplicates.

For example, rather than posting a separate Swift question to "Adjusting letter spacing in iOS 7", I added a Swift example to my existing answer.

For questions actually about the language ("What's a tuple?"), only answers about that language are acceptable.

1
3

I think that most would agree that ideal answer should be in the tagged language or, failing that, the language used or specified in the question. I believe community members should endeavour to first provide such an answer if they can do so. This seems an uncontentious assertion.

In order to determine the appropriateness of an answer in an untagged language, whether in place of or in addition to one in the tagged language, consideration must be given to the context in which the language tag is being employed. The best way to make this determination is to consider the question not from the perspective of the one answering, nor from the perspective of community moderation, but from the perspectives of both the questioner and the broader community.

As someone asking a question, I may apply a number of tags to a question. To supply a real example, I recently asked a question about difficulties with [OpenGL ES2.0] [shaders] on [Android] using [OpenTK]. I specified the language as [C#] because that was the language in which I was working, the language of the code I supplied, and the language in which I would need to implement a solution. However, I would very much prefer an answer in an incorrect language to no answer whatsoever. It is probable that I could decipher an answer in another language which may address the core of the issue. Failing that, an answer in another language may be translated by another community member.

In this example, the question primarily focuses on problems which are not language-specific, and multiple other tags are provided. It seems reasonable to provide an answer that checks 4/5 boxes in the absence of one that checks all five. Obviously discretion is required when determining whether the question demands a language-specific answer, and the clue is often in the accompanying tags.

From the perspective of the broader community, answering questions in an untagged language adds to the value of the question. Such answers provide solutions for others with similar problems in other languages, and provide a framework off which language-specific answers can be built. I think it may be unreasonable to expect an answer in the wrong language to be expected, even if it is highly insightful. However, I think it would be foolish to deem it universally unacceptable.

2

It depends.

For new questions, I think it's best to go with whatever is tagged. If it's a Swift question about an iOS concept that has already been covered in Objective-C in another question, it's probably best to close it as a duplicate of that question, as conversion in most cases is fairly straightforward (if we're going by the same principle that we're here to help as many people as possible rather than just the one asking the question), but it wouldn't hurt to add a Swift version on that question if appropriate.

I have come across a few old Objective-C questions that I felt I could answer since the introduction of Swift, so for those I prefer a dual approach; why not just give both if you have the time and the ability to do so?

I honestly don't think it's a problem to answer old questions with only Swift (if you must), but answering new Objective-C questions with Swift should probably be avoided, as that particular asker is making a conscious decision of which language s/he would like to use, and not all askers know both languages (contradictory point to what I said about the conversion, I know, but I don't think duplicating questions based around the same concept that was covered with Obj-C in Swift is a good idea).

From what I've found during my brief travels in iOS development is that it is heavily conceptual, and the language that you decide to use is often unimportant compared to the other things you have to worry about (interface design, licensing, distribution, etc.) and is often just the tool you decide to use. However, I think we owe it to the asker to respect the tool s/he has chosen.

-3

Some companies see Swift as unproven as of yet, and they aren't adopting it quite yet. I don't think this should keep you from posting an answer in Swift, though - it will be helpful for future people finding the question on Google that do use Swift.

Of course, you can't expect that your Swift answer on an Objective-C question will be accepted, and it will probably be downvoted. In principle, though, I don't see anything wrong with posting Swift answers to Obj-C questions.

2
  • 5
    What about companies that have reviewed Swift, concluded that for all the hype it's not actually worth adopting, and have decided to stick with Objective-C? Do they get thrown under the bus for having a different opinion and different requirements?
    – aroth
    Commented Feb 4, 2015 at 3:52
  • 6
    @aroth No, but if someone wishes to contribute an answer and wants to do it in Swift, there is nothing keeping that company from translating it. Of course, if the question is of any significance there will probably be someone else that posts an answer in Obj-C. I don't see a reason to reject Swift contributions just because some people don't use it.
    – Undo Mod
    Commented Feb 4, 2015 at 3:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .