Programming Language cross-pollination and troubleshooting!

A bit of oblivious programmer humor -

Last night, I was having an issue when compiling a project in Xojo. I kept getting a message about something on a line not being found. After 90 minutes of staring at the code, I went to bed. At 01:30, I came hard awake as my sub conscience slapped me in the face with the answer.

Here’s my original, failing code:

    ConnectionFailed = (Ticks >= t + (5 * 60)) || (InStr(theShell.Result, "connection refused") <> 0)

I had spent the entire weekend working in C …

A bit like

//do something clever to predict the gross value next year assuming approximately 20% of the customers decide to upgrade and less than 5% of the users cancel

… spend the day with a project manager…

Whenever I have to write some Javascript, I often find myself typing

If (blah1 = blah2) Then

…and once I finally realize the ‘Then’ needs to be a ‘{’, I may (or may not) remember that the ‘=’ needs to be a ‘==’

and that curly bracket }

is it the NEXT that matches a FOR?
or the END that matches a SELECT (uh… I mean SWITCH)
or to I just plain have too many (or worse not enough)

Thats why C often has VERY pedantic formatting rules

If you’re not using an editor that shows the matching braces, it’s time to update your toolset. And if you can’t see them both at the same time, it’s time to refactor some code.

Good advice
But am I the only one that codes

[code]if bSomethingisTrue then
…stuff

end if // end of if bSomethingIsTrue[/code]

so that if I have to insert a nested statement i get

[code]if bSomethingisTrue then
…stuff
for x = 1 to 99

next // x loop

end if // end of if bSomethingIsTrue[/code]

Cross pollination has advantages to overcome the limitations of For Next in order to place it into a timer.

for( i=1 ; i<=10 ; i++) { printf("Hello, World!\ "); }

The C loop is in fact closer to a while, as condition and increment are separate.

To create a loop with a timer, which can be extremely useful to replace threads :

[code]Static i as Integer = 1

if i < 10 then
// Do stuff
'…
i = i + 1
else
me.mode = Timer.ModeOff
end if[/code]

probably one of the reasons the in SWIFT 3, this form of FOR loop is being removed

Could you post an example in Swift 3 then ? Just for the sake of comparison ?

sure give me a few minutes

as they would be shown in XOJO

for i=1 to 10
next i
for i=1 to 10 step 2
next i
for i=10 downto 1
next i
for i=a to b 
next i

as in SWIFT

for i in 1...10 {
}
for i in 1.stride(to:10, by: 2) {
}
for i in (10...1).reverse() {
}
for i in a...b {
}

swift has some nice things
but then they do something odd like requiring named positional parameters
dunno if thats a holdover from some Obj-C underpinnings or what

not “required”

If you create a function like this

func myFUNC(x:Int, y:Int,z:String)

then YES they are required
and you would call it like this

myFUNC(3,y:2,z:"A")

note the first one is for some reason never required (although I believe THAT is changing in Swift3 as well)

but you can just as easily create it like this

func myFUNC(x:Int,_  y:Int,_ z:String)

by placing “_” followed by a space, those “names” are not required any more
and you call call it like

myFUNC(3,2,"A")

I see. Swift is definitely parting away from Obj-C…

Damn, talking about code perenity… So the old structure no longer works ?

[quote=279353:@Michel Bujardet] for( i=1 ; i<=10 ; i++)
{
printf("Hello, World!
");
}[/quote]

As of right now, using that format in Swift (officially still Swift 2.2)

results in

and I have read that “future version” is Swift3

not only that but the “++” operator is also going “bye-bye” in preference to +=

[quote=279347:@Dave S]not “required”

If you create a function like this

func myFUNC(x:Int, y:Int,z:String)

then YES they are required
and you would call it like this

myFUNC(3,y:2,z:"A")

note the first one is for some reason never required (although I believe THAT is changing in Swift3 as well)

but you can just as easily create it like this

func myFUNC(x:Int,_  y:Int,_ z:String)

by placing “_” followed by a space, those “names” are not required any more
and you call call it like

myFUNC(3,2,"A") [/quote]

It just struck me as an odd thing to put on the implementor of the method to make it optional to supply names
AFAIK even with names you still cant reorder them
Just an odd thing to do - either use named params & allow reordering them or dont & make them positional but this is a weird mish mash

Ouch…

Oh yes - stride and reverse make so much more sense… :S

[quote=279344:@Dave S]

for i in 1...10 { } for i in 1.stride(to:10, by: 2) { } for i in (10...1).reverse() { } for i in a...b { } [/quote]

Do you sometimes think that language developers just like to invent new syntax purely for the sake of inventing new syntax?