Live data from Hacker News

Apple Developer Documentation Is Missing

v4.chriskrycho.com

111–120 of 400 posts

Re: Apple Developer Documentation Is Missing

#111
post #74

Earlier quoted context omitted.

What is a "cascaded nil-coalescing operator" ?

Think the ternary operator, but worse. In Swift, this is expressed by "??". It means "If the previous test returns nil, then execute what is after the ??". For example, if you have a concrete Int, but the source might be an optional, then you could do something like this: let a = b ?? 0 That means that if b is nil, then set a to 0. Otherwise, set it to whatever value b has. You can chain these, like so: let b: Int? =…

"Think the ternary operator, but worse"

Giving the developer succinct ways to prevent program failure from unexpectedly undefined values is a feature.

Re: Apple Developer Documentation Is Missing

#112

Earlier quoted context omitted.

Think the ternary operator, but worse. In Swift, this is expressed by "??". It means "If the previous test returns nil, then execute what is after the ??". For example, if you have a concrete Int, but the source might be an optional, then you could do something like this: let a = b ?? 0 That means that if b is nil, then set a to 0. Otherwise, set it to whatever value b has. You can chain these, like so: let b: Int? =…

In Objective-C (and some other languages with ternary operators) the same can be written like this: int a = b ?: c ?: 0

Yup.

Personally, I like the ternary operator, and I also like the nil-coalescing operator, but I'm quite aware that they can produce difficult-to-maintain code, so I'm careful with them. I have gone and done some silly stuff with both, but then, I realized that I was leaving unmaintainable code.

If you use godbolt.org, you can actually see what code is produced by the source.

Re: Apple Developer Documentation Is Missing

#113
post #104

Some time ago, I was contacted by Apple to apply for a job. My code is insanely well-documented. I like to think that a lot of the inspiration for my code docs comes from Apple's open codebases. Their code is exceptionally well-documented. In any case, as is usual with all employers, these days, they completely ignored the focused, relevant links that I sent them to elements of my extensive portfolio of repos, and, i…

To be honest, while documentation is extremely important in the real world, interviews are time-constrained, and it makes no sense to write documentation when you have 45 minutes to implement something like that.

I'm not defending those types of interviews, because I'm not great at them, but it seems that they're looking for human algorithm machines. People who can go in and write very specific performant code. Maybe that's the requirement for the job as opposed to someone who can interface with businesses and do general enterprise software.

Re: Apple Developer Documentation Is Missing

#114
post #74

Some time ago, I was contacted by Apple to apply for a job. My code is insanely well-documented. I like to think that a lot of the inspiration for my code docs comes from Apple's open codebases. Their code is exceptionally well-documented. In any case, as is usual with all employers, these days, they completely ignored the focused, relevant links that I sent them to elements of my extensive portfolio of repos, and, i…

What is a "cascaded nil-coalescing operator" ?

Apparently it functions a bit similar to the javascript || assignment.

https://stackoverflow.com/questions/2100758/javascript-or-va...

Re: Apple Developer Documentation Is Missing

#115
post #74

Earlier quoted context omitted.

What is a "cascaded nil-coalescing operator" ?

Think the ternary operator, but worse. In Swift, this is expressed by "??". It means "If the previous test returns nil, then execute what is after the ??". For example, if you have a concrete Int, but the source might be an optional, then you could do something like this: let a = b ?? 0 That means that if b is nil, then set a to 0. Otherwise, set it to whatever value b has. You can chain these, like so: let b: Int? =…

... and this is so wonderful! It's in no way worse than the ternary operator. You punt to a default value really easily, without having 20 lines of `if (a.this == null) a.this == 0; if(a.that == null)a.that == ""` or similar.

When constructing objects "in-line" in c# I actually used to see the ternary operator quite a lot, as in

  new SomeClass() {
    Val = valSource == null? SomeClass.DefaultVal : valSource
  }
The coalesce operator is way better. Except it can't be used in LINQ projections.

Re: Apple Developer Documentation Is Missing

#116
post #104

Some time ago, I was contacted by Apple to apply for a job. My code is insanely well-documented. I like to think that a lot of the inspiration for my code docs comes from Apple's open codebases. Their code is exceptionally well-documented. In any case, as is usual with all employers, these days, they completely ignored the focused, relevant links that I sent them to elements of my extensive portfolio of repos, and, i…

To be honest, while documentation is extremely important in the real world, interviews are time-constrained, and it makes no sense to write documentation when you have 45 minutes to implement something like that.

I have personally found that sometimes writing out comments that explain how a confusing function is going to work will help me to understand the ins and outs and flow of the function before writing it, which will in turn help me to actually write the function, especially with algorithmic functions. Those comments might as well be written as long-standing documentation that doesn't change as long as the implementation/algorithm doesn't change. I know "comments lie" but if it's a long-lived implementation, it's more beneficial than not.

Re: Apple Developer Documentation Is Missing

#117
Nowhere in the comments thus far has anyone pointed out that SwiftUI — the framework in TFA's crosshairs — is in beta. I've written a relatively large amount of SwiftUI code and I get the impression that the design is still in flux. There are corner cases (as well as much more mainstream one) that haven't been fully thought through. Beta 5 of Xcode 11 brought non-trivial changes to the API and I expect those to continue.

"It's not finished until it's documented" is a fine sentiment, but I don't think Apple has remotely claimed that SwiftUI is finished.

Re: Apple Developer Documentation Is Missing

#118

It's always been bad, too! Back in the OS9 days, the Apple documentation was "cumulative". You had to know every trick, every hidden bit and flag, back to day 1 in order to write a program. It's no better today. People who live isolated in the Mac universe have no idea how good Microsoft Visual Studio tools are, and how complete and thorough the documentation is, and how consistent the API is. You don't have to wade…

Woz documented every line of his Apple ][ system monitor code and it was a joy to read.

Re: Apple Developer Documentation Is Missing

#119
post #104

Some time ago, I was contacted by Apple to apply for a job. My code is insanely well-documented. I like to think that a lot of the inspiration for my code docs comes from Apple's open codebases. Their code is exceptionally well-documented. In any case, as is usual with all employers, these days, they completely ignored the focused, relevant links that I sent them to elements of my extensive portfolio of repos, and, i…

To be honest, while documentation is extremely important in the real world, interviews are time-constrained, and it makes no sense to write documentation when you have 45 minutes to implement something like that.

I disagree. It's one way for the interviewee to reiterate back to the interviewer that they understand the problem and constraints.

Re: Apple Developer Documentation Is Missing

#120
post #111

Earlier quoted context omitted.

Think the ternary operator, but worse. In Swift, this is expressed by "??". It means "If the previous test returns nil, then execute what is after the ??". For example, if you have a concrete Int, but the source might be an optional, then you could do something like this: let a = b ?? 0 That means that if b is nil, then set a to 0. Otherwise, set it to whatever value b has. You can chain these, like so: let b: Int? =…

"Think the ternary operator, but worse" Giving the developer succinct ways to prevent program failure from unexpectedly undefined values is a feature.

"Giving the developer succinct ways to prevent program failure from unexpectedly undefined values is a feature."

Most languages have had this since the 1960s.

It's called the "if" clause.

The ternary and nil-coalescing operators are shorthand (sugar) for an if test (or guard, in Swift).

Like I said, I actually like them, but I have to be careful, when using them.

I really like Swift, but it's quite possible to write completely inscrutable code in it.

Post reply on HN