fbpx
× Share your code snippets, screen shots etc. here

Snippets in VS 2017 RC .... some success ....

More
1 year 11 months ago #1 by Phil Hepburn
Snippets in VS 2017 RC .... some success .... was created by Phil Hepburn
Hi guys,

Well, it may not be possible (yet) to add our own snippets - BUT - I feel I am well on my way to be able to easily tell others how to do it when we get the newer versions of the VS 2017 integration.

The free download tool makes it quite easy to be able to ignore the XML script, as these images show :-



and when the snippet is inserted it looks like this :-



and this :-



Oh! the big gotcha seems to be that we need to close and re-open the version of VS 2017 I currently have - then the new snippet shows up.

Here is the folder choice list :-



Oh! - by the way, I am NOT doing this to compete with the #command efforts - just so we know how to do it as we will need other snippets too, and I may even be able to get the snippet to take parameters as well, a bit like the pre-processor approach.

So soon we may even have a choice of three ways, hand code, #command, and also snippet.
Hope this interests ;-0)

Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #2 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Snippets in VS 2017 RC .... some success ....
Hi Phil,

So soon we may even have a choice of three ways, hand code, #command, and also snippet.


Since I'm using XIDE, I have built my own snippets.

But I don't think snippets are a solution to the "properties" problem like the preprocessor.
Snippets are inserted in the code and this code is visible and is "clogging" the editor with over and over repeated code.
I agree the in the backgrounbd this code is needed, but I don't like to see more than one readable line of it.
The needed code should be generated in the background (like auto properties generate an invisible variable). If you need to see it for diagnose, it is another thing ( I have looked at Clippers .PPO files very few times).

We have to write less code possible to get things done, and snippets go to the other direction.

Wolfgang

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #3 by Karl Faller
Replied by Karl Faller on topic Snippets in VS 2017 RC .... some success ....
+1 !

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #4 by Phil Hepburn
Replied by Phil Hepburn on topic Snippets in VS 2017 RC .... some success ....
Hi Wolfgang,

I tend to agree with your analysis ;-0)

However, like you I also wish to be able to create and use snippets, but from with VS.

I have a feeling that we may find quite a few nice and useful ways to create and use #commands in our general coding. Maybe we could run a monthly competition - you know, #command of the month award !!!

Is the idea that we can each post our #commands in the Examples part of the public Forum ? So we can copy and paste ?

How easy will it be to have two forms of #command, one with and one without the change Notification method call?

Have a nice day,
Phil.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #5 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Snippets in VS 2017 RC .... some success ....
Hi Phil,

yes, I agree with you <g>. Sharing #Command snippets is a great idea!

I'm looking forward to the new compiler version where this will be possible.

And even if I don't use the VS monster (sorry, could not resist <g>), I agree that snippets are a very important thing in VS.

Thank to the extension interface in XIDE I was able to build a textblock interface into it, and a textblock like this:
begin namespace {DefaultNamespace}

class {Filename}

end class

end namespace

works very well when starting a new class.

Wolfgang

P.S. of course I'm willing to share the source of this plugin (that is far from being finished)

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #6 by Johan Nel
Replied by Johan Nel on topic Snippets in VS 2017 RC .... some success ....
Phil,

dr philip h. hepburn wrote: Hi Wolfgang,
How easy will it be to have two forms of #command, one with and one without the change Notification method call?


Quite easy

Copy and paste the #command and add CHANGE NOTIFY. Obviously in the original #command the OnPropertyChanged method need to be removed.
#command PROPERTY <n> AS <t> GETSET <v> =>;
PROPERTY <n> AS <t>;;
GET;;
RETURN SELF:<v>;;
END GET;;
SET;;
IF SELF:<v> <> VALUE
SELF:<v> := VALUE;;
ENDIF;;
END SET;;
END PROPERTY
#command PROPERTY <n> AS <t> GETSET <v> NOTIFY CHANGE =>;
PROPERTY <n> AS <t>;;
GET;;
RETURN SELF:<v>;;
END GET;;
SET;;
IF SELF:<v> <> VALUE;;
SELF:<v> := VALUE;;
SELF:NotifyPropertyChanged(<"n">);;
ENDIF;;
END SET;;
END PROPERTY

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #7 by Johan Nel
Replied by Johan Nel on topic Snippets in VS 2017 RC .... some success ....
Ok,
As I hate this webinterface not going to go into the details, but one can easily change the #command to cater for various requirements:

PROPERTY x AS INT GET _x
PROPERTY x AS INT SET _x
PROPERTY x AS INT SET _x NOTIFY CHANGE

Just remove the non-required pieces of the command translation.

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #8 by Robert van der Hulst
Replied by Robert van der Hulst on topic Snippets in VS 2017 RC .... some success ....
Jac,

You probably know this already, but the single line syntax for properties is already supported by the compiler:
PROPERTY x AS INT GET _x
PROPERTY x AS INT SET _x := Value
PROPERTY x AS INT GET _x SET _x := Value

The GET clause expects an expression, the SET clause expects an expression list.

Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago - 1 year 11 months ago #9 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Snippets in VS 2017 RC .... some success ....
Hi Robert,

means this we can use the command preprocessor directive on X# Beta 9?

I have now tried the following code (on a single line):
#command PROPERTY <n> AS <t> GETSET <v> => ; property <n> as <t>;;; get;;; return self:<v>;;; end get;;; set;;; if self:<v> <> value;;; self:<v> := value;;; endif;;; end set;;; end property
class File1      
  protect _cCmdProp as string

property myCmdProp as string GETSET _cCmdProp

end class

but it gives the error
error XS9002: Parser: mismatched input 'GETSET'	16,30	File1.prg	PropertyTest

Wolfgang
Last edit: 1 year 11 months ago by Wolfgang Riedmann.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #10 by Robert van der Hulst
Replied by Robert van der Hulst on topic Snippets in VS 2017 RC .... some success ....
Wolfgang,

NO. The single line property syntax is built into the compiler.
You can expect (partial?) UDC support in beta 10.

But in stead of writing (using a UDC)
PROPERTY myCmdProp AS String GETSET _cCmdProp
you can already write (using built in syntax)
PROPERTY myCmdProp AS String GET _cCmdProp SET _cCmdProp := Value
This does not need END GET, END SET and END PROPERTY

Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago - 1 year 11 months ago #11 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Snippets in VS 2017 RC .... some success ....
Hi Robert,

this is really great, thank you very much! It will save a lot of code and keep the code cleaner at the same moment.

I have now tried something different:
property mySuperProp as string get self:_Get<string>() set self:_Set( value )

and it seems to work. Unfortunately I have to specify the
self:_Get<string>()

otherwise I have a compiler error.

It is the same in the in the extended version of this property:
property mySuperPropX as string 
  get 
    return self:_Get<string>() 
  end get
  set 
    self:_Set( value )
  end set
end property

IMHO the compiler should be able to understand the type of return code. Or I'm making a wrong assumption?

Wolfgang

P.S. my test code is attached as XIDE export file
Attachments:
Last edit: 1 year 11 months ago by Wolfgang Riedmann.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #12 by Johan Nel
Replied by Johan Nel on topic Snippets in VS 2017 RC .... some success ....
Wolfgang,

Wolfgang Riedmann wrote: Hi Robert,

means this we can use the command preprocessor directive on X# Beta 9?

I have now tried the following code (on a single line):

#command PROPERTY <n> AS <t> GETSET <v> => ; property <n> as <t>;;; get;;; return self:<v>;;; end get;;; set;;; if self:<v> <> value;;; self:<v> := value;;; endif;;; end set;;; end property
class File1      
  protect _cCmdProp as string

property myCmdProp as string GETSET _cCmdProp

end class

but it gives the error
error XS9002: Parser: mismatched input 'GETSET'	16,30	File1.prg	PropertyTest

Wolfgang

You state you have the #command on a single line, then you have too many ";" there should only be 1 between statements and none after the =>

Robert indicated #command will be available around Cologne except if I missed something.

Jack

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #13 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Snippets in VS 2017 RC .... some success ....
Hi Jack,

this can be.... But since we don't have the preprocessor I cannot try it out yet.

I can wait, of course. The preprocessor will be a really cool thing, I'm looking forward to use it.

Really, fun has returned to programming thanks to the "Gang of Four"!

In the meantime I will use the short property syntax - I like it very much!

Wolfgang

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #14 by Johan Nel
Replied by Johan Nel on topic Snippets in VS 2017 RC .... some success ....
Hi Robert,

Robert van der Hulst wrote: Jac,

You probably know this already, but the single line syntax for properties is already supported by the compiler:
The GET clause expects an expression, the SET clause expects an expression list.


No I have not known it, well done, good to know. Must have missed it in the "whats new" section.

Regards,

Jack

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #15 by Robert van der Hulst
Replied by Robert van der Hulst on topic Snippets in VS 2017 RC .... some success ....
Jack,

This was probably never mentioned in the readme, since the single line property syntax is also supported b Vulcan.

You can see the EBNF notation for the property on:
http://www.xsharp.info/help/property.html

Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #16 by Johan Nel
Replied by Johan Nel on topic Snippets in VS 2017 RC .... some success ....
Thanks Robert,

Robert van der Hulst wrote: Jack,
This was probably never mentioned in the readme, since the single line property syntax is also supported b Vulcan.
You can see the EBNF notation for the property on:
http://www.xsharp.info/help/property.html
Robert

If I remember correctly the #command single line was initially shown before PPOPERTY was available in Vulcan as wrapper to ACCESS/ASSIGN to align it with the then to be released PROPERTY.

The #command was done to not have to GET _var SET _var := VALUE, but shorten it to GETSET _var.

Although thus not 100% needed for a one liner property, I still think the concept of the pre-processor is a beauty and set the Clipper based dialects far ahead of the rest of the XBase pack.

It is however good to have a discussion around it to make people aware of the power that it brings to the language. We can "emulate" many other dialect syntax that the compiler does not understand yet to produce meaningful and useful code.

Jack

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #17 by Robert van der Hulst
Replied by Robert van der Hulst on topic Snippets in VS 2017 RC .... some success ....
Jack,

You are absolutely right that having a pre-processor adds a lot of power to a language.
I think that we can emulate 99% of the FoxPro syntax with the preprocessor as well.

I remember in the past, many years ago in 1993, that there was a product called the "CA-Clipper Compiler Kit for dBase IV". This product, written by Matt Whelan was using UDCs to convert dBase IV code to functions, which were then supplied in the form of a special library.

Most likely I still have a version of that (probably on 5 1/4 floppy disks), so I can have a look and use similar UDCs when we are going to add the FoxPro support.

Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #18 by Chris Pyrgas
Replied by Chris Pyrgas on topic Snippets in VS 2017 RC .... some success ....
Hi Wolfgang,

What you are looking for, is (generic) type inference based on the return type of the method, here's a simplified version of your code:

FUNCTION Start() AS VOID
LOCAL s AS STRING
s := TestClass.GenericMethod<STRING>() // OK
s := TestClass.GenericMethod() // error

CLASS TestClass
STATIC METHOD GenericMethod<T>() AS T
RETURN Default(T)
END CLASS

here you ask the compiler to figure out that the generic argument type of the method is STRING, because the result of that method is being assigned to a STRING var. While I agree that (in this case) it looks straightforward, type inference on return type is not supported by design (it's the same as in c#). Here is a discussion about this:

stackoverflow.com/questions/3203643/gene...n-types-inferred-why

Chris

ps. please don't shoot the messenger ;-)

XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #19 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Snippets in VS 2017 RC .... some success ....
Hi Chris,

thank you very much!

In the meantime I'll write the short form
property mySuperProp as string get self:_Get<string>() set self:_Set( value )

until the preprocessor will be available.

After I'll use it to build the correct code.

Wolfgang

P.S. the only person I would like to shoot sometimes is myself when I'm doing something really stupid (you know several samples...)

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago - 1 year 10 months ago #20 by Robert van der Hulst
Replied by Robert van der Hulst on topic Snippets in VS 2017 RC .... some success ....
Jack,

I tested one of your snippets with the new UDC support and the result is below;



You can see:
- UDC definition is recognized and colored in the preprocessor color
- UDC usage is recognized ans colored as keyword (especially the GETSET, NOTIFY and CHANGE words which are not normal keywords)
- The editor shows the difference between the statement separator semi colon (which is part of the UDC) and the line continuation semi colon, so they are both colored in a different color!
And in the image below you see the preprocessor output:




Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.
Attachments:
Last edit: 1 year 10 months ago by Robert van der Hulst.

Please Log in or Create an account to join the conversation.