Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Axiem posted:

Is Swift going to be supporting unit testing and the like? My workplace is thoroughly in the TDD camp (as am I), and having a language that really supports it would be fantastic.

XCTest has basic support for Swift, including the new testing features announced today. If there's anything specific you'd like to see in the Swift testing experience we'd love to hear your thoughts on it.

Adbot
ADBOT LOVES YOU

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

rjmccall posted:

Also I feel very slightly bad for randomly making fun of Ada. Only very slightly, though.

I'm sure Ada can handle it. It has features for everything else.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Ender.uNF posted:

I am not advocating for exceptions, just dealing with the fact that they exist and will be thrown if you're using CoreData.

Core Data really shouldn't be throwing an exception for anything that isn't programmer error; if it is, report it as a bug and send me the bug number for followup if you can.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Doctor w-rw-rw- posted:

If programmer error will happen, then it follows that exceptions will happen. I think it was implicit in his statement that if you're using Core Data, you're probably going to misuse it at some point and trigger an exception.

I mean programmer error in the Cocoa sense; Cocoa exceptions aren't meant to be caught by an app and recovered from, they're meant to be caught by a debugger and prevented.

In other words, "Core Data throws this exception I can't catch in Swift and there's nothing my code can do to prevent it" is properly solved by fixing Core Data not to throw an exception, rather than by letting your app continue with potentially corrupt state.

Of course, if it's because of something an app did (like trying to fire a fault for a deleted object) the solution is to not get into that situation in the first place.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Ender.uNF posted:

edit: Anyone have success creating a framework and using unit tests written in Swift? I haven't done anything special whatsoever and my first attempt to run a test fails:

Doesn't seem to make any sense, both the framework and the test project are set to compile for x86_64.

The issue with this is that the Swift standard library isn't copied into the framework or the test bundle like it is for apps. You may be able to manually copy them into your test bundle so they're available when tests are run.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

ljw1004 posted:

I'm struggling to make sense of named parameters. The online docs (and also the book, page 208) give this example code:

https://developer.apple.com/library...97-CH10-XID_213

code:

func halfOpenRangeLength(start: Int, end: Int) -> Int {
    return end - start
}
println(halfOpenRangeLength(1, 10))
// prints "9"

When I type it in, it gives an error saying that my call site failed to specify the name of the second argument, and suggests the fix of invoking "halfOpenRangeLength(1, end: 10)"

Did you add this as a free function or as a method within a class? Free functions omit all parameter names by default, while methods within a class omit only the first parameter name.

This is effectively like ObjC where a free function is just a C function, and a method in a class always has its name interspersed with the parameters.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Dessert Rose posted:

I keep banging my head into this Xcode bug where suddenly it will decide that my target might include its own product for every project I build. Even ones which previously built fine.

Is there at least a reliable workaround? I hit it again and I don't remember what I did to fix it last time.

Do you have something like your app's Info.plist also included in a Copy Bundle Resources build phase? That's often the culprit, typically the result of clicking the "please make this a member of my target" checkbox.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Ender.uNF posted:

And here is my SwiftNonStandardLibrary, featuring the missing readln(), extensions to SequenceOf<T>, exception handling, and some other goodies.

Where's the code?

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Choadmaster posted:

2) I know this bug is already filed, and the Swift team does not use dupes as a priority hint (understandable at this stage, as they presumably have a detailed roadmap for what needs to be completed already).

I think that was referring to filing intentional duplicates to try to inflate priority, like "this bug is a duplicate of 12345, here's some text copied and pasted from a web site, I vote for this feature too!"

If you are yourself running into a bug or other difficulty, you should always file it, and not worry about whether what you're filing is a dup of something else. (Only don't if you know your exact issue is already known and you've been asked not to—like, say, for access control in Swift.)

Also, don't get caught up spending hours putting together a bug report, a couple sentences is fine if that's all you actually need to specifically describe the issue. If an engineering team needs more detail they'll ask. And push back if a bug comes back to you as fixed but from your perspective it's not.

Finally, if you would like to see a feature/enhancement/change, you should also always file it yourself, and explain your needs clearly; they may not be addressed the way you requested, but they will be taken into account. (This is the reason "why" matters, not just "what.") An example of that from early OS X history was when some developers asked for the Enterprise Objects Framework to be brought forward; what they got was Core Data instead, as a model-level persistence framework for Cocoa.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

PleasureKevin posted:

two things I could do in PHP that I guess I can't in swift?

1 . omit curly braces if i'm just doing one line below an if statement

Correct, you can't omit braces, and this is a feature.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Doh004 posted:

I do iOS development for my job and I figured I should start learning how to use Swift, so I made TicTacToe. If anyone is bored could you please give me some pointers? I definitely found myself doing a lot of stuff incorrectly because I'm so used to Obj-C so I know I didn't do things in the proper "Swift" way (if that even exists?).

https://github.com/BayPhillips/TicTacToe

Thank you!

Where are your tests? :colbert:

You should follow similar naming conventions to Objective-C with Swift, i.e. start properties and method names with a lower-case letter, make the name of a method read as a sentence, etc.

For example, this:

code:

    func PlayersCornerPieces(player: Player) -> [GamePiece]

should be more like this:

code:

    func cornerPiecesForPlayer(player: Player) -> [GamePiece]

similar to how it would be in Objective-C.

The separate model classes should also be in separate files, rather than all in one, for stylistic reasons. More practically they have methods that should really be properties, even computed properties like Player.displayName (for which I did like your use of interpolation, that's what I'd have done too). Also, the type for something like that can be just String, not String!, since you probably don't need to introduce an implicitly unwrapped optional for something like that.

eschaton fucked around with this message at 05:09 on Sep 22, 2014

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

fleshweasel posted:

They implemented monads with the stupid operators because they thought it was too easy to tell what was going on.

They should've added a native concept of combining diacritics to the language to represent the functional concept of composition.

e: good luck distinguishing ± from + combined with an underbar diacritic!

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Ender.uNF posted:

swiftc is written in C++... is there any reason that it doesn't catch exceptions and bail on processing a section of code (or a file) if it blows up?

I think here you're conflating two different kinds of exceptions: language-level exceptions, and OS/system-level exceptions (traps, signals, whatever you'd like to call them).

You can use signal() handlers and Mach exception handlers to try to capture OS-level exceptions, but your recovery options are limited except for very specialized software (like debuggers).

Language-level exceptions tend to be designed for recoverability, though in practice most such exceptions should also wind up aborting the process because most software isn't itself designed for recovery.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Axiem posted:

Forgive my ignorance, but what does putting "import Foundation" or "import UIKit" at the top of a given Swift file inside a project actually do? I understand that in say, C, you provide header files in #import statements in order to let the linker do its job, but that was at a per-file level, not a per-module level.

Header files in C-family languages aren't for the linker, they're for the compiler: In order to use functions or variables the compiler needs to see declarations for them, so it knows how to generate code to access them. This is done via direct text inclusion, which has its pluses and minuses. And it's the generated code (along with a list of libraries to look in for external definitions) that gets fed to the linker, not the headers.

With Swift you can effectively treat module imports as the same sort of thing, just fancier. The compiler is basically doing the equivalent of precompiled prefix headers for you behind the scenes, because it doesn't have to worry about the language semantics specifying that literal text inclusion happens. (This also applies to @import in Objective-C.)

quote:

Following up on that, is there any compelling reason not to be able to say "just consider every file in this project to `import Foundation`"? It just seems odd to me that for Foundation, UIKit, or even any module that touches much of my code, I have to clearly define that I'm importing it.

I guess what I'm saying is, is there a compelling reason not to have a Swift version of Prefix.pch to do this for us?

It helps the modularity of your code to be explicit about what it's using. As an example, if a class doesn't truly depend on anything from UIKit, it shouldn't import UIKit, and that means it'll be portable to OS X too.

As an example, a couple years back I experimentally extracted an Awful.framework from Awful.app that would work on OS X. 99% of it didn't need UIKit and came right over, so it should have all just imported Foundation. (The only thing that didn't was something that triggered the network activity indicator, which was easily just abstracted behind a delegate.)

In general, you'll find that lots of oldschool NeXT developers treat development as an exercise in putting together a bunch of frameworks that then get composed into one or more apps. Part of doing this is clearly defining the boundaries between the different parts of your app, which includes considering their dependencies.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

fleshweasel posted:

code:

if let regex = NSRegularExpression(pattern: "\\d\\d",
    options: NSRegularExpressionOptions.allZeros, error: errorPtr) {
        if (errorPtr != nil) {

You shouldn't be checking errorPtr here, as with everything that deals with NSError you'll only get one back if the init fails and that's what you need to check for in Swift pre-2.0 or ObjC. (I can't tell you how many times I've seen [managedObjectContext save:&error]; if (error) { ... }, whoever told people they should do that is wrong wrong wrong.)

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Kallikrates posted:

Okay I wrote that before coffee, I've run across methods that accept an error pointer, and return void. Or maybe I am mis remembering but I remember hitting something from some big Framework that was essentially: -(void)foo:(NSError **)error;

None that I’ve seen in the Cocoa APIs are like that. It wouldn’t surprise me though if there were some developers who misunderstood the conventions and made frameworks like that.

There are places in Cocoa where an error itself is passed as a parameter, and nil is used to indicate “no error.” But that's different then checking whether an error out-parameter was set.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Gul Banana posted:

tbh it's just kind of hard to take the 'catastrophe' pov seriously having spent years programming in each of cocoa, java and .net. they're directly comparable stacks

Remember that Java's core libraries and even language features were based in significant part on the original NeXT AppKit design by Bill Parkhurst, the NeXT/Sun OpenStep API effort, and Objective-C. Then IFC (which was the basis for the Java 2 work) was specifically designed to mimic the NeXT APIs as well.

And then Microsoft's Anders Heljsberg based C# and .NET on Java 1.x, while a certain Bill Parkhurst was one of the people behind the Visual Studio IDE.

And the design of the original AppKit is traceable to MacApp, which is in turn traceable to the Lisa Application ToolKit. Both of which were implemented in Object Pascal, which Apple had hired Niklaus Wirth to help design, and which Borland and a certain Anders Heljsberg continued to promote and enhance long after Apple had switched to C++.

There are very good historical reasons the frameworks and languages all feel similar. They're related kind of like English, Dutch, and German. There are other languages and frameworks out there that are a bit more different, and not just "research" ones either. (Though many have been consigned to the dustbin of history…)

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
If you want to see what NeXT AppKit development was like pre-OpenStep, someone has an online collection of the Nextstep 3.3 documentation which includes such APIs as -[View drawSelf::] and -[View display:::].

Yes, that's two and three colons, respectively.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

emoji posted:

Whatever it is, Xcode crashes very hard at the moment I attempt to package.loadlib using the raw symbol, tho not reliably.

That's LLDB being killed because it's trying to read memory it's not allowed to for code signing reasons, or something along those lines. Please file a bug.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

PT6A posted:

I mean, what fills up the students' time if they aren't teaching algorithm analysis and design in CS? I'd be hard pressed to come up with 50-60 credits of CS-relevant material without touching on those subjects.

These type of degree programs often feature classes in various technologies instead. So you get classes on Java, .NET, C++, HTML and CSS "programming," game development, "apps," and so on.

An IT degree at a good school is more of a CS degree than the above, but the above is what some schools offer as one. And neither is likely to know the joy of a real 18-unit Operating Systems class…

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Siguy posted:

That pipermail interface is barely an interface. I feel like the Swift guys are intentionally clinging to the mailing list as a method of weeding out contributors. If you want to participate, you have to put up with a pretty arcane communication system.

There's nothing arcane about using mailing lists for high volume discussion. They work extremely well for it and have for decades.

Web forums are seriously poo poo, second in shiftiness only to web "chat" systems.

If you want a fuller-featured archive interface for a list you can always build one, grab the mbox files for the archives, and put it up.

quote:

As a lurker curious about the language but not dedicated enough to read through a daily email log, I mostly get by with Erica Sadun's recaps.

What does "a daily email log" even mean, a digest subscription? Just subscribe to the list and have your mail client (or server) filter it into a folder, then read it when you have time. Done.

quote:

If I want to find an actual post, the only not totally lovely solution I've found is to use Gmane's still operational NNTP server and browse with a newsreader: nntps://news.gmane.org/

You have discovered one of the other ways to deal with online discussion better than a web site. Web sites are fine for presenting archival information, for interaction that's why we have—and have had—apps.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
At least it's not a web forum.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
In case you missed it, Chris is a guest on the Accidental Tech Podcast and he talks about all sorts of stuff.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
While I'm a very strident advocate of files as primary source artifacts (for tool generality), imbuing the files themselves with meaning rather than their pure content seems like the wrong direction to go.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Huckleduck posted:

Quick question about using Swift as a script. I made an XCode project file with the Swift Package Manager. The purpose of the script is to contact a server and download some files, then write those files to disk. This is an async operation, but scripts end whenever they let go of the main thread. I've tried three things, one of which worked.

1. I tried to make a Dispatch Semaphor (a counting one, value of 0) and iterated it in the completion block of my async call in the script. This did not work, somehow the completion block never came back.
2. I tried using Dispatch Group. I made a group, entered the group, all the usual jazz, left the group in the completion block of the script and made a dispatch wait with a timeout. The timeout always gets hit, the completion group never comes back.
3. I made a property called "isDone" outside the function, setting it to false. Inside the async function's completion block I set it to true. Then, I grabbed the current runloop, then made an autorelease pool. In the autorelease pool I have a while loop that does nothing, but it does hold onto the main thread until isDone is true. This actually works. :how:

I realize that #3 here is jank, and in my defense I did #1 and #2 first - I have worked with GCD and am 95% sure I have all the elements in place. Is it not working because of the weirdness of running this script through Terminal?

For a classic command line tool with a main run loop, you'd run it repeatedly until the work is done, which would likely be signaled by a variable being set (in a thread-safe manner) by whatever the worker is, and then stopping the main run loop. The main run loop would check the variable (also in a thread-safe manner, of course) and then when it's set decide to stop running. Note that you can't rely on a run loop to stop on its own; the frameworks can add their own sources too, after all.

I strongly suspect that whatever mechanism you used to do the download relied on having the main run loop turning, in which case the above sounds like what you should do too. Your #3 is very close to it, you just need to set the Boolean safely, check it safely, actually run the main run loop, and explicitly stop the main run loop after setting the Boolean. This should all also be easy to encapsulate.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Kallikrates posted:

Playgrounds haven't had inline errors for me for several releases. The code/run/output cycle isn't any faster these days than running an app/tests. Maybe I need to nuke my Xcode.

Reinstalling Xcode is virtually never going to help anything. (Same with reinstalling the operating system.)

Why is it even on peoples' list of things to try? You'd be better off trying the same thing under a brand new user account, in case there's some cached state interfering.

Adbot
ADBOT LOVES YOU

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
That's more of a UIKit framework question than a Swift language or tooling question, you might get more assistance in the Apple platform thread.

  • Locked thread