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.
 
  • Post
  • Reply
Doctor w-rw-rw-
Jun 24, 2008
I've gotten away with it more often than not. Whose anecdata wins?

Honestly, if someone is parsing a limited set of something like (rgba?\((0-9){1,3},(0-9){1,3},(0-9){1,3}\)|#?([a-fA-F0-9]{3}){1-2}), chances are they're dealing with data that is either normalized at some level, or somewhat controlled/validated.

Writing a proper parser won't cause problems but it could be time poorly spent in terms of opportunity cost.

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?

Doctor w-rw-rw- posted:

I don't doubt that that approach is super fast, and nice for compilers, but it sounds like overkill for a typical iOS app (assuming the developer is not already familiar with writing recursive descent parsers)

To me writing a little parser like this is the sort of that a lot of people seem to think is hard because they just haven’t done it.

Give it a try, it should be pretty easy.

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:

I've gotten away with it more often than not. Whose anecdata wins?

Honestly, if someone is parsing a limited set of something like (rgba?\((0-9){1,3},(0-9){1,3},(0-9){1,3}\)|#?([a-fA-F0-9]{3}){1-2}), chances are they're dealing with data that is either normalized at some level, or somewhat controlled/validated.

Writing a proper parser won't cause problems but it could be time poorly spent in terms of opportunity cost.

And when you discover that the data isn’t as normalized as you think it is, and someone put in a comment or an extra space, and you have to start tweaking the regex, you’ll wind up having to spend the time you thought you were saving anyway.

If you’re going to argue opportunity cost, argue about the utility of spending a week on something, not a couple hours.

Doctor w-rw-rw-
Jun 24, 2008

eschaton posted:

And when you discover that the data isn’t as normalized as you think it is, and someone put in a comment or an extra space, and you have to start tweaking the regex, you’ll wind up having to spend the time you thought you were saving anyway.

If you’re going to argue opportunity cost, argue about the utility of spending a week on something, not a couple hours.

Of course the compiler writer (not exactly clear on whether you work on clang/llvm or Xcode or what) would see a lot of different pathological input and corner cases, and know *exactly* what to do to write the best parser off the top of their head.

In any case, decent unit tests would catch those problems, and not *every* problem needs to handle messy input. As long as the unit tests are filled out with reasonable input, most programs and apps will fare fine with a "parser" built out of string functions in a handful of minutes.

It's because a lot of developers haven't written a "real" parser that it will take time to learn to do that, or realistically to google around for stackoverflow posts which describe. You are paid to know this stuff - a lot of it must be second nature, but I certainly can't rattle off the top of my head what a "real" parser would be (parser generator? recursive descent? something dumber?) even though I probably could relearn it without much trouble.

But going the easy route and then going the easy-but-less-familiar-route-that-takes-time or hard route as needed still sounds like the natural course of action to me.

Dirk Pitt
Sep 14, 2007

haha yes, this feels good

Toilet Rascal
Is anyone going to WWDC? I didn’t get a ticket but decided alt-conf and layers both look interesting so I’ll be in the area. I might be a bit jetlagged but a meetup would be cool as hell. Flying in from Stockholm on Sunday and out on Friday so down whenever.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Doctor w-rw-rw- posted:

Of course the compiler writer (not exactly clear on whether you work on clang/llvm or Xcode or what) would see a lot of different pathological input and corner cases, and know *exactly* what to do to write the best parser off the top of their head.

In any case, decent unit tests would catch those problems, and not *every* problem needs to handle messy input. As long as the unit tests are filled out with reasonable input, most programs and apps will fare fine with a "parser" built out of string functions in a handful of minutes.

It's because a lot of developers haven't written a "real" parser that it will take time to learn to do that, or realistically to google around for stackoverflow posts which describe. You are paid to know this stuff - a lot of it must be second nature, but I certainly can't rattle off the top of my head what a "real" parser would be (parser generator? recursive descent? something dumber?) even though I probably could relearn it without much trouble.

But going the easy route and then going the easy-but-less-familiar-route-that-takes-time or hard route as needed still sounds like the natural course of action to me.

Just admit you don't know something, dude. It's okay. This mental gymnastics of "well OF COURSE I know this and require only the minimum of refreshing to be back to doing it flawlessly, but for the benefit of others..." gets old fast.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
eschaton does not work on compilers in any way. He's still right, though: you should really just write a simple recursive-descent parser on top of a simple lexer like this:

Swift code:
public enum Token {
  public case identifier(Substring)
  public case integer(Substring)
  public case comma
  public case lparen
  public case rparen
  // ...
  public case badCharacter(Character)
  public case eof
}

public struct Lexer {
  private var contents: Substring
  public var currentToken: Token

  public init(contents: Substring) {
    self.contents = contents
    currentToken = .eof
    lex()
  }

  public mutating func consume() {
    lex()
  }

  public mutating func consumeIf(predicate: (Token) -> Bool) -> Bool {
    guard !predicate(currentToken) { return false }
    lex()
    return true
  }

  public mutating func consumeIf(exactly token: Token) -> Bool {
    return consumeIf { $0 == token }
  }

  private mutating func lex() {
    contents = contents.dropWhile { $0.isWhitespace }
    guard let c = contents.first { currentToken = .eof; return }
    switch c {
    case _ where c.isDigit:
      let idx = contents.firstIndex { !$0.isDigit } ?? contents.endIndex
      currentToken = .integer(contents.prefix(upTo: idx))
      contents = contents.suffix(from: idx)
    case _ where c.isLetter || c == "_":
      let idx = contents.firstIndex { !$0.isLetter && !$0.isDigit && $0 != "_" } ?? contents.endIndex
      currentToken = .identifier(contents.prefix(upTo: idx))
      contents = contents.suffix(from: idx)    
    case ",":
      currentToken = .comma
      contents = contents.dropFirst(1)
    case "(":
      currentToken = .lparen
      contents = contents.dropFirst(1)
    case ")":
      currentToken = .rparen
      contents = contents.dropFirst(1)
    // ...
    case _:
      currentToken = .badCharacter(c)
      contents = contents.dropFirst(1)
    }
  }
}

enum ParserError: Error {
  case unexpected(Token)
  case integerOutOfRange(Substring)
}

public struct Parser {
  private var lexer: Lexer

  public init(contents: Substring) {
    lexer = Lexer(contents: contents)
  }

  public mutating func expect(exactly expected: Token) throws {
    if !lexer.consumeIf(exactly: expected) {
      throw ParserError.unexpected(lexer.currentToken)
    }
  }

  public mutating func parseInt() throws -> Int {
    guard case .integer(let string) = lexer.currentToken {
      throw ParserError.unexpected(lexer.currentToken)
    }
    lexer.consume()
    guard let result = Int(string) {
      throw ParserError.integerOutOfRange(string)
    }
    return result
  }

  public mutating func parseCommaSeparatedList<T>(elementParser: (inout Parser) throws -> T) throws -> [T] {
    try expect(exactly: .lparen)
    var list = [T]()
    if lexer.currentToken != .rparen {
      repeat {
        list.append(try elementParser(&self))
      } while lexer.consumeIf(exactly: .comma)
    }
    try expect(exactly: .rparen)
    return list
  }

  public mutating func parseIntList() throws -> [Int] {
    return parseCommaSeparatedList { $0.parseInt() }
  }
}

rjmccall fucked around with this message at 23:48 on Apr 22, 2019

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?

Dirk Pitt posted:

Is anyone going to WWDC? I didn’t get a ticket but decided alt-conf and layers both look interesting so I’ll be in the area. I might be a bit jetlagged but a meetup would be cool as hell. Flying in from Stockholm on Sunday and out on Friday so down whenever.

I’ll be at WWDC. ;)

Doc Block
Apr 15, 2003
Fun Shoe
Gonna get a job at Apple just so I can go to WWDC every year :haw:

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
A recursive descent parser is not some fancy-pants thing that you need to learn how to write. It's basically what you get if you set out to write a parser with no knowledge of how a parser should work. Realizing that you're writing a recursive-descent parser just helps you skip a few steps and get to something working faster.

JawnV6
Jul 4, 2004

So hot ...

Doc Block posted:

Gonna get a job at Apple just so I can go to WWDC every year :haw:
wait what
:ohdear:

Doc Block
Apr 15, 2003
Fun Shoe

JawnV6 posted:

wait what
:ohdear:

I am not being serious

duck monster
Dec 15, 2004

Froist posted:

You have my interest - in the last week my work’s latest update (which introduces UDP connections) has had issues with IPv6 UDP on some Android forks (obviously unrelated), but the iOS version hasn’t released yet because we’re stuck in rejection limbo.

Seems a good opportunity to figure out if we’ll have similar issues waiting for us when we manage to release on iOS. Have you got any more details/an OpenRadar link for what exactly is “very hosed”?

Not sure the report link, one of the other guys filed it. The issue seems to have something to do with multicast and IPV6. We've moved on. The hardware devices we talk to don't support IPv6 anyway.

Also I'm really really growing to dislike Realm. Ran some stats over our git repos and we spend about 60% of our debugging time knocking stupid realm bugs on the head. Never was my choice to use it, and I'm really starting to think the benefits don't match the stupid costs. This , by the way applies to RX type libraries too. I'm sure theres a use-case for this poo poo, but I haven't encountered one yet.

Its a big ol' mess of buzzword tech.

duck monster fucked around with this message at 05:35 on Apr 24, 2019

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I would be interested in hearing what stupid issues you have with Realm since I'm probably responsible for half of them and the other half are probably things I've spent the last two years wishing I could find time to improve.

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?
Isn’t Realm the “not Core Data” ORM that used to market itself as “Core Data doesn’t support threads, we do” when that’s been incorrect since day one?

eschaton fucked around with this message at 04:59 on Apr 25, 2019

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The marketing's always been pretty dumb and off.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

eschaton posted:

I’ll be at WWDC. ;)

What a surprise, I'll be there too!

I figured I'd get up on stage and say a few words at some point.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Plorkyeran posted:

I would be interested in hearing what stupid issues you have with Realm since I'm probably responsible for half of them and the other half are probably things I've spent the last two years wishing I could find time to improve.

Speaking of, how’s it going?

Stringent
Dec 22, 2004


image text goes here

rjmccall posted:

Speaking of, how’s it going?

I'm using it for a small app at the moment and it's working fine, fwiw.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

rjmccall posted:

Speaking of, how’s it going?

Well I still have a job, I'm getting some figgies in 6 months and there's a 9 month roadmap that involves good things for the stuff I work on.

After that who the gently caress knows.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Yeah, I was seeing some speculation that it was an acquihire, so I'm glad they're not blowing up your engineering group, at least immediately.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The server stuff is a big question mark (there is a plausible path to it sticking around, but...), but all of the conversations around what happens with the client database have been around things like what roles we should hire people for now that we can actually afford to do so again.

fankey
Aug 31, 2001

Thanks for the parser comments. I ended up finding a parser on github that met my needs so crisis averted.

Now another question - is there a straightforward way to draw rounded rectangles in CoreGraphics that have different horizontal and vertical radii? Basically implementing this. WPF has a handy ArcSegment which allows you to specify both a x and y radius for the arc. All the arc functions I see in CoreGraphics only take a single radius and I'm hoping I'm not doomed to try and piece-wise approximate using bezier curves - although if someone knows a handy reference there please let me know!

Doctor w-rw-rw-
Jun 24, 2008
https://stackoverflow.com/questions/11365775/how-to-draw-an-elliptical-arc-with-coregraphics ?

Pope Hilarius
May 3, 2007

Plorkyeran posted:

The server stuff is a big question mark (there is a plausible path to it sticking around, but...), but all of the conversations around what happens with the client database have been around things like what roles we should hire people for now that we can actually afford to do so again.

Realm Sync might go extinct? Will there be a replacement? I've been a cloud customer for the last few months and built a lot of my app around it, would suck for me and my app if that was all wasted time/dreams. Realm just seemed so promising.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Oh, I specifically meant the current server codebase and not the whole "mobile platform" thing. Upselling people on server things is the whole point business-wise, since it's the only thing anyone will actually pay for. Because of that, there will presumably always be an option to pay money for data sync, but it might involve a different backend in the future. I have no idea what practical implications that will have for you, if any.

fankey
Aug 31, 2001

Thanks. Somehow I missed that one in my searching. Worked great!

Doh004
Apr 22, 2007

Mmmmm Donuts...
Finally heading off to a new job after being at my current place for about 4 1/2 years. Excited as I'm getting a bit more back into actual iOS development as I've been doing higher level management for a while now :)

Speaking of which - anyone use Apollo yet? I'll be navigating some GraphQL decisions that have already been made so curious to hear other people's experiences with it (if any).

BusError
Jan 4, 2005

stupid babies need the most attention

Doh004 posted:

Finally heading off to a new job after being at my current place for about 4 1/2 years. Excited as I'm getting a bit more back into actual iOS development as I've been doing higher level management for a while now :)

Speaking of which - anyone use Apollo yet? I'll be navigating some GraphQL decisions that have already been made so curious to hear other people's experiences with it (if any).

This is minimally helpful, but I have a number of coworkers who've used Apollo on (JS) projects and had nothing but good things to say about it. I don't know any more than that, but it sounded promising!

SaTaMaS
Apr 18, 2003
Are there any good resources on functional design patterns for Swift? As I understand it, functional programming has obsoleted a lot of the design patterns as they were presented in the Gang of Four book, but when I look for Swift design patterns online, they tend to be OOP implementations of the GOF patterns that don't take advantage of Swift's functional capabilities.

KidDynamite
Feb 11, 2005

SaTaMaS posted:

Are there any good resources on functional design patterns for Swift? As I understand it, functional programming has obsoleted a lot of the design patterns as they were presented in the Gang of Four book, but when I look for Swift design patterns online, they tend to be OOP implementations of the GOF patterns that don't take advantage of Swift's functional capabilities.

obj-c.io has an app architecture book that covers TEA(The Elm Architecture) that allows functional programing. TEA is only one out of 5 architectures covered.

Doh004
Apr 22, 2007

Mmmmm Donuts...

BusError posted:

This is minimally helpful, but I have a number of coworkers who've used Apollo on (JS) projects and had nothing but good things to say about it. I don't know any more than that, but it sounded promising!

So far not so bad. No complaints but I haven't had to change much with our implementation client-side yet. Now server side? That's a different story but that ain't GraphQL's fault...

jackpot
Aug 31, 2004

First cousin to the Black Rabbit himself. Such was Woundwort's monument...and perhaps it would not have displeased him.<
If I were looking for something like an iOS for Fuckin Dummies class or book, where would I go? I'm doing more iOS design lately and I'm in a place where I don't really know what's possible. I did design/html/css for years, and so when I design something for the web I know whether it's buildable, but in iOS I just don't know the rules. I'm looking for something that'll let me build prototypes without any data or real functionality - I'm basically looking to make the app equivalent of an Invision prototype. Something like what Codepath does but my work isn't going to send me to SF for two months.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I don’t know of a great tutorial or class, but the app equivalent of an InVision prototype is storyboards in Xcode. With segues, collection and table view controllers, Auto Layout, etc. you should be able to get pretty far without writing a line of code. You can run it on your device or in the simulator for free and with little effort. Sending it to others is more of a pain: you’ll need an Apple Developer membership and you’d want to look into sending out builds via e.g. TestFlight.

You can also get a lot done in an actual shipping app if you’re somewhat comfortable with storyboards (and if your developers put in a little bit of effort to enable you), so it might come in useful after the prototype phase too.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Also read the HIG a few times if you haven’t already. It’s a great inventory of what’s available out of the box, and tells you when it’s generally (un)acceptable to use a particular control.

Doh004
Apr 22, 2007

Mmmmm Donuts...
The HIG. Always the HIG.

The best UX/Designers I've worked with know it like the back of their hand.

jackpot
Aug 31, 2004

First cousin to the Black Rabbit himself. Such was Woundwort's monument...and perhaps it would not have displeased him.<

Doh004 posted:

The HIG. Always the HIG.
Oh definitely, I've spent a lot of time there.

pokeyman posted:

I don't know of a great tutorial or class, but the app equivalent of an InVision prototype is storyboards in Xcode.
Actually I don't mind Invision for things it's appropriate for, but what I want to learn to do is poke around and see what's possible, for real. A lot of the things I'm designing are only a few pages, and it would be cool - not necessary, but cool - to be able to mock it up in a working app to show folks. This button opens the share sheet? So do that. The items in this list all open a drawer, or that link opens another site in the app using a webview? Figure out how to do that. All of this can be faked in various prototyping tools, I know, but it wouldn't hurt to know more about how all this is done when it's done for real.

Dirk Pitt
Sep 14, 2007

haha yes, this feels good

Toilet Rascal
Anyone meeting up at WWDC? I’m hitting Vegas on my way in to see family but am free starting Monday.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

jackpot posted:

Actually I don't mind Invision for things it's appropriate for, but what I want to learn to do is poke around and see what's possible, for real. A lot of the things I'm designing are only a few pages, and it would be cool - not necessary, but cool - to be able to mock it up in a working app to show folks. This button opens the share sheet? So do that. The items in this list all open a drawer, or that link opens another site in the app using a webview? Figure out how to do that. All of this can be faked in various prototyping tools, I know, but it wouldn't hurt to know more about how all this is done when it's done for real.

Makes total sense. I’m saying you can get pretty far jumping into Xcode yourself and seeing what you can do. Here’s some random video I found that looked alright when I hastily scrubbed through it, to give you some idea: https://www.essentialdeveloper.com/articles/s01e01-swift-app-idea-and-prototyping-with-storyboards

Things like opening the share sheet or a web view might need a couple of lines of code, totally doable.

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?

Dirk Pitt posted:

Anyone meeting up at WWDC? I’m hitting Vegas on my way in to see family but am free starting Monday.

I’m up for it

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply