. .

st4u

ST 4U 203: Scratch Editions in Envy

March 7, 2012 9:18:28.076

Today's Smalltalk 4 You looks at "scratch" editions in VA Smalltalk. If you just grab an application and start coding, it's what you get - and today we'll look at what that means. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

ENVY.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll look at what a "scratch" edition in VA Smalltalk means. Recall that ENVY tracks every change you make in VA; that means that a version of your code always lands in the repository. So if you don't create a new edition, one gets created for you. Make a small change in some application:

Scratched

You'll get prompted about creating a scratch edition. That's simply a new edition you haven't named. Go ahead and do so; you'll see this:

Scratched

Now all you need to do is tell ENVY to make that a new edition:

New Edition

And you'll have a new "clean" edition to work with.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u203-iPhone.m4v ( Size: 2497262 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 202: XML Parsing in Pharo

March 5, 2012 8:54:22.512

Today's Smalltalk 4 You looks at using XML in Pharo Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

xml

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Technorati Tags: , ,

Enclosures:
[st4u202-iPhone.m4v ( Size: 4520467 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 201: Using the Case Statement

March 2, 2012 11:09:21.915

Today's Smalltalk 4 You looks at using our simple case statement class from last time. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

case statement.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll make use of the case statement code we built last time. Here's the workspace we'll use:


dict := Dictionary new.
dict at: 1 put: [Transcript show: 'This is One'].
dict at: 2 put: [Transcript show: 'This is Two'].

case := CaseStatement new.
case addAll: dict.
case caseAt: 1.
case caseAt: 2.
case caseAt: 3.

case removeCase: 2.
case caseAt: 2.


That creates a simple case statement with two cases (and at the end, removes one of them). Try the first three lines after defining the dictionary and adding it to the CaseStatement - you should see this in the Transcript:

Case Statement

Now execute the removal, and try the last line:

Case Statement

After removing the second case, we get the default case when trying it (as expected). That's it - we now have a working Case Statement object in Smalltalk. Next time you run into someone asking about one, you'll have it

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u201-iPhone.m4v ( Size: 3579475 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 200: A Case Statement in Smalltalk

February 29, 2012 10:59:24.463

Today's Smalltalk 4 You looks at implementing a case statement construct in VA Smalltalk. If you would like to download the code, links are below, in the walkthrough section. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Case Statement.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll build a simple case statement class in VA Smalltalk. Why? People are often surprised that Smalltalk does not have one, so building one is a good way of showing how Smalltalk works to a new user, while implementing a concept that's familiar to them. To get started, define a new class:


Object subclass: #CaseStatement
    instanceVariableNames: 'cases defaultCase '
    classVariableNames: ''
    poolDictionaries: ''



The cases will be stored in a dictionary, and the default case will be held in the defaultCase variable. In this example, we'll default that to a simple Transcript write. Next, let's add the instance creation code:


addAll: associationsOrDictionary
	^self addAll: associationsOrDictionary default: self simpleDefaultCase.

addAll: associationsOrDictionary default: default
	^self new addAll: associationsOrDictionary default: default

Here we allow for the definition of a default case, and for the inbound cases to be either a dictionary or a collection of associations. We'll see how that gets handled in the instance code:


addAll: associationsOrDictionary default: default
	|associations |
	
	associations := associationsOrDictionary isDictionary
		ifTrue: [associationsOrDictionary associations]
		ifFalse: [associationsOrDictionary].
	associations do: [:each | self addCase: each].
	defaultCase := default

Note the conversion of string keys to symbols - that ensures that we have unique keys. For the values, we simply assume any object that responds to #value. It'll probably be a block, but that's not all that could be done there. Now let's look at the execution:


caseAt: keyName
	"execute the corresponding value"
	
	| key val |
	
	key := keyName isString
		ifTrue: [keyName asSymbol]
		ifFalse: [keyName].
		
	val := self cases at: key ifAbsent: self defaultCase.
	^val value

Again, we convert the key if necessary, then do a lookup. If that fails, we simply use the default case. Finally, we send #value to the looked up case. That's it - we now have a case statement in Smalltalk.

Want the code? Download it here.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u200-iPhone.m4v ( Size: 5173702 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 199: HTTP in Pharo

February 27, 2012 10:33:43.866

Today's Smalltalk 4 You looks at using HTTP in Pharo Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

HTTP

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Technorati Tags: , ,

Enclosures:
[st4u199-iPhone.m4v ( Size: 2976117 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 198: Raising Exceptions in VA Smalltalk

February 24, 2012 7:47:17.524

Today's Smalltalk 4 You looks at raising exceptions in VA Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Exceptions.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll take a look at raising exceptions (either your own or existing ones already defined) in VA Smalltalk. We'll use a somewhat artificial example to demonstrate:


var1 := 10.
var2 := '2'.
(var1 isString or: [var2 isString])
  ifTrue: [MessageNotUnderstood signal: 'Cannot Add Strings']
  ifFalse: [var1 + var2].



This code raises the MessageNotUnderstood exception when it sees that we are trying to add a string to a number. The larger point is that this is how you raise an exception in VA (or most other Smalltalks) - see class Exception for the full range of API options.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u198-iPhone.m4v ( Size: 3535827 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 197: A Simple HTTP Server in VA Smalltalk

February 22, 2012 7:40:27.519

Today's Smalltalk 4 You looks at implementing a very simple HTTP server in VA Smalltalk. If you do this yourself, you would actually want to create some objects, not just use the code snippet below. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

HTTP Server.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll take a look at setting up a simple HTTP server in VA Smalltalk. Bear in mind that for any "real" task you would want to create some classes of your own; this example will be enough to get you started. The code you'll want to use is below:


| server handler result |
handler := DirectedMessage
	receiver: 
		[:request :response| |htmlStream htmlResponse|
			htmlStream := WriteStream
			on: (Locale current preferredStringClass new: 128).
			htmlStream nextPutAll: '
'.
			request header sstHttpStringOn: htmlStream.
			htmlStream nextPutAll: '
'. htmlResponse := htmlStream contents. response header: (SstHttpResponseHeader new status: SstHttpConstants::HttpOk; version: request header version; contentLength: htmlResponse size; yourself); contents: htmlResponse; yourself] selector: #value:value:. (result := (server := SstBasicServer new) addHandlerUrl: 'http://localhost:9988') isSstError ifTrue: [result raise]. server requestHandler: handler. (result := server startUp) isSstError ifTrue: [result raise]. server inspect "-- When finished, send #shutDown"

This code does a couple of things. First, it uses DirectedMessage to set up a response handler - something to deal with each inbound request. In our case, it's a simple block that spits out some basic header type information as the body of the response. This is the part where you would want to customize; it's pretty easy to see how you could generalize this example for some ad hoc application status reporting

After that, we set up the actual server as an instance of SstBasicServer. Again, for an actual application, you'll want to create your own class for the server. In our case, we specify the port, some basic error handling (note the use of #isSstError), and start the server. As with HTTP client usage, we use #startUp - and eventually, when we want to shut it down, #shutDown.

Execute the code above - you should see something like this:

server

Now, open up a browser on your server (assuming you are running it now), and you should see something like this:

browse

Finally, using the workspace attached to the inspector, send #shutDown to the server - you should see something like this:

shutdown

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u197-iPhone.m4v ( Size: 5909667 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 196: Raising Exceptions in VisualWorks

February 20, 2012 11:09:40.691

Today's Smalltalk 4 You looks at using exceptions (raising them) in VisualWorks Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Exceptions

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Technorati Tags: , ,

Enclosures:
[st4u196-iPhone.m4v ( Size: 3916412 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 195: URL encode/decode in VA Smalltalk

February 17, 2012 9:28:48.902

Today's Smalltalk 4 You looks at url encoding and decoding in VA Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

url encoding.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll take a look at url encoding and decoding in VA Smalltalk. When making HTTP requests and posts, it's quite common to have to deal with encoded content. Fortunately, it's easy to do in VA. To Encode, we'll use an url:


"encode an url"
url := 'http://www.jarober.com/blog/blogView?entry=3506669370'.
encoded := url sstUrlEncode.
^encoded. 

'http://www.jarober.com/blog/blogView?entry=3506669370'


You can see the encoded text right there. Now the reverse - decoding an encoded string:


"decode"
decoded := encoded sstUrlDecodeQueryComponent.
^decoded

 'http://www.jarober.com/blog/blogView?entry=3506669370'



And there's the result, back in its original form. That's all there is to it.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u195-iPhone.m4v ( Size: 2646996 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 194: HTTP Queries in VA Smalltalk

February 15, 2012 11:29:38.719

Today's Smalltalk 4 You looks at client level HTTP again in VA Smalltalk - specifically, how to make such usage simpler. We also take a brief look at using proxy servers. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

HTTP Get.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll go back to HTTP queries in VA Smalltalk. As it happens, there's a simpler way to do queries than getting the client, starting it up, and shutting it down. Instead of this:


"Set up a client for http, execute a request"
client := (SstHttpClient  forTransportScheme: 'http') startUp.
response := 
	[client get: 'http://www.jarober.com']
	ensure: [client shutDown].
^response.

We can do this:


"shortcuts"
url := 'http://www.jarober.com/'.
response := url sstAsUrl fetch.
^response.

If you trace through the execution, you'll see that it does the same thing as the more complex looking code - but it's a whole lot simpler to use. Once you do that, you should see something like this:

HTTP Query

We can't really demonstrate proxy server usage, as the network used here doesn't have that. However, it's pretty straightforward. Simply use the following:


"proxy setup"
(SstTransport configurationRegistry at: 'httpl')
proxyUrl: ('http://proxy.myco.com:8080') sstAsUrl.

and then execute requests normally - you'll then be using your proxy server.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u194-iPhone.m4v ( Size: 4607491 )]

posted by James Robertson

 Share Tweet This

Previous Next (554 total)