fbpx
Welcome, Guest
Username: Password: Remember me
Share your code snippets, screen shots etc. here
  • Page:
  • 1
  • 2

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

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1222

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1225

  wriedmann's Avatar wriedmann Away Posts: 1549
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
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1227

  FFF's Avatar FFF Offline Posts: 571
+1 !

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

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1228

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1229

  wriedmann's Avatar wriedmann Away Posts: 1549
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)
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1230

  lumberjack's Avatar lumberjack Offline Posts: 454
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1231

  lumberjack's Avatar lumberjack Offline Posts: 454
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1234

  robert's Avatar robert Offline Posts: 973
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1235

  wriedmann's Avatar wriedmann Away Posts: 1549
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
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

Last edit: by wriedmann.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1236

  robert's Avatar robert Offline Posts: 973
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1237

  wriedmann's Avatar wriedmann Away Posts: 1549
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
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it
Attachments:

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

Last edit: by wriedmann.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1238

  lumberjack's Avatar lumberjack Offline Posts: 454
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1239

  wriedmann's Avatar wriedmann Away Posts: 1549
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
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1240

  lumberjack's Avatar lumberjack Offline Posts: 454
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1241

  robert's Avatar robert Offline Posts: 973
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1242

  lumberjack's Avatar lumberjack Offline Posts: 454
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1243

  robert's Avatar robert Offline Posts: 973
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1244

  Chris's Avatar Chris Offline Posts: 1149
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.

Snippets in VS 2017 RC .... some success .... 2 years 4 months ago #1246

  wriedmann's Avatar wriedmann Away Posts: 1549
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...)
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

Snippets in VS 2017 RC .... some success .... 2 years 3 months ago #1333

  robert's Avatar robert Offline Posts: 973
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:

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

Last edit: by robert.
  • Page:
  • 1
  • 2