[2.4] AppendDelimited?

This forum is meant for questions and discussions about the X# language and tools
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

[2.4] AppendDelimited?

Post 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?
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

[2.3] AppendDelimited?

Post 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.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

[2.3] AppendDelimited?

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

[2.3] AppendDelimited?

Post 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 ;)
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

[2.3] AppendDelimited?

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

[2.3] AppendDelimited?

Post 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# :)
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

[2.3] AppendDelimited?

Post 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...
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

[2.3] AppendDelimited?

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

[2.3] AppendDelimited?

Post 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 ;)
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

[2.3] AppendDelimited?

Post by Chris »

robert wrote:In the team Chris is our guardian of readability.
:) :D :)
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply