May 02, 2016
On 29/04/16 04:36, Walter Bright wrote:
> On 4/28/2016 2:32 PM, Daniel Kozak via Digitalmars-d wrote:
>> Wierd, I am almost sure it does not work for me last time when I tried :)
>
> That's because in dmd there's the line:
>
>      if (strcmp(user, "Daniel") == 0)
>      setScoping(false);
>
> It's a feature!
>

Microsoft Windows have APIs that have code substantially like the above.

i.e.:

stdcall SomeWindowsAPI(parameters) {
  if( getProcessName()=="Norton Antivirus" ) {
    // Do something differently
  }
}

If a program is deemed important enough to their echosystem, and that program uses an API in a broken (or otherwise non-forward compatible way), then they will add exceptions to their API to keep that program working.

Shachar
May 02, 2016
On 5/2/16 6:55 AM, ag0aep6g wrote:
> On 02.05.2016 09:45, Jacob Carlborg wrote:
>> Does it matter? I thought the idea was to get the same behavior not
>> explicitly a range.
>
> default0 said that D's ranges would be more awkward than a for loop. I
> think D's iota is fine.
>
> D's special syntax is even nicer, but it's a language thing. And
> apparently Swift is cutting down on syntax, not adding. Something like
> iota is probably doable in a library. I don't know Swift, though.

Swift has both builtin syntax and library mechanism similar to iota:

for i in 0..<5 // [0 to 5)
for i in 0...5 // [0 to 5]
for i in 0.stride(to: 5, by: 1) // [0 to 5)
for i in 0.stride(through: 5, by: 1) // [0 to 5]

You can also hack with where expressions the builtin range syntax to skip values like iota, but I'm almost positive this doesn't perform well, or at least won't in complex situations:

for i in 0..<10 where i % 2 == 0 // even numbers less than 10

I think for-in (swift) and foreach (D) are both fantastic for iterating a straight range or pre-determined sequence. I would never use for loops for a straightforward index progression (and ideally, I would ignore the index if at all possible).

However, there are cases where I pull out the for loop because the ending condition is complex, or strangely related to the index variable, or the increments aren't regular. For loops have so much power in such a succinct syntax, I can't understand why anyone would shun them as taboo or error prone. Seems like it's more a philosophical decision than practical or helpful.

And anyone who says "bleh, you can just use a while loop if you need that" I want to beat with a semi-colon over the head.

-Steve
May 03, 2016
On Monday, 2 May 2016 at 14:32:30 UTC, Steven Schveighoffer wrote:
> On 5/2/16 6:55 AM, ag0aep6g wrote:
>
> And anyone who says "bleh, you can just use a while loop if you need that" I want to beat with a semi-colon over the head.
>
> -Steve

Apparently, Swift also does not have goto. For all languages that do have it, why use while at all if you have goto and if at your disposal? It's so much more general and powerful and simpler anyways :^)

Though I suppose for Swift just using recursion may do as an alternative to while. No need to introduce a new keyword/new syntax for something you can already easily do using a simple combination of other features, right?
1 2 3 4 5
Next ›   Last »