Counter Examples

Gabor Szabo - Jan 3 '23 - - Dev Community

I love experimenting with programming languages, databases, frameworks, etc.

The standard example of a "Hello World" program is nice to get started, but usually way too simple. So I started to create a slightly more complex example. A counter example.

In each example we are going to create a counter. A simple counter will just increment a single number. A multi-counter will handle several counters. e.g. one per client, one per user, or one per some arbitrary string.

I think these counter example can show you several aspects of a programming environment and can help you get started writing your own applications.

In this project we are going to implement a counter with various front-ends and back-ends. Sometimes these two parts will be in one program.
Some of the solution will be web based. Some will be command line based. Some might be GUI-based.

The counters might be stored in some kind of a "database". It can be a plain text file, some data serialization format, a relational database, a NoSQL database and who knows what else.

The simpler version of the counter handles a single counter. Every time we run the counter it will show a number one higher than the previous one.

An interaction with a command-line tool might look like this:

$ count
  1
$ count
  2
$ count
  3
Enter fullscreen mode Exit fullscreen mode

The multi-counter is slightly more complex. It will be able to maintain several counters at once.
So an interaction with a command-line tool might look like this:

$ count foo
  foo: 1
$ count foo
  foo: 2
$ count bar
  bar: 1
$ count foo
  foo: 3
Enter fullscreen mode Exit fullscreen mode

This is going to be a long project, but it might help understand various techniques for data serialization.

Series

This is the beginning of a series. Soon I am going to publish the first entry.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .