xsharp.eu • [2.4] AppendDelimited?
Page 1 of 2

[2.4] AppendDelimited?

Posted: Tue Apr 14, 2020 8:15 pm
by FFF
Robert,
just had a look into source at
https://github.com/X-Sharp/XSharpPublic ... erver1.prg
Lines 189/190 have:

Code: Select all

			IF IsObject(oFSSource) .and. __Usual.ToObject(oFSSource) IS FileSpec  VAR oFS
				cSource := oFS:FullPath
Note the "VAR oFS".
Is this correct code?

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 6:58 am
by Chris
Hi Karl,

I was not aware of this syntax that the guys have implemented! Here's a sample:

Code: Select all

FUNCTION Start() AS VOID
	LOCAL oObject AS OBJECT
	oObject := 123
	IF oObject IS INT VAR nInt
		? nInt * 2
	END IF
RETURN
it just tells the compiler that if the var is indeed of the type we are checking for, to assign it to another var that is now strongly typed.

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 7:13 am
by robert
Chris,
Correct. I originally wanted to implement it like this:

Code: Select all

IF oObject IS INT nInt
but you indicated that that was "too much C#" so I added the VAR keyword as you requested:

Code: Select all

IF oObject IS INT VAR nInt
The compiler emits something like this:

Code: Select all

IF oObject IS INT 
   VAR nInt := (INT) oObject
- The variable is automatically typed as the type after the IS clause
- The visibility of the variable is inside the IF branch only
- Of course you can do a similar check in an ELSEIF for another type

Robert

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 7:21 am
by FFF
Chris wrote:Hi Karl,
I was not aware of this syntax that the guys have implemented! Here's a sample:

Code: Select all

FUNCTION Start() AS VOID
	LOCAL oObject AS OBJECT
	oObject := 123
	IF oObject IS INT VAR nInt
		? nInt * 2
	END IF
RETURN
it just tells the compiler that if the var is indeed of the type we are checking for, to assign it to another var that is now strongly typed.
Ah, thx. Frankly spoken, i'd like it removed. There's no hint in the syntax what happens behind the scene, especially no assignment...
As you wrote to my other question: if it would spare a lot of typing...

The unfortunate thing is, that i now still don't see, why

Code: Select all

FUNCTION csf2dbf() AS LOGIC
	LOCAL cPfad, cSource, cDbf AS STRING
	LOCAL lOK := FALSE AS LOGIC
	LOCAL oDB AS DbServer
	cPfad:= "C:DB"
	cSource:= "kv_lieferad.csv"
	cDbf:= "kv_Lieferad.dbf"
	oDB:= DbServer{cPfad+cDbf}
?	lOK := oDB:AppendDelimited(cSource, ",")
RETURN  lOK

produces no error, but returns ".F." and the target stays empty ;)

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 7:23 am
by robert
Karl,

The DELIM and SDF RDDs are not there in the current build (they are mentioned in the "unsupported features" section in the help file). The good news is that I have implemented them and they will be included in the next build.

And w.r.t. the feature: you do not have to use it.

Robert

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 7:24 am
by Chris
Robert,
robert wrote:Chris,
Correct. I originally wanted to implement it like this:

Code: Select all

IF oObject IS INT nInt
but you indicated that that was "too much C#" so I added the VAR keyword as you requested:
Ah right, I remember now! And yeah, I agree with myself, the original syntax was way too much c# :)

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 7:33 am
by FFF
robert wrote:The DELIM and SDF RDDs are not there in the current build (they are mentioned in the "unsupported features" section in the help file). The good news is that I have implemented them and they will be included in the next build.
Ah, thx, that explains my problem... Looking forward to see it, yesterday, pls ;)
And w.r.t. the feature: you do not have to use it.
Well, that's not the point. One of imho XBase style languages biggest advantages always was its clear readability. For almost anything you don't have to have "arcane" knowlegde to understand, what is written. That is a big value in itself to keep...

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 8:15 am
by robert
Karl,
FFF wrote:
And w.r.t. the feature: you do not have to use it.
Well, that's not the point. One of imho XBase style languages biggest advantages always was its clear readability. For almost anything you don't have to have "arcane" knowlegde to understand, what is written. That is a big value in itself to keep...
I agree that the language should be readable. In the team Chris is our guardian of readability. He has already used his veto for quite some features and/or syntaxes, believe me.
But that should not stop us from adding features that make the product more usable or that increase productivity.
We get requests from users for features like this. Another similar feature that we have added (and that you almost certainly don't like) is declaring and passing an out variable at the same time.
Since features like this are fairly easy to implement (the underlying Roslyn platform already supports it) we decided to add that.
So this works now too

Code: Select all

FUNCTION Start AS VOID
LOCAL strNumber AS STRING
strNumber := "1234"
IF Int32.TryParse(strNumber, OUT VAR iResult)
    ? iResult
ENDIF        
IF Int32.TryParse(strNumber, OUT iResult2 AS Int32)
    ? iResult2
ENDIF
RETURN

Robert

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 8:36 am
by FFF
robert wrote:(and that you almost certainly don't like) is declaring and passing an out variable at the same time.
....

Code: Select all

FUNCTION Start AS VOID
LOCAL strNumber AS STRING
strNumber := "1234"
IF Int32.TryParse(strNumber, OUT VAR iResult)
    ? iResult
ENDIF        
IF Int32.TryParse(strNumber, OUT iResult2 AS Int32)
    ? iResult2
ENDIF
RETURN
FTR, no problem with this. With almost no knowldege about coding, i can understand, "i have a string and try to use it as a number"
I'm not sure i would use it, but one can understand what happens.

But i agree, it's always a fine line and certainly not easy to decide. Glad you are a balanced team ;)

[2.3] AppendDelimited?

Posted: Wed Apr 15, 2020 2:02 pm
by Chris
robert wrote:In the team Chris is our guardian of readability.
:) :D :)