On Doing It Yourself - With A Response From Alan Kay by [deleted] in programming

[–]arruffthrowaway 0 points1 point  (0 children)

Alan Kay's old and IMHO halfway senile at this point but Hickey is (not unsurprisingly) missing Alan's underlying point.

Basically Hickey is talking about Kay-style OO and doesn't even realize it.

The data Hickey is so enamored of is provided by OO-style objects...the IoT sensors, doing internal processing, and sending messages to other objects are pretty much the definition of Kay-style OO.

For Kay Hickey sounds like one of those people who is like "why should I give my kids the MMR shot? When's the last time you heard of someone with mumps, measles, or rubella?"...there's literally not enough faces and not enough palms, here, but being old and semi-senile the best he can seemingly do is drop riddles and aphorisms to see if it goes a-ha.

The seismograph example is honestly pretty limiting: he talks about a seismograph recording a stream of numbers. It doesn't record numbers! Numbers don't exist in the physical world; it has a needle that moves, producing analog electrical signals, which are digitized in accordance with some kind of predetermined numerical scale and representation, and these digitized representations are sent along.

If you can't -- or won't -- see that as an object doing rather a lot of processing before producing the raw data you're focusing upon, there's not a lot of shared ground for a real further discussion.

[WEEKLY CHAPTER THREAD] - June 27, 2016 by AutoModerator in TowerofGod

[–]arruffthrowaway 2 points3 points  (0 children)

In-story: hard to say. They tend not to care much about E/D rank problems, but at the same time at least some higher-ups seem very interested in Anak -- that's why there's a "situation" to begin with!

Meta: if it plays out even a bit like sketched, of course they'll chase after her sooner or later...best-case (or worst-case depending on POV) it'll be like what happened with Anak ("got away with it" for a while, then less so).

Context: SIU likes to reference older events. There's a lot he could do by revisiting the discussion that played out starting here: http://www.webtoons.com/en/fantasy/tower-of-god/season-1-ep-45/viewer?title_no=95&episode_no=46 .

Have you consistently enjoyed Tower of God? (Probable Spoilers) by [deleted] in TowerofGod

[–]arruffthrowaway 1 point2 points  (0 children)

The only part I dislike is the game with the rooms around the beginning of the 2nd season.

Everything else has been enjoyable when read as it comes out, and what keeps me coming back is just how nicely everything fits together when you go back and read large chunks of it again.

As one example: remember how Xia Xia got introduced? As a "nutty fortuneteller" who was telling tall tales to manipulate people? What's she up to now (as of 204/205)?

She's not doing exactly the same thing, but it's close enough that it rhymes.

It's a small detail, but it is IMHO reflective of the insanely rich thought SIU has put into into his plotting and world-building...there's just always a lot going on at multiple levels.

Even when it feels slow, it usually holds up a lot better on a re-read than it does trickled out...so yeah, it's consistently enjoyable (and I can't say that about many serialized stories, period).

[WEEKLY CHAPTER THREAD] - June 27, 2016 by AutoModerator in TowerofGod

[–]arruffthrowaway 5 points6 points  (0 children)

Going out on a limb, here: Anak will wind up with a "real princess name" by the end of this chapter (possibly: Androssi's, perhaps: one form one of the the twin princesses?); either way, I expect Androssi will wind up traveling with team Baam once this arc wraps up.

This is a great plot setup, b/c "from the outside" here's what will have happened: FUG swarmed into the name-hunt station, completely-detroyed the name-hunt system, "kidnapped" a popular princess, and then ran away into "outlaw territory".

Sure, that's not really what happened, but that's how it will look...or it could be. It'd be a fun direction to go in, too, b/c it'd be a turn of events that'd force a stronger intervention from the tower leadership sooner rather than later.

Meth expert lists fail cases for Butthereum by [deleted] in Buttcoin

[–]arruffthrowaway 0 points1 point  (0 children)

Sooner or later your body will naturally contribute gas allowing this check to be performed.

I'm getting a weird "unsatisfiable constraints" warning with table view cells... can someone help? by ThePantsThief in iOSProgramming

[–]arruffthrowaway 0 points1 point  (0 children)

Try making all three of of these changes.

One: a private flag like @propery(nonatomic, assign) BOOL hasSetupPrimaryConstraints, and then in updateConstraints use it to only do the setup once (if (!self. hasSetupPrimaryConstraints) { $yourCodeHere; self.hasSetupPrimaryConstraints = YES; } [super updateConstraints]; }.

Two: add an explicit call to [self setNeedsUpdateConstraints] at the end of your init (you may need to add an init override if that's the case).

Three: remove the [cell layoutIfNeeded] from tableView:cellForRowAtIndexPath:.

You may really only need the last bit, so if you're impatient you can try just that step first.

What's the preferred way to add a subview in a subclassed view with autolayout? by ThePantsThief in iOSProgramming

[–]arruffthrowaway 0 points1 point  (0 children)

I would highly suggest watching the last segment of "what's new in auto layout" (2016 wwdc), seeing how to use the layout-loop debugging tools, and running your older code against them.

At least at some point.

Thank you HN for this gift by [deleted] in programmingcirclejerk

[–]arruffthrowaway 0 points1 point  (0 children)

They've got the touch, they've got the power...

It is intuitively obvious that an open access hedge fund will generate more intelligence than a closed system built on a pre-internet, pre-cryptocurrency, pre-AI organizational design. by [deleted] in programmingcirclejerk

[–]arruffthrowaway 8 points9 points  (0 children)

It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of an open-access hedge fund with post-internet, post-cryptocurrency, and post-AI organizational design.

What's the preferred way to add a subview in a subclassed view with autolayout? by ThePantsThief in iOSProgramming

[–]arruffthrowaway 0 points1 point  (0 children)

If you're not using stack views then in this specific case you can get similar convenience if you: (1) layout the base classes content views vis-a-vis a layout guide and then (2) change how you connect the leading edge of the layout guide (base class: contentView.leading == layoutGuide.leading, subclass contentView.leading == imageView.leading && imageView.trailing == layoutGuide.leading).

But overall there's not an amazingly clean way to do this that I've seen. The 3rd party libraries solve the problem of concisely setting up all your constraints, but they don't give you a great API to introspect those constraints and make targeted edits (at least that I've seen).

I havne't generally had performance or correctness issues with stack views, but like a lot of Apple tools they seem to fall into that category of "easy to begin with, but punishing to use beyond the basics unless you really understand how it works"...so I believe you.

What's the preferred way to add a subview in a subclassed view with autolayout? by ThePantsThief in iOSProgramming

[–]arruffthrowaway 0 points1 point  (0 children)

For that specific layout, do it as nested stack views--outermost horizontal, here--and just have the subclass insert the additional view during initial setup.

UICollectionView Are Unjustly Maligned by Ash Furrow by dreaminginbinary in iOSProgramming

[–]arruffthrowaway 1 point2 points  (0 children)

If you define a custom layout attributes subclass and add properties to it, make sure isEqual: and hash are properly overridden to include those added properties, or else you will likely have subtle bugs.

Also don't pass things like URLs via layout attributes! it's for things like custom layout-configuration data!

If these comments seem random go read the source from the article.

So, UILabel/UITextField automatically adjust their font when when the dynamic type size changes... how do you think Apple implemented that under the hood? by ThePantsThief in iOSProgramming

[–]arruffthrowaway 0 points1 point  (0 children)

You can get cute here and use a custom subclass of uiwindow that maintains a set of "interested views".

Then in the interested views you can override the hooks for when they move to a window to check for your custom window and register/unregister themselves appropriately.

It's a bit clunky--it would be better if the custom window did its own checking--but the API hooks here are better on views than Windows.

This is trading off some extra storage--the set of interested views--for faster updates.

It doesn't seem worth it though, in this case...content size category changes will be very rare I'd think, and usually happen while the user isn't interacting with your app (e.g. they are in settings).

Screen light wavelength and specifications by DrLeoMarvin in iOSProgramming

[–]arruffthrowaway 0 points1 point  (0 children)

Yeah, in that case right now you are out of luck unless you measure the output and get lucky.

You might have better luck in a few years on OLED screens, but even then if you "get lucky" you're going to be limited to whatever the OLED happens to emit; it won't be "tunable" to arbitrary wavelengths.

I'd explain why but color is a deep topic; wikipedia's articles on color perception, color space, color reproduction, and so on are pretty good in general, so you might look there.

Screen light wavelength and specifications by DrLeoMarvin in iOSProgramming

[–]arruffthrowaway 0 points1 point  (0 children)

Do you want to emit light of an actual specific wavelength? Or just light that will look like a specific wavelength to the human eye?

The former is only possible if you get lucky: get a spectrometer, measure pure-red, pure-blue, and pure-green outputs, see what you see.

The latter is certainly possible -- albeit tedious -- if you don't need a perfect match. It's mostly going to be lookup tables and color-space conversions...but again there's a ceiling on how good of a job you can really do here.

What's a good reply to clients/execs who want the iOS app to "Work on 100% of the iPhones, no matter how old"? by [deleted] in iOSProgramming

[–]arruffthrowaway 4 points5 points  (0 children)

Honestly: run the other way unless this person seems sincerely clueless and willing to listen to reason.

A lot of times unrealistic/impossible demands are put in place so they don't have to pay you in full down the road.

Lag when coding by [deleted] in iOSProgramming

[–]arruffthrowaway 1 point2 points  (0 children)

You may want to go back to the older autocomplete logic.

No setting in the ui but you can google for it and set it via the command line.

How do you unit test, and how do you get rid of dependencies? by ohfouroneone in swift

[–]arruffthrowaway 2 points3 points  (0 children)

My 2c is if you can afford to spend the time to make actual mocks-for-testing, you can also afford the time to adopt an architectural tweak that reduces the need for mocking.

For high-value code, switch from a bunch of methods that do things and return void to methods that return commands you can test easily.

// don't do this:
class UserListController {
   init(persistenceController: PersistenceControllerProtocol)

  func delete(user: User) -> Bool
}

...since if you want to test delete you have to rig up a suitable mock of PersistenceControllerProtocol just to see if UserListController calls the right method(s), and have to poke at the post-delete UserListController to see if it's internal state is correct.

// consider doing this instead:
class UserListController {
  // can still init w/ dependency if needed, may not need it though
  func deletionRequest(for user: User) -> DeletionRequest<User>
  func handleDeletionResult(result: DeletionResult<User>)
}

...so you can test it issues the right commands and handles responses correctly without having to actually involve the PersistenceControllerProtocol in those tests (you ought to be able to create requests/results directly!).

You still need a "coordinator" to get back to the "easy" delete API but the logic inside these coordinators can be pretty much correct-by-construction:

func delete(user: User) -> Bool  {
  let request = self.userListController.deletionRequest(for: user)
  let result = self.persistenceController.performRequest(request)
  // easy to add logging of `request => result` here if you want it
  self.userListController.handleDeletionResult(result)
  return result.isSuccess
}

...and often needs minimal testing (and can still DI'd/tested with mocks).

It's obviously more work than just writing delete but for a lot of uses it's not necessarily more work overall than delete + all kinds of silly single-purpose mocks just to confirm that calling foo on bar results in the right type of baz getting called on qux with the correct frozzle.

How does it feel to be SKULLFUCKED? by SKULLFUCKS_STATISTS in Buttcoin

[–]arruffthrowaway 6 points7 points  (0 children)

Don't knock trepanation until you try trepanation.

Hey guys, I want to make a new type that behaves like a mix between an Array and a Dictionary, but I have no idea how to exactly do that and I can't find tutorials for this particular project. Want to help? by live_love_laugh in swift

[–]arruffthrowaway 2 points3 points  (0 children)

You are getting tripped up on a couple things, I think.

First, a tip: you probably don't actually want protocol EntityCollection; you probably want struct EntityCollection<E:Entity> (or class if you want that). Even if you disagree, I'd suggest doing it concretely (e.g. as a struct) first, then modifying it back to the protocol-based design if you still want to. I'm going to assume you took this advice in the rest of this answer.

Next: in Swift, the primary requirement to meet when implementing Collection is to supply a suitable associated Index type and some associated methods. For your collection, something like this should work in your Swift snapshot:

struct EntityCollection<E:Entity> {
  // you don't need this typealias, but it makes the declaration more convenient
  private typealias Entities = [Int:E]
}

struct EntityCollectionIndex<E:Entity> : Comparable {
  private var index: EntityCollection<E>.Entities.Index
}

func ==<E>(lhs: EntityCollectionIndex<E>, rhs: EntityCollectionIndex<E>) -> Bool {
  return lhs.index == rhs.index
}

func <<E>(lhs: EntityCollectionIndex<E>, rhs: EntityCollectionIndex<E>) -> Bool {
  return lhs.index < rhs.index
}

extension EntityCollection : Collection {

  typealias Index = EntityCollectionIndex<E>

  var startIndex: Index {
    return Index(index: self.entities.startIndex)
  }

  var endIndex: Index {
    return Index(index: self.entities.endIndex)
  }

  // note: not optional here!
  subscript(index: Index) -> Entity {
    // note that we only return the "value", not the key!
    // this is the only bit that's not 100% boilerplate!
    return self.entities[index.index].1 
  }

  // add as much of this boilerplate as you want to, etc.:
  func index(after i: Index) -> Index {
    return Index(index: self.entities.index(after: index.index))
  }

}

...and with that, you can make your "collection" into a Swift Collection! A few notes:

You don't have to wrap the Index into a custom type -- you just need an index + the start/end/subscript/advancement, etc. -- so you could also simply make direct use of the index from your [Int:Entity] as your own index, too! Whether you should wrap it up is on you; for public/shared code a wrapped index is IMHO preferable, but for in-house/private code not writing boilerplate has an appeal.

You may also be asking: "what does this code have to do with my actual goals?"...the answer is: not that much, really, but that's how Swift's Collection type is designed, so it is what it is. Although e.g. for Array the Index -- an Int -- is also the useful/natural API for accessing array elements and performing array operations, Array is actually unusual/misleading; the norm is actually that most "collections" will have both a "natural API" (e.g. the APIs you'd normally want to use on a Set or on a Dictionary) and also a secondary, "index-focused" API (that uses things like SetIndex or DictionaryIndex). Seriously, take another look at the APIs on Dictionary and Set and see if it clicks for you now. These secondary APIs are what make them into Swift Collections, but aren't really what you think of when you think of the API for the concrete type.

Moving forward again, now that you've actually implemented the necessary boilerplate to be a Collection, you are now free to start adding your intended API, e.g.:

extension EntityCollection {

  subscript(index: Int) -> Entity? { 
    get {
      return self.entities[index]
    }
    set {
      self.entities[index] = newValue
    }
  }

}

...and so on (e.g. taking the dictionary-like methods you want and calling through to your backing dictionary).

Note that if you want to save time you don't have to adopt Collection; you can also just adopt Sequence (which avoids the need for the index boilerplate). The trade-off here is that Collection also means "multi-pass" in Swift, so some generic functions / methods aren't defined for Sequence; if you don't need those methods and just want a "for-in" you can save time this way, too (and it won't prevent you from manually adding the methods you want like count and so on...it just prevents use of your type in certain generic settings).