The Cuis Cookbook

From Cuis CookBook
Jump to navigation Jump to search

A programming language cookbook is something like StackOverflow, without the digging part and the try&pray experience. For a gentle and structured introduction to Cuis-Smalltalk, you should start with the The Cuis Book and Learning-Cuis more about this in References. This is intended to be a resource for programmers, in the sense that it answers questions that will naturally come up to programmers while exploring Smalltalk.

Reliability. I am writing these notes while learning Cuis. Some of what I write may not be the best way to solve the problem, it may not even be correct. Be patient, double check. Since I use these recipes myself I am going to improve them in time.

Sorting principles. Topic order is intended to go from easy to difficult. From frequently necessary to rarely used. From needed at the beginning of the programming experience to needed by black belts. These three forces, as with the 3 laws of robotics, regulate what chapter goes toward the top of the document. They hold also for sub-chapters and articles.

Contributions. I am trying to figure out ways to make contributions possible and fruitful, see contributions motivated guidelines. As a write I see that format guidelines are also important.

Copyright. You have the right to read, print for your own use, and contribute to the document. You can make external links to this document. You can not copy the document and make it available somewhere else on the Internet. You can't claim ownership. You can't bring the document to an editor and publish it. I, as the author of more than 99% of the words displayed here, retain all rights as well as the right to change these rules.

  • Introduction. What you should expect from this book and the reason why I am writing it. STARTED.
  • Why Smalltalk?. For what reason should you learn another programming language which is also not so popular? Read on, there are very good reasons. STARTED.
  • Why Cuis Smalltalk? . TODO
  • MetaCookbook. Collection of things about this document.

Installation and start up

Cuis in its environment

Things unique to Cuis and/or Smalltalk

Here are all the things that are totally unknown for anybody who has never programmed in any Smalltalk.

About a general Class and Object

Data Structures

  • Fundamentals: numbers, strings and symbols

Strings (before default UTF)

Collections

Streams

Date and time

Files and directories

You should keep in mind that Smalltalk uses files but it is not based on files. I copy here

part of a Juan mail to mailing list: "... The essential idea you need to be aware of when learning about all this is that Smalltalk uses files, but it is not file-based. What this means is that all the tools in the Smalltalk image (with the only exception of FileList and FileContentsBrowser) are NOT showing files, but live objects. The way them relate to files is usually not really important ...".

Error Handling and the Debugger

Processes

Uncategorized useful features

Run external programs

If you run Cuis in Linux/Unix, and to some extent also in the Mac, you can use thousands of already written shell programs that solve the most diverse issues. Examples:

  • Do you want to know how much free space is available on the disk?
  • How many wireless networks your computer can see?
  • Run an R script to make a fantastic plot?
  • ... these and thousands of other things are possible once you are able to leverage the power of Unix from Cuis.

You can perform these kind of operations with the module OSProcess included in Cuis or with the external package CommandShell. The second is easier, the first is lower level => more difficult but more flexible.

Networking and the Web

  • How to ping a computer
  • How to discover the IP of a given host name
  • How to get a webpage's content

Databases

  • Talk to PostgreSQL. See the PostgreSQL package, it has documentation.
  • Talk to MongoDB
  • Talk to SQlite

Scripting Cuis

This section is about setting Cuis to start up in the way you like it, on any image you may want to boot.

  • Author name and initials programmatically
  • Set your preferred font size
  • Set your user name
  • Stop the system from asking to save the image on pressing Cuis World->Quit
  • An example of customized Cuis startup Requires only one executable script file !
  • Do ENV variables affect Cuis ?
  • How do I pass a string to be executed by Cuis when it boots ?
  • How do I pass a file to be executed by Cuis when it boots ?
  • How to quit Cuis immediately. No questions asked.

Scripting with Cuis

Is it possible to make Unix scripts with Cuis? Does it make any sense? This section explores these subjects.

  • Initial considerations. here

Delivering an application written in Cuis

This section explores ways in which you can have other people, non programmers, use your coolest applications. To run the application it may be necessary to: [1] Run VM and an Image [2] Run VM + Image + some code snippet passed as a String [3] Run VM + Image + a script file.

  • Deploy a Cuis application in Linux
  • Deploy a Cuis application in Windows-10
  • Deploy a Cuis application in MacOS

Morphic Cookbook

  • Basic operations with Morphs
  • Kill a Morph . A few ways to destroy a Morph.
  • Place Morphs in World as you wish, automatically
  • Drawing and pictures with the ImageMorph
  • Application. Convert a color image to black and white
  • Application. Show contours in an image
  • How to layout the Morphs . This is the basic step to know prodromic to make your own GUI in Cuis.
  • Fonts - 1. First interactions with Fonts
  • Basic event handling in Morphic . Here we see how to do something when a mouse button or a key on the keyboard get pressed.

The Sound system

To some people doing programming is manipulating sounds. As for some other people it is building a nice graphical user interface or some one else does networks services. For this reason the sound system chapter is placed after Morphic.

All this chapter requires you to load the sound module.

Feature require: 'Sound'.

Introspection and The compiler

These notes are taken reading the wonderful document "The HitchHiker's guide to the Smalltalk Compiler" by Vassili Bykov, here .

  • get the current World object.
  • what happens when Cuis start up.
  • the main loop.
  • The Cuis scanner.
  • The Cuis parser.
  • See the compiled code.

The Virtual Machine

  • Building the Virtual Machine
  • Building the VectorGraphics plugin
  • Choosing between FFI and plugin
  • Run a script with a proper window title

Applications built on Cuis

  • DrGeo.
  • Borghi DataStreamer.

TODO

These are reminders for me about things to do in the Cookbook or in Cuis

  • DEV. SpellChecker, for text panes in Cuis. It would be useful to be able to spellcheck comments in code. I like to put comments, without spell checker they are so full of bugs they appear really untrustworthy.
  • Video about class variables.
  • Page about ';' -- '::' -- 'yourself'.
  • Video about installation of Cuis, not so easy the first time
  • Video about updating Cuis, not obvious
  • Video about using the Transcript efficiently
  • Video about creation of a minimal GUI
  • Video about creation of a minimal application, runnable from Linux command line
  • Video about creation of a minimal application, runnable from Windows GUI
  • Video about making Tests, and discovering how to use existing classes with them
  • Video-or-page about variables, especially class variables