C# declaration style in X#

This forum is meant for questions and discussions about the X# language and tools
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

C# declaration style in X#

Post by Jamal »

Is it possible to add C# declaration style where the type precedes the variable - sometime in the future?

For example:

MyClass x := MyClass{}

which behaves like the X# style:
LOCAL x := MyClass{} AS MyClass

or

int y := 0

which behaves as:

LOCAL y := 0 as int

I like the C# short style.

Jamal
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

C# declaration style in X#

Post by robert »

Jamal,

We already have

var x := MyClass{}

Adding C# style syntax is probably technically possible but I wonder how many people would really want that?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
FFF
Posts: 1521
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

C# declaration style in X#

Post by FFF »

Write
VAR myClass := myClass{}
Or
VAR i:= 0

Short enough?
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
FoxProMatt

C# declaration style in X#

Post by FoxProMatt »

If the matter is allowing (or supporting) that one can make an explicit reference to the Type rather than using the VAR keyword, I'd vote to add support for this.

One, it would make X# even more C#-like, and
Two, in the C# world, many people poo-pooh the use of the "var" keyword in favor of the explicit Type reference.

Code: Select all

var x := MyClass{}

Code: Select all

MyClass x := MyClass{}
Simply allow both.
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

C# declaration style in X#

Post by Jamal »

Hi Robert,

But VAR declares an implied local, which might be good, but it is ambiguous. I prefer strongly typed declarations.

This may be exciting for people who are familiar with C# (like me :woohoo: )

Jamal
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

C# declaration style in X#

Post by Chris »

Hi Jamal,

I think you've been infected with the well known nasty c# virus! But it's OK, nowadays it can be healed! Best medicine is to stay away from it for a couple weeks and do only xBase programming.

(just kidding of course!!!)

(hmm, well, mostly...:))
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

C# declaration style in X#

Post by Jamal »

Hi Chris,

I think that X# is a VARient of the C# virus :evil:
But that is a good thing!

Jamal
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

C# declaration style in X#

Post by Chris »

Hehe, OK, point taken!

Btw, I tried my best to prevent VAR from being implemented in X# but I failed :)
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

C# declaration style in X#

Post by robert »

Chris,

Take this example.

Code: Select all

LOCAL oDev   := GetDevelopers() as IList<Developer>
LOCAL oC        := GetCountries() as IList<Country>
LOCAL oAll   := FROM D       IN oDev  ;
                JOIN C       IN oC ON D:Country EQUALS C:Name   ;
                ORDERBY D:LastName  ;
                SELECT CLASS {D:Name, D:Country, C:Region}     // Anonymous class !
What should the type of oAll be ?
I think using VAR oAll make a lot of sense here.

Btw the answer is (the last time I checked)

Code: Select all

 IOrderedEnumerable<<>f__AnonymousType0<Developer,Country,String>>


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

C# declaration style in X#

Post by mainhatten »

Matt Slay wrote:If the matter is allowing (or supporting) that one can make an explicit reference to the Type rather than using the VAR keyword, I'd vote to add support for this.

One, it would make X# even more C#-like, and
Two, in the C# world, many people poo-pooh the use of the "var" keyword in favor of the explicit Type reference.
Simply allow both.
I think personal preference has its place - but there is already for me a lot of ambivalence (plus uncetrainty as I am learning) on how to human-parse X#. For a single dev no problem, he can go to the next mirror and blame the dev, but in team effort I'd argue for more lenience only after a tool similar to vfp "Beautify" is introduced. Every coder can have their own idea of "neat" or readable code applied to new version from source control and must adhere to company standard during check in - best done via automatic call.
Comparing versions might look different from personal pref, but reading speed while coding is not artificially lowered when working on the code from THE GUY WITH THE CAPSLOCK PROBLEM WHO CODES TOTALLY DIFFERENT FROM MY STYLE:::

;-)
Post Reply