The i-Technology Media!
Register | Log in
   
 
.NET  ·  AJAX  ·  CLOUD  ·  ECLIPSE  ·  FLEX  ·  OPEN WEB  ·  iPHONE  ·  JAVA  ·  LINUX  ·  OPEN SOURCE  ·  ORACLE  ·  PBDJ  ·  SEARCH  ·  SILVERLIGHT  ·  SOA  ·  VIRTUALIZATION  ·  WEB 2.0  ·  WIRELESS  ·  XML
Comments
Drool, Britannia? Is the UK Failing the Cloud?
By Roger Strukhoff
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Jan. 8, 2012 11:38 AM EST
read more & respond »
Cloud Expo on Google News
Did you read today's front page stories & breaking news?

Cloud Expo & Virtualization 2011 West
Keynotes
Oracle
Opening Keynote | An Enterprise Cloud for Business-Critical Applications
Abiquo
Day 2 Keynote | The Enterprise Cloud Tightrope - Balancing for Success
Akamai
Day 3 Keynote | The DNA of an Enterprise Cloud
DIAMOND SPONSOR:
Oracle
Many Clouds, Many Choices'Cloud
PLATINUM PLUS SPONSORS:
Abiquo
Enterprise Cloud Best Practices - Town Hall - Join the discussion…
PLATINUM SPONSORS:
Intel
Progressing Toward the Federated, Automated and Client-Aware Cloud
New Relic
How to build an app with Twitter-like throughput
Rackspace
Computing in the Cloud Era
GOLD SPONSORS:
Gale Technologies
Practical Cloud Migration
IBM
Re-think IT. Re-inventing Business.
Intel/McAfee
Identity Driven Security in the Cloud
PerspecSys
Hackers Hackers Everywhere, Is My Public Cloud That Safe?
Red Hat
Unlock the Value of the Cloud
SHI
Mission Critical Applications and the Cloud - Myth or Reality?
SoftLayer
Not Your Grandpa's Cloud
Terremark
Integrating Enterprise Clouds
VMware
Upgrade to a vCloud
POWER PANELS:
Cloud Expo Silicon Valley: CTO Power Panel
Cloud Expo Silicon Valley: CEO Power Panel
Cloud Expo Silicon Valley: Cloud SuperStars Panel
Cloud Expo Silicon Valley: CloudNOW Panel
Click For 2010 West
Event Webcasts
Cloud Expo & Virtualization 2011 East
DIAMOND SPONSOR:
Dell
Dell & VMware Deliver the Enterprise Hybrid Cloud
PLATINUM PLUS SPONSORS:
Abiquo
Are Financial Services Organizations Risking Security by Avoiding Cloud Computing?
Oracle
From Consolidation to Enterprise Private PaaS
PLATINUM SPONSORS:
Intel
Driving the Transformation to Next Generation Cloud Data Centers
Rackspace
The Inevitability of an Open Cloud
GOLD SPONSORS:
CA Technologies
Follow YOUR path to Cloud Computing
Interxion
Who Keeps the Cloud in the Air?
Microsoft
Patterns for Cloud Computing
PerspecSys
War in the Clouds: Are you ready?
ServiceMesh
The Big Win: Stop Playing Small-Ball with Your Cloud Strategy
Terremark
Evaluating Enterprise Clouds
Xiotech
Cloud Storage: Myths and Realities
POWER PANELS:
Cloud Expo New York: CTO Power Panel
Cloud Expo New York: CEO Power Panel
Cloud Expo New York: CMO Power Panel
Cloud Expo New York: Wrap-Up Power Panel
Click For 2010 West
Event Webcasts
Live Google News by SYS-CON!
Top Three Links You Must Click On


Tips & Tools
Bye Bye Clip Window; Hello Snippets
Increase .NET coding productivity

By: Yakov Werde
Sep. 13, 2010 09:00 AM

What Are Snippets?
Clips or snippets are pieces of code that are either difficult to remember or often used with minor tweaks. Developers look for ways to leverage their IDE to write code snippets once and then paste them into an editor whenever / wherever they are needed. In Classic the IDE facility is called the Clip Window. In the .NET IDE the facility is called Snippets. The process of creating and using Snippets in .NET is quite different from its Classic counterpart. The purpose of this article is to familiarize a Classic developer with the .NET IDE Snippet facility and help increase their .NET coding productivity by guiding them through the process of defining and using .NET code Snippets.

Classic Clips: A Review
Figure 1 shows the Classic Clip Window displaying two snippets. Table 1 summarizes the use and benefits of Classic Clips

Figure 1: Classic Clip Window

Introducing VS .NET Snippets
Visual Studio implements Snippets differently than Classic. Table 2 summarizes their capabilities and features

Predefined System Snippets
Out-of-the-box PowerBuilder contains a set of predefined System snippets. System snippets are located in the PowerBuilder installation folder tree. You can view and modify their source code as needed, but any changes you make will be lost when you upgrade your PowerBuilder IDE. As you can see from Figure 2, editor support for what used to be called "paste special à statement," the familiar control structures, is implemented as insert snippets. Figure 3: shows how to insert a system snippet from the menu system. Figure 4 shows a System snippet list in the editor.

Figure 2: System snippets

Figure 3: Inserting a system snippet

Figure 4: System snippet list in the editor

Placing a Snippet
You can use the Shortcut chords Ctrl-K, Ctrl-X or right-mouse button or Edit Menu to have the system present you with a list of snippets to choose from. Note from Figure 5 that you can choose from either developer or system snippets (when both are present).

Figure 5: Snippet Folders choice

When you select a snippet, the code is placed in the editor at the cursor location and any variables defined in the snippet are assigned their default values. Variables in the snippet are highlighted. Hovering the mouse over a variable shows their tooltip. This a cue for you to adjust the variable value as needed (see Figure 5a).

Figure 5a

Snippet Manager
The shell provides a snippet manager that you can use to add and delete snippet files from within the IDE. You can open it using the chords Ctrl-K, Ctrl-B or the Tools à Snippets Manager menu. Although you can't define new snippets using this utility, you can import snippets created by a fellow developer. Note there is no magic to this utility. You can just as easily copy or move files into a snippets folder using Windows Explorer. Exercise caution though as you can accidentally remove your System snippets! They are not moved to the Recycle Bin. Figure 6 shows the Snippets Manager.

Figure 6: Snippets Manager

Defining a Snippet
A real benefit of Snippets is that you can define and use your own code snippets to automate your own repetitive tasks or to support your memory when writing code. In this section I'll show you how to define a .NET snippet.

Snippets are defined as XML files with a .snippet file name extension. Their structure and content adhere to the Code Snippet XML schema located at http://msdn.microsoft.com/en-us/library/ms171418(v=VS.80).aspx

The snippets you define are stored in the C:\Users\<current user>\Documents\Sybase\PowerBuilder 12.0\PowerBuilder .NET\Code Snippets\PowerScript\My Script Snippets folder. As your collection of snippets grows, you can organize them into subfolders. The IDE shows your snippets by folder. You can easily navigate the folders to locate the snippet you want using the mouse or tab key. Alphabetic type ahead and keyboard selection is also supported.

Although, you can create and edit snippets by following the schema and entering valid XML using any text editor, by far the easiest way to get started writing snippets is by downloading and using a Snippet Editor. I found a great open source one from Bill McCarthy, a Microsoft MVP, at http://snippeteditor.codeplex.com/. Although the editor is MS Visual Studio-centric and doesn't see the isolated shell, I discovered a couple of workarounds that made it work with PowerBuilder. First, to allow access to the editor as part of my Visual Studio experience, I added it to my tools menu as an External Tool. Now I don't have to leave PB to access it. Figure 7 shows my Tools menu after adding the external tool.

Figure 7: Snippet Editor on Menu

Next, the Snippet Editor is MS centric and tied to the MS VS keys in the Registry. It automatically loads C# and VB snippets and doesn't see the isolated shell keys; I had to add PowerBuilder's My Snippets folder to the folder view. The tool provides an "Add Path" context menu item that supported my action. (Unfortunately it doesn't remember added paths, so you have to do this every time you use the tool.). Figure 8 shows my folder view after adding the folder.

Figure 8: PB User Snippets in Snippet Editor

Last, the editor only supports language attributes for Microsoft languages. Whenever you create a new snippet you will need to edit the generated snippet file with WordPad and change the language attribute of the Code element to PowerScript <Code Language="PowerScript". If you skip this step, PowerBuilder will not recognize the snippet and you won't see it listed it in the snippet choice list in the Painter. Fortunately, subsequent edits to the body of the snippet in the Editor don't revert the language designator change, so this is a one-time patch. (I dropped an email to the tool author asking him to add PowerScript support. The tool is open source; if you're a C# pro, you might consider modifying the code and submitting the change.)

Snippet Anatomy
Figure 9 shows the edit fields in the Snippet Editor and their effect on the Snippet choice list and resulting pasted code. Table 3 briefly explains each.

Figure 9: Annoted picture of Snippet Editor fields

Conclusion and Limitations
The product engineers have done a reasonable job of providing support for member body literal and object type Snippets with or without parameters. Once you spend a bit of time configuring your own snippets and getting used to working with them in the editor, you will find the Snippet feature is a beneficial productivity enhancement.

There are limitations in the current implementation that you should be aware of. First, there is no migration path for Classic clips into the .NET IDE. You'll have to redo all your Classic clips as Snippets. Copy and paste from Classic into the Snippet Editor should do the trick. (I added an action item to my ToDo list to build a conversion utility. Not sure when I'll get to it though.)

Next, the Sybase engineers have provided equivalent functionality to that in Classic without implementing the advanced capabilities present in the Snippet specification. For example, the specification provides for elements that allow you to specify which references and imports (usings) a code object needs - these do not work in PB. If your snippet code contains code objects in a namespace or assembly, you will have to add those references and usings manually.

The specification supports snippets in three scopes: (1) Class Declaration, snippets that define an entire class; (2) Member Declaration, snippets that define an event handler or function routine; and (3) Member Body, snippets inserted into existing member. Of the three, only member body snippets are supported. This is roughly equivalent to Classic clips.

I'd like to see tool support for imports and references; having it would make coding calls to methods in assemblies and web services easier; I'd be less prone to forgetting or using a reference. I'd also like to see support for Class and Member snippet definition. Having it would increase my productivity by making implementing common CCUOs as well as function and events in all object types into a template-generated activity.

Happy coding!

Listing 1

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>dwUpdate</Title>
<Author>eLearnIT LLC</Author>
<Description>Basic DW Update Block</Description>
<HelpUrl></HelpUrl>
<SnippetTypes />
<Keywords />
<Shortcut>updt</Shortcut>
</Header>
<Snippet>
<References />
<Imports />
<Declarations>
<Literal Editable="true">
<ID>Transaction</ID>
<Type>Transaction</Type>
<ToolTip>Transaction Object Reference Name</ToolTip>
<Default>SQLCA</Default>
<Function></Function>
</Literal>
</Declarations>
<Code Language="PowerScript" Kind="method body" Delimiter="$">
<![CDATA[if dw_1.Update( ) > 0 then
commit using $Transaction$;
else
rollback using $Transaction$;
end if

]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

Published Sep. 13, 2010— Reads 2,826
Copyright © 2010 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
About Yakov Werde
Yakov Werde, a 25 year IT industry veteran, is a member of TeamSybase and the newly formed Sybase Customer Evangelist Team. Yakov is a recognized author, speaker and trainer who has been designing and delivering PowerBuilder, .NET, EaServer, Web App Development, and Java training for over 14 years to corporate, military and government developers. Prior to discovering his aptitude as an educator, Yakov worked as an architect, project manager and application coder in the trenches of application software development. Yakov holds a Masters in Education with a specialty in instructional design for online learning from Capella University and a BS in math and computer science from Florida International University. Yakov, managing partner of eLearnIT LLC (www.elearnitonline.com), authors and delivers workshops and web based eLearning tutorials to guide professional developers toward PowerBuilder Classic and .NET mastery. Follow Yakov on Twitter as @eLearnPB

Add Your Feedback

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers

ADS BY GOOGLE

Breaking Java News
Tawsho Mining Inc. Announces Grant of Stock Options
Orbitz Worldwide Invests in Employee & Channel Learning with SumTotal Extended Enterprise Solution
AJC Expands Assistance to Greek Holocaust Survivors
Maxwell Systems Wins 2012 Constructech Residential Top Trusted Product Award for ProContractorMX Complete Construction Management Software
The Lanier Law Firm Announces California Patent Infringement Lawsuit for Atomic Precision Systems Against Intel, IBM, Others
NVHomes Announces Grand Opening of New Single Family Estate Homes at Riverwood at Ferry Point in Alexandria, VA
CSR™ Taps Anderson for Executive Vice President Role
Take Advantage of Haven's Spring Deals from Just GBP 79 at Selected Parks
Broadway Technology's CTO Joshua Walsky Named in Institutional Investor's Trading Technology Top 30

ADVERTISE   |   MAGAZINE SUBSCRIPTIONS   |   FREE BREAKING-NEWSLETTERS!   |   SYS-CON.TV   |   BLOG-N-PLAY!   |   WEBCAST   |   EDUCATION   |   RESEARCH

.NET Developer's Journal - .NETDJ   |   ColdFusion Developer's Journal - CFDJ   |   Eclipse Developer's Journal - EDJ   |   Enterprise Open Source Magazine - EOS
Open Web Developer's Journal - OPENWEB   |   iPhone Developer's Journal - iPHONE   |   Virtualization - Virtualization   |   Java Developer's Journal - JDJ   |   Linux.SYS-CON.com
PowerBuilder Developer's Journal - PBDJ   |   SEO / SEM Journal - SJ   |   SOAWorld Magazine - SOAWM   |   IT Solutions Guide - ITSG   |   Symbian Developer's Journal - SDJ
WebLogic Developer's Journal - WLDJ   |   WebSphere Journal - WJ   |   Wireless Business & Technology - WBT   |   XML-Journal - XMLJ   |   Internet Video - iTV
Flex Developer's Journal - Flex   |   AJAXWorld Magazine - AWM   |   Silverlight Developer's Journal - SLDJ   |   PHP.SYS-CON.com   |   Web 2.0 Journal - WEB2
Apache   |   CMS   |   CRM   |   HP   |   Oracle Journal   |   Perl   |   Python   |   Red Hat   |   Ruby on Rails   |   SAP   |   SaaS

SYS-CON MEDIA:   ABOUT US   |   CONTACT US   |   COMPANY NEWS   |   CAREERS   |   SITE MAP
SYS-CON EVENTS:   |  AJAXWorld Conference & Expo  |  iPhone Developer Summit  |  Cloud Computing Conference & Expo  |  SOA World Conference & Expo  |  Virtualization Conference & Expo
INTERNATIONAL SITES:   India  |  U.K.  |  Canada  |  Germany  |  France  |  Australia  |  Italy  |  Spain  |  Netherlands  |  Brazil  |  Belgium
 Terms of Use & Our Privacy Statement     About Newsfeeds / Video Feeds
Copyright ©1994-2008 SYS-CON Publications, Inc. All Rights Reserved. All marks are trademarks of SYS-CON Media.
Reproduction in whole or in part in any form or medium without express written permission of SYS-CON Publications, Inc. is prohibited.
 
close this window