Swift is cross-platform (and open source), and obviously this doesn't depend on parts of Swift (like the iOS/OS X only APIs) that are not available on other platforms, but only on the core (and portable) libs.
Two things I'm not a fan of so far in the API design.
1) Function names are misleading or not descriptive enough. E.g. isAlpha(). I assumed this meant is alphanumeric, but it actually means isAlphabetic (as in no numeric values at all). isAlphanumeric() clears this up, but just call the first isAlphabetic and remove any ambiguity.
2) Explicit binary inverts; e.g. isUppercased(), isLowercased(). This leads to bad coding style as conditionals that point in the affirmative usually leads to easier to read code. If it's not uppercased of course its lowercased, so why keep a function around to point this out? Save on the cognitive load on the users and just keep one around. Let them negate it for the desired result.
Otherwise, thank you for contributing what looks to be a pretty handy library that isn't tied to just MacOS/iOS and Xcode. I'm really starting to enjoy Swift and am curious to use it in non-client environments soon and a library like this is a pretty nice tool to have.
Strings are one of the most difficult things to get right in any standard library. You can be like C and offer barebones support, but many developers will make mistakes. You can be like Java and offer much more complete support, but you can never quite satisfy everyone's use case and people complain. I personally would never have even thought to include functions like `kebabCased`, this is a very interesting take on a string library. Overall, good stuff.
12 comments
[ 3.4 ms ] story [ 49.4 ms ] threadIt is a library of functions that manipulate objects of the language built-in String type, not a library that implements a string type from scratch.
It doesn't rely on any Apple-specific APIs.
1) Function names are misleading or not descriptive enough. E.g. isAlpha(). I assumed this meant is alphanumeric, but it actually means isAlphabetic (as in no numeric values at all). isAlphanumeric() clears this up, but just call the first isAlphabetic and remove any ambiguity. 2) Explicit binary inverts; e.g. isUppercased(), isLowercased(). This leads to bad coding style as conditionals that point in the affirmative usually leads to easier to read code. If it's not uppercased of course its lowercased, so why keep a function around to point this out? Save on the cognitive load on the users and just keep one around. Let them negate it for the desired result.
Otherwise, thank you for contributing what looks to be a pretty handy library that isn't tied to just MacOS/iOS and Xcode. I'm really starting to enjoy Swift and am curious to use it in non-client environments soon and a library like this is a pretty nice tool to have.
Why should it mean alphanumeric? C's isalpha() also tests for being a letter, for instance, and has isalnum() for alphanumericness.
> If it's not uppercased of course its lowercased
If you're working exclusively with ASCII and ignoring non-letter characters, yes. But is this library bound by those constraints?
But checking !(isUppercase(str) || isLowercase(str)) to see if its not case-able(?) is absurd
Obviously you'd instead want the function notCaseable(str).
https://github.com/ArtSabintsev/Guitar/blob/0dc71e9dea5ba975...