|
The sizes of basic types are orthogonal to the layout rules, though. I agree that the decision to make Int track the machine word size came with obvious memory-use penalties, but we still made that decision, and there's no use second-guessing it every time we see those penalties in action. It's easy enough for users to use a smaller type internally when the memory use matters. For what it's worth, we were never seriously considering making Int a fixed 32-bit type: we wanted to encourage using a single Int "currency" type, and if that was going to be fixed across platforms, it was going to have to be 64-bit. I had a major hand in shooting that down in favor of the less portable solution, for memory and interop reasons.
|
# ? May 23, 2016 22:02 |
|
|
# ? May 15, 2024 09:13 |
|
Man, the way you're seriously answering that comment about sizeof(Int), I think I remember your posting history better than you do.
|
# ? May 23, 2016 22:04 |
|
Heh, maybe. I'm kind of light-headed today; home sick.
|
# ? May 23, 2016 22:08 |
|
sarehu posted:Okay on that note I'll retract calling sizeof(T) "wrong." On the other hand if you're optimizing struct packing like this, sizeof(Int) could stand to be 4 bytes to save some cache line space... You're typically operating on an UnsafePointer which knows the size/stride anyway. Swift doesn't currently have an easy way to deal with packed values at all.
|
# ? May 24, 2016 05:08 |
|
I went on a car trip recently and saw one of the trucks where the Swift developers live and work, like in Knight Rider.
|
# ? May 24, 2016 07:41 |
|
Some commentary on dynamism in Swift: http://mjtsai.com/blog/2016/05/21/dynamic-swift-2/
|
# ? May 24, 2016 15:46 |
|
I'm looking forward to the swift UI framework that will get these people to stop writing these hand-wringing blog posts
|
# ? May 24, 2016 17:04 |
|
I've never had the impression that the Swift team was opposed to dynamism. They just haven't finished designing Swift's answers to those problems that demand dynamism.
|
# ? May 24, 2016 18:18 |
|
Doctor w-rw-rw- posted:Some commentary on dynamism in Swift: http://mjtsai.com/blog/2016/05/21/dynamic-swift-2/ quote:No one doubts that this team will produce a great language for writing a compiler—the question is how it will handle apps. Apple is attempting something very ambitious: a single language that can span the spectrum. They are in uncharted territory, which is why people don’t know exactly what to expect. Members of the Swift core team have explicitly said they have no plans to rewrite Swift in Swift right now precisely because that leads to language suited to building compilers. None of them have expressed a disregard or distain for the problems of app developers. I just think Swift is being ambitious in trying to be a systems programming language and app development language. Almost every example of something that requires dynamism is not a real example, it's just Apple developers thinking only in terms of how the existing SDKs and Interface Builder work. The complaints about code generation are because they've never used good code generation. Visual Studio represents all visually designable elements as code and it works really well. It injects stored properties and statically typed event handlers through extensions. Interface Builder could do the same thing and instead of having to drag between IB and code it could just happen automatically. Swift needs a good safe macro/metaprogramming system. It needs good reflection. It does not need objc_msgSend or swizzling.
|
# ? May 27, 2016 22:50 |
|
that reminds me, are there plans to make swift more expressive?
|
# ? May 28, 2016 01:00 |
|
It's interesting to see all this heated Swift debate coming up now. Wonder what triggered it?
|
# ? May 28, 2016 02:12 |
|
Snapchat A Titty posted:that reminds me, are there plans to make swift more expressive? No, it's too expressive as it is and we need to cut back.
|
# ? May 28, 2016 02:14 |
|
smackfu posted:It's interesting to see all this heated Swift debate coming up now. Wonder what triggered it? Seems to go in waves. Often a Respected Member of the Community will write a variously dismissive thing that sets everyone off.
|
# ? May 28, 2016 02:38 |
|
John Gruber seemed interested in linking every article he could find this week. Wil Shipley is treating it as an overreaction.
|
# ? May 28, 2016 03:32 |
|
rjmccall posted:No, it's too expressive as it is and we need to cut back. Nice
|
# ? May 28, 2016 03:59 |
|
Toady posted:John Gruber seemed interested in linking every article he could find this week. Wil Shipley is treating it as an overreaction. The worst bit of this is that John Gruber’s influence is so outsized compared to most of the people he's linking to, and that he's basing the merits of dynamism in Swift on who is arguing for it — namely his friends. Not that I'm worried anyone working on a successor to UIKit is taking notes from Daring Fireball, thank christ. Yesterday Brent Simmons posted about how Elm (a ML language primarily designed for writing UIs) handles this case, and he doesn't like it because switch statements. Personally, I really like the way Elm (and its intellectual offshoots like Redux) handles inputs, and think it's a great fit for a static, funcitonal setting. I don't find the argument that it's too much boilerplate particularly convincing, and it's weird to read all these Objective-C programmers who are apparently very squeamish in the face of verbosity.
|
# ? May 28, 2016 09:49 |
|
Nothing fancy but I thought the ability to do this was super nicecode:
|
# ? Jun 2, 2016 18:46 |
|
Officially a Swift contributor, I guess. Probably about the easiest contribution possible, but:
|
# ? Jun 8, 2016 08:54 |
|
Congrats!
|
# ? Jun 8, 2016 16:58 |
|
So. Question about how to best store something. I am converting an old program of mine from Obj-C and I never liked the way I did it there. Wondering if Swift has a better option. I am generating a table of 26 different alphabets, which I then need to be able to access individual elements of, by row/column - but the row/column indices are also alphabets. So basically this: code:
I have simplified for this example, but the alphabets are all scrambled, not merely shifted a character to the right. I'd like to be able to basically go: code:
Suggestions?
|
# ? Jun 8, 2016 19:19 |
|
You can define custom subscript accessors for your data structure. https://developer.apple.com/library...4097-CH16-ID305
|
# ? Jun 8, 2016 19:44 |
|
emoji posted:You can define custom subscript accessors for your data structure. I would add that subscripts can have multiple indices so this works just fine: code:
You're constructing a matrix so using a two-dimensional array or offsets into a one-dimensional array would work just fine.
|
# ? Jun 9, 2016 00:09 |
|
Ender.uNF posted:I would add that subscripts can have multiple indices so this works just fine: Edit: figured out how to declare it. Are dictionary keys optional by default? code:
HaB fucked around with this message at 14:36 on Jun 9, 2016 |
# ? Jun 9, 2016 13:10 |
|
The result of subscripting into a dictionary is optional to account for the possibility that there isn't an entry for that key.
|
# ? Jun 9, 2016 15:26 |
|
I've written an extension method on Int called '.asRgbColor' so you can do...code:
Edit: I filed a bug, looks like the parser is confused because the 'a' at the start of asRgbColor is valid in a hex string, so it tries to parse it as a floating point hex literal! Changing the var name to toRgbColor fixes the issue... toiletbrush fucked around with this message at 00:16 on Jun 10, 2016 |
# ? Jun 9, 2016 23:50 |
|
toiletbrush posted:I've written an extension method on Int called '.asRgbColor' so you can do... It's a bug in the lexing of hex literals. The problem is that there is a floating-point hex literal format, and what follows the dot is, in fact, more hex digits; so we're slurping up the '.' and the 'a' and then failing to backtrack correctly when we see the 's'. There's an unsolvable ambiguity here if the entire property / method name is composed of valid hex digits (or 'p'), but since we're already Doing The Right Thing when the first character after the dot isn't a hex digit, there's really no justification for not Doing The Right Thing when any of the characters isn't a hex digit.
|
# ? Jun 10, 2016 00:30 |
|
I haven't tried it, but wouldn't conforming UIColor to IntegerLiteralConvertible and using "let thing: UIColor = 0xfff" and "self.backgroundColor = 0xfff" be more convenient anyway?
|
# ? Jun 10, 2016 21:00 |
|
Choadmaster posted:I haven't tried it, but wouldn't conforming UIColor to IntegerLiteralConvertible and using "let thing: UIColor = 0xfff" and "self.backgroundColor = 0xfff" be more convenient anyway? Yeah we've got that in our codebase it's p sweet.
|
# ? Jun 11, 2016 00:06 |
|
rjmccall posted:It's a bug in the lexing of hex literals. The problem is that there is a floating-point hex literal format, and what follows the dot is, in fact, more hex digits; so we're slurping up the '.' and the 'a' and then failing to backtrack correctly when we see the 's'. how often does a floating point number in hex notation come up? maybe FastInvSqrt?
|
# ? Jun 11, 2016 14:46 |
|
That was my first question, but apparently it is super common in numerics.
|
# ? Jun 11, 2016 15:49 |
|
So if I am creating an extension on say - String. What magic must I perform to keep that in its own file? I'd like to be able to use it on ALL strings in my app, so I don't want it in just one class or whatever.
|
# ? Jun 11, 2016 18:28 |
|
Could you just wrap the literal in parens or something to make the member access unambiguous?
|
# ? Jun 11, 2016 18:37 |
|
HaB posted:So if I am creating an extension on say - String. What magic must I perform to keep that in its own file? I don't understand. The usual access modifiers (private, internal, public) should do it for you?
|
# ? Jun 11, 2016 18:47 |
|
pokeyman posted:I don't understand. The usual access modifiers (private, internal, public) should do it for you? They don't appear to be. Extension declaration, in own file: code:
code:
|
# ? Jun 11, 2016 19:27 |
|
Think you might want public extension String
|
# ? Jun 11, 2016 19:31 |
|
afaik, public extension just applies public to all of the members of the extension, so that wouldn't make a difference. It looks like it should work based on what you posted, so something else must be going on. If the extension is in a different module, you need to import the module where you want to use it. Otherwise, maybe check your target inclusions and make sure that both files are included in the target you're building.
|
# ? Jun 11, 2016 21:18 |
|
lord funk posted:Think you might want public extension String this fixed it. Thanks.
|
# ? Jun 11, 2016 21:49 |
|
HaB posted:this fixed it. That's odd—in my experience, setting the visibility of the member should have been enough. Visibility and extensions seems to be an odd spot in the language. Don't force-unwrap your optionals though. Do this instead: code:
|
# ? Jun 11, 2016 22:23 |
|
rjmccall posted:That was my first question, but apparently it is super common in numerics. im gonna tell on you dogg
|
# ? Jun 12, 2016 04:51 |
|
|
# ? May 15, 2024 09:13 |
|
theres really good docs on rjmccall leaking stuff imo
|
# ? Jun 12, 2016 04:51 |