2017-02-22

Quick tip: Call a rest service with curl

curl \
--header "Content-type: application/json" \
--request POST \
--data '{"id": 42, "active": true}' \
http://localhost:8080/lanes/addTask

2017-02-21

A collection of home computers and accessories: Video Technology Laser 110

I collected home computers for almost a decade. As I decided to donate my collection to the Museum Industriekultur in Nuremberg and already handed over these cute little machines and its accessories to the museum, it’s time to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. Sit back and enjoy the picutres.

Main unit

Main unit (diagonal view(

2017-02-19

A collection of home computers and accessories: Atari VCS 2600

I collected home computers for almost a decade. As I decided to donate my collection to the Museum Industriekultur in Nuremberg and already handed over these cute little machines and its accessories to the museum, it’s time to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. Sit back and enjoy the picutres.

Please note: The Atari VCS 2600 certainly is not a homecomputer, still, you could even add a keyboard and code in BASIC. As of 128 Bytes of RAM, not particularly useful, though.

Main unit

Switches

Main unit (diagonal view)

2017-02-18

A collection of home computers and accessories: Oric 1

I collected home computers for almost a decade. As I decided to donate my collection to the Museum Industriekultur in Nuremberg and already handed over these cute little machines and its accessories to the museum, it’s time to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. So, just sit back and enjoy the picutres.

Box

Inner packaging

Manuals

Main unit

Main unit (bottom view)

Main unit (diagonal view)

Dart for Java developers: Mobile apps with Flutter

In a previous installment of my series of posts about Dart for Java developers we took a brief look at how to write a simple web application using Dart. This time, I would like to introduce you to the Dart way of going mobile. It's called Flutter. Flutter had its first public appearance in 2015. At that time it was called Sky. Since then Flutter has evolved quite a bit. Although still being a technical preview it is possible to write real world applications. As with all prerelease solutions, some things will likely change. On the other hand, being an early adopter also means building up skills early.

The underlying idea of Flutter is to build Material Design mobile apps for Android and iOS with one code base using Dart as the programming language. On both platforms the user interface is not made of native components. Flutter handles all painting by itself. Nonetheless Flutter tries to provide expected behavior, for example by using appropriate gestures, animations and transitions. This approach has both pros and cons. I am not going to discuss them here, but leave pondering up to you.

At this point, you are probably asking yourslef how a Flutter application looks both in source code and up and running. I have created a Flutter version of the temperature conversion app. You can find it on GitHub. Here is a screenshot of the app running in the iOS Simulator:

Screenshot of the temperature conversion app

Before taking a look at the code, I would like to talk about system requirements. Currently you need a macOS or Linux machine. Support for Windows appears to be work in progress. Setting things up currently requires quite a few steps, but these are well documented. Finally, let’s take a look at the code. The basic structure of a Flutter app looks like this:

import 'package:flutter/material.dart';
import ...

...

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: _appName,
      home: new MyHomePage(title: _appName),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
 
final String title;
 
@override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  ..

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(config.title),
      ),
      body: new Block(
      ...
      )
    );
  }
 
...
}

The top-level function main() is the entry point of the application. We instantiate a class that extends StatelessWidget. As the name implies, such widgets have no mutable state. Its build()-method returns yet another widget: MaterialApp. It has a title and a home. The latter one is a StatefulWidget. It overrides createState(), which to no surprise returns a freshly created State. Its build()-method returns a Widget that represents the current state. This may look complicated at first sight, but in fact its super simple. Changes to the state result in build() being called. As you can see in my sample app at GitHub, there is a corresponding setSate() to set this chain in motion.

2017-02-12

A collection of home computers and accessories: Commodore Datassette 1531

I collected home computers for almost a decade. As I decided to donate my collection to the Museum Industriekultur in Nuremberg and already handed over these cute little machines and its accessories to the museum, it’s time to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. So, just sit back and enjoy the picutres.

Box

Box (opened)

Datassette

Datassette (bottom)

2017-02-11

A collection of home computers: Philips VG 8020

I have been collecting home computers for almost a decade. As I have decided to donate my collection to the Museum Industriekultur in Nuremberg and already handed over these cute little machines to the museum, it’s time to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. So, just sit back and enjoy the picutres.

 

The box

Opened box

Main unit

Cartridge slots

Main unit (diagonal view)

2017-02-06

A collection of home computers: Sharp MZ-721

I have been collecting home computers for almost a decade. As I have decided to donate my collection to the Museum Industriekultur in Nuremberg (and handed over these cute little machines), I would like to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. So, just sit back and enjoy the picutres.

Box

Opened box

Main unit (front view)

Builtin tape recorder

Main unit (diagonal view)

Main unit (bottom view)

Manual

Dart for Java developers: a visibilty primer

In the previous installments of my small series about Dart for Java developers we saw quite a few lines of code. ...that is, if you looked at the .dart files I linked to. ;-) You may have wondered why some identifiers start with an underscore. I briefly mentioned libraries and packages, but did not say much about visibility or scope. The underlying questions are
  • Where can I see a variable, function or method?
  • Where and when can I access them?
Consider the following source file named a.dart:

var answer = 42;
main() {
  var a = answer;
  {
    var b = a;
    print(b);
  }
  print(b);
}

It will print 42 once, but then fail with a NoSuchMethodError. That happens because there is no top-level getter b. To a Java developer it will not be surprising that print(b); outside the nested block fails, as b is not visible here. But why do we see NoSuchMethodError? Didn't I just access an identifier?

In Dart access to variables occurs via getters and setters, and if these have not been defined by the developer, they will be there automatically. If we remove the second print(), the program will run just fine (assume a version named a_correct.dart). Now take a look at the following lines of code:

import "a_correct.dart";
main() {
  print(answer);
}

If we run it, 42 is printed once. In a_correct.dart answer has been declared at the top-level, so the identifier can be seen by the library that imports a_correct.dart. But what if we don't want a variable or function be visible? Just prefix the identifier with an underscore. Imagine a file b.dart:

var _answer = 42;
_hello() {
  print(_answer);
}

And c.dart:

import "b.dart";
main() {
  print(_answer);
  _hello();
}

Not to much surprise, it will fail. Neither _hello() nor _answer are visible. There is more control about what packages export to the outside world, but this is an advanced topic I might cover later. So, for now dear Java devs, just forget about publicprivate and protected. And stick to this simple rule:

If it's local, prefix the identifier with an underscore.

Clear. Precise.

2017-02-04

A collection of home computers: Commodore 128D

I have been collecting home computers for almost a decade. As I have decided to donate my collection to the Museum Industriekultur in Nuremberg (and handed over these cute little machines), I would like to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. So, just sit back and enjoy the picutres.

Main unit and keyboard

Builtin Floppy Drive

Main unit and keyboard (diagonal angle)

2017-02-03

Dart for Java developers: a simple web app

In the previous installment of my small series of posts about Dart for Java developers we have put together the pieces we crafted so far. We saw a small console application which used both model and converter libraries. As a next step we will be building a small web application. The following screenshot shows the running program.

a temperature converter web app

The corresponding html file is fairly simple. If you take a look at the body you find three tags: h1, form and p. The latter one will receive the computed temperature. The headline is merely decorative. The form comprises a text input field for the input temperature, two fieldsets which contain radio buttons for the input and output temperature units, and a button. There is no css to make the ui a little more fancy. Relating pull requests would be greatly appreciated.

So far, so easy. But how do we connect the html file to a Dart program, and how does this look like? The head contains two script references:

<script defer type="application/dart" src="main3.dart"></script>
<script defer src="packages/browser/dart.js"></script>

The latter one bootstraps the Dart runtime, whereas main3.dart (yes, that name is not extraordinarily desriptive ;-)) refers to the program. Let's take a look at it. There is a toplevel main() function, which connects the code to ui elements through querySelector(). To be able to use this function, we must import the dart:html package. Have you spotted the two calls to listen()? One is used to receive button clicks, while the other one will give us events when a key icharacter is entered. We use this to disable the button if the input field is empty. The remaining code is straight forward. We instantiate a model class, set it up, and have it calculate the output temperature.

Isn’t that easy?

2017-01-29

A collection of home computers: Thomson MO5 E

I have been collecting home computers for almost a decade. As I have decided to donate my collection to the Museum Industriekultur in Nuremberg (and handed over these cute little machines), I would like to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. So, just sit back and enjoy the picutres.

Box (top view)

Box (bottom view)

Box (opened)

Computer (top view)

Computer (diagonal angle)

Computer (bottom view)

Manual

Manual and lightpen

Screenshot

2017-01-28

A collection of home computers: Sinclair ZX Spectrum

I have been collecting home computers for almost a decade. As I have decided to donate my collection to the Museum Industriekultur in Nuremberg (and handed over these cute little machines), I would like to share some pictures of my collection. You can find the technical specification of all of then throughout the Internet, so no need to repeat it here. So, just sit back and enjoy the picutres.

Front view of the box

Back view of the box

Inlay with machine and power supply

The Spectrum

Spectrum from a diagonal angle

Bottom of the Spectrum

Power supply (front view)

Power supply (back view)

2017-01-22

Dart for Java developers: putting it all together

Welcome back to my small series of posts about Dart for Java developers. In the previous installment I promised to actually use the Model class soon. A very simple scenario can be seen in the file main2.dart. If main2.dart is invoked from the command line, one must pass exactly three arguments:

  1. input temperature unit
  2. value of the input temperature
  3. output temperature unit
The program is quite simple. We have two import statements as we need both model.dart and converter.dart. The first one gives us (among other things) the definition of a class named Model. We instantiate it using the familiar new keyword. After that we set the unit for both input and output temperature. enumFor() is a top-level function defined in model.dart. It checks if one of the enum values ends with the string passed as the only formal parameter. Remember that we pass them to the program via the command line. So to satisfy the string comparison, we need to enter exactly degreesCelsius, degreesFahrenheit or kelvin.

The temperature value itself is converted from String to double through stringToDouble(). This function can be found in converter.dart. It uses an internationalization package named intl. This package is capable of honoring locale-specific settings like the decimal mark and the thousands separator. My example explicitly sets the locale to German, which means that english 1,234.56 has to be entered as 1.234,56. Feel free to experiment with this. Why not reading the name of the locale from the command line?

Once the model has been set up, calculateOutTemperature() can be called to do the actual computation. After that, the result can be printed from the getter outTemperatureAsString(). Dart has first-class support of getters and setters, so no method parenthesis are needed.

2017-01-15

Dart for Java Developers: The Model class

In my previous post, Dart for Java Developers: Into the code, we looked at two Dart source files, converter.dart and main.dart. Both contained so-called top level functions, that is, making code available without the need to put it in a class. Recall that each Dart file is a library. A library with a top level main() function is a script. Libraries are combined or grouped to form so-called packages. Packages can be easily distributed and reused. The Dart SDK comes with a package and asset manager called pub. Packages are described in a specification file named pubspec.yaml. It consists of, among other entries, a name, a version and a list of dependencies. For example, Temperature Converter relies on the internationalization package intl. A package can live anywhere. Some packages are on GitHub. Others reside at pub.dartlang.org. You can publish your packages there, too. Here is a description what you need to do: https://www.dartlang.org/tools/pub/publishing. The pub tool is invoked either through the plugin of your IDE (if you open a pubspec in IntelliJ you get a commands list at the top of the editor window), or from the console. If you fancy the shell, remember to include /bin in your PATH environment variable.

Now, let's turn to code. Recall that my original Temperature Converter app was written in Java using JavaFX. There is a Model class that uses Converter. So, Model has both state and behavior. The class is used as follows:

  1. Instantiate it
  2. Set the domain data (unit of input and output temperature and the temperature itself)
  3. Perform the calculation
  4. Grab the output string
  5. Back to 2.

Let's see how this looks like in Dart. We start with a library statement (which gives the library a name), followed by an import. We rely on the converter library you have encountered in the previous post. After that you see an enum definition. Compared to, for example Java, Dart enums allow less customization. Currently the string representation of the enum evaluates to enum_name.enum_value. To be able to more easily map user interface elements to enum values (you will see that later) I implemented a convenience method named enumFor(). Dart enums cannot be defined inside classes. Now let's take a look at the Model class (it's inside model.dart). Besides the lack of access level modifiers (more on that soon) the code looks comfortingly familiar. With two very welcomed exceptions. Have you spotted the get and set keywords? Dart has language level support for getters and setters.

In the next installment we will actually use the new Model class. But if you cannot wait to try it out, just grab the code from GitHub and start playing.

2017-01-11

Dart for Java Developers: Into the code

In a previous post, Dart for Java Developers: First Contact I offered you a glimpse at the language by creating a very basic project using the project creation wizard of IntelliJ IDEA. Today I would like to dig a little deeper by showing you how to rewrite a Java program in Dart. I will use a small temperature conversion app which I wrote for a series of talks about Java on mobile devices. You can find the JavaFX version on GitHub.

The program consists of four classes, a user interface definition and a resource bundle. TemperatureConverter is the main class. It loads the ui from an fxml file and instantiates a controller class called FXMLDocumentController. This controller binds ui components and actions to a model class named Model. This class holds the actual domain data and invokes code from the Converter class. It contains a couple of static methods that do the actual temperature calculation. Let us start with this one.

As you can see in the source, although doing different computations, the innards of the methods are mostly the same, that is, doing some arithmetics using the primitive double data type. The method stringToDouble() converts a string to a double value honoring locale specific settings like the decimal mark and the thousands separator. doubleToString() creates a string consisting of a double value with its fractional part omitted if it is zero, and a suffix. How could we do this in Dart?

For your convenience I set up a GitHub repository. Please take a look at converter.dart. Possibly to a bit of a surprise, it does not contain a class, but several top level functions. unitDegreesCelsius, unitDegreesFahrenheit and unitKelvin are compile time constants. _f is declared final, so its value can be assigned only once, but obviously not during compile time. I really like the compact function definition using =>, which takes an expression. If more statements are needed, the traditional body using curly braces comes into play. Also very nice is the string interpolation you can see in _doubleToString(). You can access the value of an expression inside a string by using ${expression}. If the expression is an identifier, the {} can be omitted.

To see the calculations in action I have provided main.dart. If a dart file contains a toplevel main()-function it is called a script. The following screenshot shows the execution of the program in Visual Studio Code.
Editing and running the script in Visual Studio Code

Dart programs and libraries are often distributed as packages. Packages follow certain rules regarding structure and content. You can see a bit of this in the screenshot. I might go into a little more detail in a future post. The json file you can see in the screenshot is not part of that package but helps running the program in Visual Studio Code. Want to try for yourself? Great. Just clone the repo and start playing.