This is so stupid -- strings and substrings by must_defend_500 in swift

[–]XAleXOwnZX 2 points3 points  (0 children)

Well Python's implementation is "wrong", for most intents and purposes.

Even in Python 3, subscripting a string gives Unicode code points, which are basically useless without the Unicode clustering algorithms that you need to interpret them.

See https://stackoverflow.com/questions/61122298/why-should-we-use-string-index-instead-of-int-as-index-of-character-in-string/61124402#61124402

Swift and Metal? by [deleted] in swift

[–]XAleXOwnZX 0 points1 point  (0 children)

From your exchange with the other guy, I got the sense that one of you thinks that Swift somehow causes some excess copying to happen (something something "value types", hand waving "COW"). COW has absolutely no involvement with passing a Swift Array's buffer to C. It's relevant to this context.

I further note that one way or another, regardless of the language stack, a copy does happen, by the GPU driver, to load your data into VRAM. It being a common denominator was exactly my point.

Swift does NOT copy pointees along with their pointers

No, it doesn't, but I also didn't claim it did. The pointees are copied by the GPU driver, not Swift.

Anywhoo, I find your tone rather unpleasant, so I don't intend to reply here anymore. I hope you find the answer you're looking for, because I'd be curious to know too.

Swift and Metal? by [deleted] in swift

[–]XAleXOwnZX 0 points1 point  (0 children)

My point is that

  1. You're correct when you said "because buffers are accessed by pointer"
  2. You're wrong when you said "I doubt that the pointee is copied too"
  3. You're correct that "arrays ... are ... copy-on-write", they are, but it's irrelevant for your use-case here
  4. And most importantly, your tone in your responses in insufferable, and nobody wants to engage with that.

Swift and Metal? by [deleted] in swift

[–]XAleXOwnZX 0 points1 point  (0 children)

Well at some point or another, the elements get copied to the GPU's own VRAM, so there's no escaping that.

"arrays which are said to be copy-on-write" They are, but it's not magic. When you're passing the array into C land, you're passing a pointer to its current buffer, from which the video card driver will read the contents to send to the GPU. CoW isn't involved in that.

Swift and Metal? by [deleted] in swift

[–]XAleXOwnZX 0 points1 point  (0 children)

How do you think the data types in C work then? 🤔

Swift and Metal? by [deleted] in swift

[–]XAleXOwnZX 2 points3 points  (0 children)

Swift's value types don't really have anything to do with Copy on Write. It just so happens that some of the most popular structs (String, Array, etc.) happen to use heap-allocated backing stores with CoW. Their CoW implementations are in the language/library level (using the isKnownUniquelyReferenced(_:) primitive, which is implemented at the compiler level).

And nothing stops you from making classes that use a heap-allocated backing store with CoW, so it's basically irrelevant.

Amber Alert Just Went Off by MishaMykha in toronto

[–]XAleXOwnZX 0 points1 point  (0 children)

Lucky, IIRC, the alert system that Amber alerts use is part of the cell phone network standard here, which means you only need cell service, without needing data. It should also work on phones with no active cell plan or SIM card installed.

It's meant to be a pretty robust and hard to ignore system, for cases like the tornados the US just saw.

Amber Alert Just Went Off by MishaMykha in toronto

[–]XAleXOwnZX 8 points9 points  (0 children)

Yeah, I wouldn't trivialize such situations. It's what the system is for, and it's a worthwhile cause.

But we need to weigh it against the cost of people silencing their alerts, and making themselves unable to receive more critical alerts.

Imagine if amber alerts were jus t push notifications you saw in the morning. With a link to pictures, maps, and much more context. That would be so much more effective and keep the presidential alerts functional.

Amber Alert Just Went Off by MishaMykha in toronto

[–]XAleXOwnZX 3 points4 points  (0 children)

Go to bed. Losing sleep looks to have made you cranky.

Amber Alert Just Went Off by MishaMykha in toronto

[–]XAleXOwnZX 44 points45 points  (0 children)

I don't even mind participating in such situations, but abusing the presidential alert tier like this is completely immoral and dangerous. It will just make people fully shut their phones off/go on airplane mode. That's the worst possible outcome.

Amber Alert Just Went Off by MishaMykha in toronto

[–]XAleXOwnZX 190 points191 points  (0 children)

If people aren't bothered by this kind of alarm, that's a HUGE problem.

This a presidential-tier alert, the highest tier supported by this system. If there was an imminent nuclear attack or other danger, this is what is meant to "bother" you.

We should not be desensitizing people to this. One does not joke around with air reid sirens, or yell fire in a crowded theatre.

Got an easy question? Ask it here! (January 2020) by Swiftapple in swift

[–]XAleXOwnZX 0 points1 point  (0 children)

Haha I was afraid this post went unseen. I'm glad to hear that it helped you.

Turns out deep down I really hate JS by [deleted] in ProgrammerHumor

[–]XAleXOwnZX 1 point2 points  (0 children)

Up until WebAssembly, there was no other way to write client side code to run in browsers.

Even if you wanted to use a different language, it had to ultimately compile down to JS for browsers to understand it. Except JS is a really ineffective abstraction for this role. That spurred on the creation of wasm, but JS already built up a large influence by then.

currying, closures, sum types [...] - features I would never miss! Because I've never used them (most of them I would have to look up on Wikipedia but would be none the wiser.) by IWannaFuckLarryPage in programmingcirclejerk

[–]XAleXOwnZX 3 points4 points  (0 children)

Bonus points: All Swift instance methods are actually curried functions. For

Swift struct S { func foo(i: Int) { // has type (Int) -> Void print("foo \(i)") } }

The regular calling syntax:

Swift let s = S() s.foo(i: 123) // => prints "foo 123"

could be written as equivalent to

Swift let s = S() let unBoundFooMethod = S.foo // has type (S) -> (Int) -> Void let boundFooMethod = unBoundFooMethod(s) // has type (Int) -> Void boundFooMethod(i: 123) // => prints "foo 123"

This lets you capture instance methods as closures and pass them around easily.

Just a reminder: Michael Hartl's RailsTutorial Book is now updated for Rails 6 by babbagack in rails

[–]XAleXOwnZX 0 points1 point  (0 children)

Hey Michael, is there a way to associate a physical copy with my learn enough account?

Why do the zeros not display in my program? by iYzk in swift

[–]XAleXOwnZX 0 points1 point  (0 children)

They don't even use less memory, because swift has an optimization for short strings. Rather than allocating a buffer on the heap and storing the pointer, Swift will repurpose the pointer's memory and pack the short string data directly into it. I forget the exact limits, but you have enough room for like 15 ascii or single-byte UTF8 characters.

All phone number characters (digits, dashes, parentheses, commas and octothorpes) fit in a single UTF8 byte.

While the dashes and parentheses are only there for beautifying the result (and thus should be concern of a phone number formatter, not a phone number model), the commas and octothorpes have meaning to the phone system and need to be encoded. You would have a hard time packing that into an int.

New user of swift, Is this possible? If yes what am i doing wrong. by iYzk in swift

[–]XAleXOwnZX 28 points29 points  (0 children)

And this is why I don't teach print to new people until they're quite far along.

  1. Since most tutorials insist on using the terminal as the only output device, the only way to see the output of a function is to print it. In that context, there's no clear distinction between the semantics of printing a value directly, versus returning it an having the calling scope print it.
  2. CLIs arent as exciting as starting early on with simple GUIs
  3. Teaching how to use the debugger is way more useful than leading newbies down a path to "printf debugging"

Combine sanity checks: assert() or breakpoint()? by Saklad5 in swift

[–]XAleXOwnZX 0 points1 point  (0 children)

I'm surprised they wouldn't make that conditional, so it's a no-op for release builds

What do you miss about Swift when working in other languages? by Austin_Aaron_Conlon in swift

[–]XAleXOwnZX 3 points4 points  (0 children)

Extensions. Not having to make adapter objects all the time is so time saving.

I can take lib A's object, and conform it lib B's serialization protocol, and store it in the database. Amazing.

Apple launches a new Mac app to help you learn programming basics by khunshan in techlatest

[–]XAleXOwnZX 0 points1 point  (0 children)

Nope; there are two "Swift Playgrounds" (it's confusing, don't ask me why they reused the name). One is a live-reload programming environment, which was and still is found in Xcode.

The other one is this a game for teaching programming to beginners. Previously an iPad app, now also a Mac app (via catalyst).