. .

st4u

ST 4U 193: Raising Exceptions in Pharo

February 13, 2012 11:13:17.510

Today's Smalltalk 4 You looks at using exceptions (raising them) 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:

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:
[st4u193-iPhone.m4v ( Size: 3796638 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 192: Http Get in VA Smalltalk

February 10, 2012 12:20:39.339

Today's Smalltalk 4 You looks at client level HTTP (specifically, get) 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:

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 take a look at doing HTTP queries in VA Smalltalk. To get started, you'll need to load the SST (server Smalltalk) packages for HTTP:

Load HTTP Support

All we'll be looking at today is the client side of HTTP, but you need to server package to get that in the image. Once you do that, take a look at class SstHttpClient:

Http Client

A quick look at the APIs makes it appear that all you need to do is create an instance and start using #get:, but it's a bit more involved than that:

Create a client and query

Here's the code:


"set up a client for http requests and execute a request"
client := (SstHttpClient forTransportScheme: 'http') startUp.


That sets up a client for usage. Notice that we needed to specify http (you could also specify https - we'll get into things like proxy servers in the future). next, you issue the request. Once you've "started" the client, you can continue to issue requests:


response := client get: 'http://www.yahoo.com'.

if you inspect the result, you'll see the full response object:

HTTP Response

To get the content, simply send #asString to that piece of the response.

Finally, when you are finished with the client, shut it down:


client 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:
[st4u192-iPhone.m4v ( Size: 5283289 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 191: Generating Accessors in VA Smalltalk

February 8, 2012 8:33:01.414

Today's Smalltalk 4 You looks at generating accessors with the VA Smalltalk toolset. 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:

Accessors.

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 something you need to do all the time in Smalltalk - generate accessor methods. In VA Smalltalk, you'll want to switch to the Trailblazer browsers to do that (see this tutorial for more on that). To start with, select your class in the browser, and then pop up the context menu - pick Show>>Instance Variables:

Show Instance Variables

Next, select one of the variables, and use the context menu again:

Generate Accessors

For each one selected, you'll get prompted for the name of the argument for the setter method:

Setter

And that's it - you now have accessing methods:

Accessors

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:
[st4u191-iPhone.m4v ( Size: 3426227 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 190: Security Libraries in VW 7.8 NC?

February 6, 2012 0:00:40.799

Today's Smalltalk 4 You looks at using the (no longer included) encryption libraries in VW 7.8 NC. To do that, you'll need to have a copy of VW 7.7.1 installed, so that you can copy the relevant libraries over. 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:

Security Libraries

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:
[st4u190-iPhone.m4v ( Size: 3938494 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 189: Reading the Command Line in VA Smalltalk

February 3, 2012 12:00:41.632

Today's Smalltalk 4 You looks at how your application can read the command line that started 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:

command line.

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 continue looking at the command line for VA Smalltalk, focusing on reading the command line at runtime. Here's a command line with a (presumed) application argument, -k:

Starting VA

VA pays no attention that argument, but what if we want our application to do something with it? Simply do the following:


commandLine := System commandLine.

Try that in a workspace, and inspect the results - you should see something like this:

Starting VA

All arguments and argument names will be strings; you'll need to parse them yourself. It's pretty easy though - you can set up a simple streaming facility for that easily.

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:
[st4u189-iPhone.m4v ( Size: 3277889 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 188: VA Smalltalk Command Line Options

February 1, 2012 12:03:36.669

Today's Smalltalk 4 You looks at starting VA Smalltalk up from the command line. 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:

Command Line.

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 starting VA Smalltalk from the command line. While you would normally start up your development environment from an icon or the start menu on Windows, you might deploy to Linux, or need to set up a Windows "cron" job. The simplest way to start the environment up is to just run the VM:

Starting VA

By default, the VM will look for abt.icx in the current directory, and start that. What if you want to start a different image? Use the -i argument:

Starting VA

Note that we omitted the extension .icx; you need to do that, as the VM will append it itself. There are a lot of command line options you can use to control startup options (memory usage, logging - tons of stuff) - you'll want to examine the docs in detail for that:

Command Line 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:
[st4u188-iPhone.m4v ( Size: 4138408 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 187: Exploring Processes in Pharo

January 30, 2012 10:46:13.331

Today's Smalltalk 4 You looks at processes in Pharo - specifically, some of the tools and APIs that make working with them easier. 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:

Processes

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:
[st4u187-iPhone.m4v ( Size: 5963250 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 186: Exploring The Smalltalk Process Model

January 27, 2012 14:58:56.387

Today's Smalltalk 4 You looks more deeply at the process model in Smalltalk, using VA Smalltalk as our example. 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:

Processes.

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 deeper look at processes in VA Smalltalk. We'll be exploring the cooperative process model that VA (and most other Smalltalks) use. First off, we'll set up the following two processes:


"show cooperative processing model"
coll := OrderedCollection new.
cond1 := 1.
proc1 := [[cond1 < 10] 
	whileTrue: [coll add: cond1.
						cond1 := cond1 + 1]].
proc1 fork.


cond2 := 20.
proc2 := [[cond2 < 30] 
	whileTrue: [coll add: cond2.
						cond2 := cond2 + 1]].
proc2 fork.

^coll

When you execute those two, and then inspect the collection, you'll see the following:

Process

Notice that the first process ran to completion before the second one ran. That's because they were both set up at the same priority - unless one of them yields the processor (for IO, or in code purposely), the first will simply run until completion. In the normal Smalltalk process model, only a higher priority process will preempt an existing one. To get a process to yield, use the #yield message, as seen below:


"show cooperative processing model - #yield"
coll2 := OrderedCollection new.
cond3 := 1.
proc3 := [[cond3 < 10] 
	whileTrue: [coll2 add: cond3.
						cond3 := cond3 + 1.
						Processor yield]].
proc3 fork.


cond4 := 20.
proc4 := [[cond4 < 30] 
	whileTrue: [coll2 add: cond4.
						cond4 := cond4 + 1.
						Processor yield]].
proc4 fork.

^coll2

That gives us the following:

Process

With the #yield being used, each process waits for any otter process (at the same or lower priority) to have a shot at the processor. What if one process is at a higher priority?


"show cooperative processing model - higher priority"
coll3 := OrderedCollection new.
cond5 := 1.
proc5 := [[cond5 < 10] 
	whileTrue: [coll3 add: cond5.
						(Delay forSeconds: 1) wait.
						cond5 := cond5 + 1]].
proc5 fork.


cond6 := 20.
proc6 := [[cond6 < 30] 	
	whileTrue: [coll3 add: cond6.
						cond6 := cond6 + 1]].
proc6 forkAt: Processor userInterruptPriority.

^coll3		

The Delay is used in the first process so that it doesn't run to completion before we even start executing the second process. The results are shown below:

Priority Levels

The first process starts running, goes into a wait state (the Delay), and then never gets the processor back so long as the higher priority process runs. That's how the scheduler works in Smalltalk.

Finally, what if you have a long running process that you need to kill? Simple - use #terminate:


"kill a process"
proc7 := [[true] 
	whileTrue: [(Delay forSeconds: 2) wait.
						Transcript show: 'Executing...'; cr]] forkAt: Processor userBackgroundPriority.
						
proc7 terminate.

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:
[st4u186-iPhone.m4v ( Size: 9254001 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 185: Automating Unit Tests

January 25, 2012 8:36:28.532

Today's Smalltalk 4 You looks at automating unit tests in VisualWorks using SUnitToo. 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:

Automating Tests

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:
[st4u185-iPhone.m4v ( Size: 5513597 )]

posted by James Robertson

 Share Tweet This

st4u

ST 4U 184: Processes in VA Smalltalk

January 23, 2012 8:22:36.626

Today's Smalltalk 4 You looks at processes (and the process model) in Smalltalk, using VA Smalltalk as our example. 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:

Processes.

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 processes in VA Smalltalk. That will involve looking at two classes: Process and ProcessScheduler. Class Process is displayed below:

Process

Creating a process is pretty simple - you use a Block, which we looked at in a recent tutorial. You can see the code we used to play with processes below:


"create a process"

cond := 1.
block := [[cond < 10] 
	whileTrue: [Transcript show: 'Condition is: ', cond printString; cr.
						cond := cond + 1]].
block fork

cond := 1.
block := [[cond < 10] 
	whileTrue: [Transcript show: 'Condition is: ', cond printString; cr.
						cond := cond + 1]].
block forkAt: Processor userInterruptPriority

		

To create a process, simply encapsulate the desired code in in a block. Then, rather than executing it with #value (et. al.), fork off the process, as you can see above. In VA Smalltalk, there are 8 priority levels (ranging from 1 to 8 as numeric values) - but you should use the named levels, which you'll find in class ProcessorScheduler:

Priority Levels

The reason you should avoid the named levels can be seen in what's happened in other Smalltalk implementations. VisualWorks originally had 8 priorities, ranging from 1 to 8. At some point, the engineering team at Cincom changed that to 100 levels, and remapped the named levels within the new range. Instantiations could do the same with VA; it's best to avoid future problems by using the API.

To see a process execute, try highlighting the code blocks above - you should end up with something like this in the Transcript:

Processes

Another thing to keep in mind - the Smalltalk process model uses green (lightweight) threads. That means that each Smalltalk process exists only within the context of the heavyweight VM process; a Smalltalk process is neither an OS level process nor an OS level thread. Additionally, the model is one of cooperative multi-tasking - processes at the same priority level will not yield to other processes of the same priority.

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:
[st4u184-iPhone.m4v ( Size: 7981008 )]

posted by James Robertson

 Share Tweet This

Previous Next (554 total)