Home network improvements

The new and the old router

Last summer, when we got the new 5G network from the operator, replacing the 4G, they delivered a new router for us (on the right side of the picture).

Having a two storey house with a tin roof and a side building where I work, that little router could not handle the range needed at all. I tried to configure an old Asus router to act as a repeater for the white thing, but that did not help at all.

So, after using the phone network at the side building for a while, the frustration finally grew to intolerable levels and I went to Verkkokauppa and bought that monster on the left.

Since it is also an Asus router, the old Asus Wi-Fi router and the monster are now configured as a mesh. Goodbye networking problems.

Other news: busy at work, grading Data structures and algorithms course projects. That is put on hold from Monday for three weeks, when I spend all my free working time in student admission work. Since I am again the only teacher doing the grading, this will take some time…

The way teaching resources are diminishing each year as the number of students is rising each yer, is a constant source of frustration to me. Last Fall I was teaching 3-4 courses at the same time totalling almost 1000 students, having only two full time teachers and two part time assistants is not fun. AFAIK, next Fall is going to be probably worse. No like, no like at all.

So no resources means everything is delayed. Anyways, the rest of the work time in the coming three weeks, around 5-10 hours per week, are spent in watching over BSc project work groups. Each group has six students, and they are supposed to work on software projects for external clients. During the next three weeks, the first steering group meetings are supposed to accept the project plans for these projects. Lots of guidance giving, reading plans, giving feedback and meetings, that is.

All this is slowed down a bit me having a flu since Tuesday. All face to face meetings were changed to online meetings. Suits me well, don’t have to dress up and move to the campus, taking time from other things. But then I need to make sure I get light walks done on free time. Not too sick for that, luckily.

I miss my friend

Nuki is my friend. He is a Japanese spitz, born 13th July 2009.

Each morning he wakes me up early with a soft murmur. I get up and dress, drink a glass of water and give him his medicines. He has issues with his joints and gall bladder. He likes to take the medicine with a slice of chicken fillet.

Then I put on the clothes, considering the weather I check beforehand, his vest and go to check out the neighbourhood. He is very keen on guarding and patrolling “his” area, marking it for any intruders to know he is the king here. Oftentimes, I would talk with him about the weather, observations about the environment, and commenting him about his bad behavior towards other dogs. He always made very clear to other doggies about them not having the right to be in or around His Kingdom.

There are only three or four other dogs he ever accepted as a friend. In our current neighbourhood, there is this one small, old black poodle lady, and another Japanese Spitz, younger lady that he likes. Others are just Enemies that must be banished.

Then we return to home to prepare us breakfast. Since he is already old, I am not so tight about serving him treats in addition to the doggie breakfast. When I will have a glass of sour milk, I will also pour some for him in a small glass cup. And he gets to lick the inside of my glass when I’m done. Often also he waits by me for the last small piece of my bread, which I will offer him. When making porridge with frozen bilberries, he often likes to eat those too, one by one, from my hand. Good for your eyes, you know.

We are friends and we share what is good and tasty.

Then he takes a nap as I go through my work email with the laptop on the sofa. Lately he has started to come beside me to ask for some scratching and massaging his aching back. In human years, he is around 100, not the youthful healthy himself anymore.

Before I go to my remote workplace in the side building of our house, I often treat him with a piece of biscuit. For some reason he doesn’t like to come there but likes to stay in the main building. Never got to understand why that is.

When I return to main building for a cup of tea or lunch, he is often sleeping on the entrance floor and woke up to greet me. And of course, he is again very interested in what I was eating. And if there would be any treats for him too.

We used to take the afternoon walk around 1-2 pm, but lately he wanted to go earlier. Probably because of his age and the health issues. This walk was usually the longest one. We often took a route around the residential neighbourhood here. The area has lots of trees and walking paths in the forest. Very nice for a nature loving dog and his masters.

Then I continue my work in the side building usually, if not sitting on the main building sofa with the laptop. All of my teaching during and after the pandemic has been remote, also meetings. So I rarely went to the campus for meetings or events. Nuki of course liked this. If in the main building, he’d always get his scratching service, if I was there. Of course, the other humans in the building were also usable and utilized for his pleasure, but as the head of the pack (at least for him), I was the often the human to go to.

We also have a cable outside where I could attach him so he could enjoy the fresh air, observe the birds, chase the squirrels and stare at passing other doggies and humans. Lately he didn’t want to go there, probably because of freezing temperatures and his aching joints.

After work and the evening stroll, we would often watch the telly in the living room. On Fridays, we have a pizza evening with red wine. Nuki always got to eat the sides of my pizza. Since I am such a lousy master what comes to discipline, he was often quite vocal in making sure he got his share. To me it was often quite amusing, the way he made those sounds to make sure I knew what he wanted. In addition to pizza, potato chips were also his favourite although a rare treat.

Last week Nuki’s walking got increasingly and quickly more difficult. He had his joint medicine injection on Friday, earlier than planned. That did not help. On Friday evening, he could no longer get up. In the Saturday morning, January 13th 2024, I tried to get him to his morning pee, but we ended just sitting in the dark and cold, snow slowly covering us in the back yard. We lifted him in a large bag with a blanket and I took him to the vet, him sitting in the front seat while I scratched him and talked to him all the way, driving to the other side of the town.

Vet said there is nothing that can be done, considering his health and age, without extending his needless suffering. Which I kind of had accepted already for some time ago, that our shared journey would be coming to an end. He was paralyzed from waist down and could not pee. Nuki was put to sleep and then sent to his last journey to where ever, I don’t know. I sat by him to the very end, caressing him, accompanying him during his last moments. No more pain and suffering for Nuki.

Now there is no one to wake me up in the morning. No Nuki to share my breakfast. No friend to take me to walks in the morning, in the afternoon or in the evening. No one to make sure our borders are guarded against hairy enemies. No one to bark and greet incoming visitors. No one begging to lick the glass clear when I finish my sour milk. No one to share the biscuit with my afternoon tea. No one waiting for me to come home on the mat at the front door. No one to scratch and talk nonsense to. No one to share the fried yellow of the egg another human in the house does not want to eat. No sounds of pawns tapping on the wooden floor as he woke up from his sleep. When I see a glimpse of movement in the corner of my eye in my work room outside the window, it is not him there, watching over me.

I miss you, my friend.

Advent of Code status update

Today (Dec 22nd…) I solved the Day 16 puzzle, using a graph data structure that I generalised from Day 8 implementation specific graph. I brute forced the part 2 of the puzzle. Probably would get it much faster if I would modify it to be a little bit more clever solution. Maybe won’t, since who cares.

I am still using Swift, though at some points I’ve considered if I should use C++ or Java. I could then utilise my old code. For example, graph data structure implementations done for teaching, with both Java and C++.

I got left behind at day 12, where the puzzle was the first one I had no idea how to start solving it. Maybe a bit too mathematical to my taste. The overall feeling with this puzzle was “meh…? :/” The first puzzle that I was not even interested to solve. Eventually I did solve the part one, but since brute forcing doesn’t really work with part two, I have not tried since. I did take a look at some solutions with Python and C++ from the community but didn’t follow their examples. I know memoization, it would help here, but with this data…

The next problematic puzzle was day 13, part 2. Part 1 was OK, but again for part 2 I would need to find a faster solution. Also, I do not manage to get the expected result using real data, although the unit tests with test data do pass. Maybe I will return to this after the holidays…?

I agree with those comments in the AoC community that some of the puzzle descriptions and/or test data are deliberately vague, perhaps to prevent or hinder using “AI” in solving the puzzles. The negative impact is that this also creates interpretation problems and requires deep dwelling into the input data. To find out why solutions that pass tests with test data, do not provide the correct answer with the real data. Oftentimes this helps, with the support from insights from the AoC community.

In addition to the generic graph data structure, I also implemented a generic Matrix (or Grid) data structure, to make it easier and faster to parse grid data (2D array) from the input data.

A code snippet in Swift: 
func parse<Character>(data: String) -> Matrix<Character> {
	var matrix: Matrix<Character> = Matrix()
	data.components(separatedBy: .newlines).forEach { line in
		if line.count > 0 {
			matrix.append(row: Array(line) as! [Character])
		}
	}
	return matrix
}
An algorithm to create a Matrix (generic 2D array) of characters from input data string.

When looking at some repositories from people participating for many years in AoC, they often have a good collection of tools to help in solving the puzzles. Since many puzzles are similar to ones in previous years, it helps when you just pick up what you need from the data structures and algorithms you already have, to build the solution. I have avoided the temptation to take these building blocks from others, and built my own. In case I participate again next year.

AoC has been a good learning experience seeing how others approach the problem solving. Like the one where I used a grid of characters. Some saw that you could interpret the symbols in lines of the grid as zeroes and ones, and then handle the data as arrays of bits or rows of integers, and use operations like xor to find differences in lines (arrays of bits/integer values). A thought like this vaguely passed through my mind but I never grasped it but let it pass, and continued away with grid / array based solution. A good reminder for me to consider to stop thinking for a while, instead of storming ahead with some idea that may not actually be so good in solving the puzzle.

Apart from moments of frustration and lack of motivation with some puzzles, AoC has been fun so far. Some participants have commented that this year is more challenging than the previous ones. Probably I’ll try to finish all this year puzzles, although late. Positions in leaderboards are not too important for me, but it is nice to see that I managed to stay in top-50 in Swift leaderboard after checking in day 16 solution.

Probably will fall in position since Christmas preparations are going to start full speed today, and I haven’t bought yet a single present to anyone…. It helps a bit that both my kids and their families are not in town until January and we’ll celebrate with gifts then.

Advent of Code – hanging on, so far

I’ve solved all the puzzles by now, both part 1 and 2. Some have been quite tricky to solve. Other issues I’ve had — mainly stupid parsing problems.

Having an effective parser would be something that helps. Also, as someone suggested in the Swift forums, a (generic) grid would help since apparently many puzzles have a grid to navigate.

Already today I thought that the puzzle could be done using a graph. Went for maps (dictionaries) and arrays again, though. Unfortunately all my graph implementations I could reuse are either in Java or C++, and I’ve been doing everything so far in Swift. Maybe I’ll prepare a Graph struct/class in Swift just to be ready when it is needed….

Today’s part 2 was hard in a sense that the solution took almost eight minutes to run on my Mac Mini M1. Surely there should be a way to optimise. But — won’t do that, I already passed the challenge. I still am busy with teaching, so all these puzzles are done on extra time.

Anyways, today I rose to position 16 on private AoC Swift leaderboard. Even though I am not competing and skipping a day or failing a puzzle is no issue to me, it is nice to see that I do relatively well – so far…

By now I’ve used Sets, Dictionaries, arrays, ranges, string manipulation, string splitting, enumerations, and those grid operations. Let’s see what comes up tomorrow…

Advent of code day 1

The accompanying challenge doggie

For the first time, I started the Advent of Code challenge. I’ll be working with Swift using the AoC project template from Apple folks in GitHub, announced in the Swift discussion forums.

Got the two stars from the first day of the challenge. 🎉 and rewarded myself with the traditional Friday pizza with red wine 🍕🍷

Part two of day one required some interpretation. I finally got the idea and finished with success.

Don’t want to spoil the challenge but I did the part two in two different ways:

  • Going through the input string using String.Index, character by character, picking up words of numbers (“one” etc) converting them to digits (“1”) to a result string. This should be O(n) where n is the number of chars in the input data string.
  • Replacing words using Swift String replaceOccurrences using two different Dictionaries. This has two consecutive for loops iterating two dictionaries replacing text in input string using keys in dictionaries (eg “oneight”) with values (“18”) in dictionaries. This should be O(n*m) where m is the number of entries in the two dictionaries (ca 15 +/- some), n being the number of characters in the input string.

Surprisingly, the first option took 12 secs as using the higher APIs took only 0.007 secs. Maybe I did the first wrong somehow or Swift String index operations are really slow here because of Unicode perfectness. I’ve understood that the collections APIs used with strings are not so picky about Unicode correctness.

Otherwise I used conditional removal of characters that are letters from the string, map algorithms to map the strings containing numbers to integers and reduce algorithm to calculate the sum.

Challenges like this are a good way to brush up my skills. And learn more about Swift. I added myself to the Swift leaderboard to see how other Swift programmers do.

Tomorrow is the day two. Should have time for that in the morning since I wake up early nowadays, both because of myself and the dog. He is already 14+ years and having health issues unfortunately. Meaning early wake-ups every now and then.

The end part of the AoC maybe a real challenge because of all the Christmas hassle in the house. And the busy end of the semester at the university. Interesting to see how far I get and with how many gaps.

Fast Index Order in Binary Search Tree

So, you can use a Binary Search Tree (BST) to store and quickly access key-value pairs. Usually the key gives the position of the value element in the tree. You place smaller values in the left side, and larger values in the right side of the tree.

A sample BST unbalanced, having 13 nodes in the tree. Key in the BST is the person’s name in ascending order.

Finding by key value is O(log n) operation. Starting from the root node of the tree, comparing the key, you can choose which subtree to continue searching for the key. If the BST is balanced, you need to only do O(log n) comparisons at most to get to the key-value pair you wish to find. Like searching for Jouni Kappalainen takes four comparisons from the root and it is found.

The tree contents in key order shown in a Java Swing table view. Order is by BST key order.

Note that the numbers in each tree node picture above is the number of children of that specific node. For example, Kevin Bacon has zero children, as Samir Numminen has five, and the root node has 12 children.

How about if you want to treat the BST as an ordered collection, each item in the tree accessible by index, as you would do with an array? Like, “give me the 6th element in the tree (element at index 5), when navigating in-order, from smallest to largest key in the tree”. In the sample tree above, Kappalainen would be in the index 5 (zero based indexing). Kevin Bacon’s index would be zero since it is the first element in-order. Root node would be at index 1 in this sample tree.

The obvious thing to do would be to traverse the tree in-order, counting indices from the lowest left side node (Bacon) with index 0 (zero) and then continue counting from there until you are at the index 5 (Kappalainen).

Sample tree with in-order indices added in blue. Compare this to the GUI table order and you see the indices are correct.

This works, but the time complexity of this operation is O(n). If you have, let’s say a million or more elements in the three, that is a lot of steps. Especially if you need to do this repeatedly. Is there a faster way to do this?

The faster way is to use the child counts of the tree nodes to count the index of the current node (starting from the root), and then use that information to decide if you should proceed to left or right subtree to continue finding the desired index. This makes finding the element with an index O(log n) operation, which is considerably faster than linear in-order traversal with O(n).

For example, consider you wish to find element at the index 5. Since the root node’s left child has zero children, we can then deduce that the root node’s index is zero plus one, equals one. Therefore at the root you already know that the element at index 5 must be at the right subtree of the root. No use navigating the left subtree.

Also, when going to the right child from the root, you can calculate the index of that node, Töllikkö. Since Töllikkö is after the root node, add one to the index of root node, therefore the current index being two (2). Then, since all Töllikkö’s left children are in earlier indices, add the child count of Töllikkö’s left subtree, which is 8, to the current index, having current index of ten (10). And since the left child node must be counted too, not just its children, we add another one (1) to current index, it now being 11. So the index of Töllikkö is 11.

Now we know that since we are finding the index 5, it must be in the left subtree of Töllikkö, so we continue there and ignore Töllikkö’s right subtree.

Moving then to Kantonen, we need to deduct one (1) from the current index, since we moved to earlier indices from Töllikkä, current Index being now 10. This is not yet Kantonen’s index. We need to deduct the number of children in Kantonen’s right child + 1 from the current index, and will get 10 – 6, having 4. That is Kantonen’s index.

Since 4 is smaller than 5, we know we need to proceed to the right subtree of Kantonen to find the index 5. Advancing there, in Numminen, we need to add 1 to the current index since we are going “forward” in the index order to bigger indices, as well as the count of children + 1 (the subtree itself) in Numminen’s left subtree, in so current index (Numminen’s) is now 6.

Since 6 < 5 we know to continue searching the index from Numminen’s left subtree there we go (to Kappalainen), deducing one (1) from current index, it now being 5. Now, earlier, when moving to left (to Kantonen), we also deducted the number of children in Kantonen’s right subtree. But since Kappalainen has no right subtree, we deduct nothing.

Now we see that current index is 5, the same we are searching for. So, we can stop the search and return Kappalainen as the element in the index 5 in the tree.

Using this principle of knowing the count of children in each tree node, we can directly proceed to the correct subtree, either left or right, and therefore replacing the linear in-order search with faster logarithmic search. With large data sets, this is considerably faster.

While demonstrating this to students using the course project app TIRA Coders, we saw that loading 1 000 000 coders to the course TIRA Coders app, the O(n) index finding operation (required by the Java Swing table view) made the app quite slow and sluggy. When scrolling, the app kept scrolling long time after I lifted my hand off the mouse wheel. Swing Table view was getting the objects in the visible indices constantly while scrolling and as this is O(n) operation, everything was really, really slow.

When replaced by the O(log n) operation described above, using the app was a breeze even with the same number of one million data elements in the BST; there was no lags in scrolling the table view nor in selecting rows in the table.

So, if you need to access BST elements by the index, consider using the algorithm described above. Obviously, for this to work, you need to update the child counts in parent nodes while adding nodes to the BST. If your BST supports removing nodes and balancing the BST, you need to update the child counts also in those situations.

(I won’t share any code yet, since the students are currently implementing this (optional) feature with the given pseudocode in their BST programming task.)

Blasts from the past

Two blasts from the past. Sorry for the long post but hey, this is a frigging blog, not some social media service for attention spans of mere seconds.

First “blast”

When teaching (exercise support sessions) over Zoom, we course teachers have a private chat in Slack to coordinate who goes to which breakout room to help students asking for help. When there’s no acute problems to address, we occasionally chat about random topics.

Yesterday I was participating from the bed using my laptop since I’ve got the flu but was well enough to participate somewhat.

I have had this idea to write the Data structures and Algorithms course materials into a book format. Not to be sold in book stores, but just shared to the students as a single PDF / eBook file.

I remembered doing exactly that, very very long time ago in a discontinued course, and happened to mention this to the other teachers in Slack; that I couldn’t find the book in my computer archives.

“Hold my beer”, said one of the teachers, and voilá, he uploaded that course pdf “book” from 1999 to the Slack channel! As it happens, he was at that time or just before, a student on that course and had archived the material! He is a lot better than me in archiving, apparently, so thanks JLa for that! He also participated in teaching (also) this course, as far as I can remember.

A snippet from the course material for Programming environments course.

The course, Programming environments, was originally a Mac programming course, by our Department Mac guru who left us a long time ago to work in the industry (good for him). Then later, I implemented the course for programming with C in Windows (thanks to Petzold’s book). Even later I also implemented a version to teach Symbian C++ programming in Nokia devices.

Anyhows, I liked the idea to provide the material in a “book” format to the students, and even distributed the book in an eBook format for them to read. A total of 45 pages. I wish I’d find the original editable document somewhere from my external backup drives or USB drives, would be fun to have it.

Maybe I’ll do this sometime again for some course. Writing can be fun.

The second “blast”

A thing I did find when browsing through my archives, was a department plan to arrange teaching for the study year 2009-2010.

Especially interesting for me was to check out the list of courses our team (software engineering focused teachers/courses) at the department taught that study year (table below).

I will just list the courses about programming or strongly programming related or strongly technical courses:

Finnish course nameEnglish course name
AlgoritmitAlgorithms
C ohjelmointiProgramming in C
C++C++ programming
Johdatus kääntäjiinIntroduction to compilers
Johdatus ohjelmointiinIntroduction to programming
Johdatus tietorakenteisiinIntroduction to data structures
LogiikkaLogic
Ohjelmistojen testausSoftware testing
Ohjelmointikielten periaatteetPrinciples of programming languages
Ohjelmointityö IProgramming assignment I
Ohjelmointityö IIProgramming assignment II
Ohjelmointityö IIIProgramming assignment III
Ohjelmointityö IVProgramming assignment IV
OHJY/MacOS/iPhoneProgramming environments / Mac/iPhone
OHJY /  WindowsProgramming environments / Windows
OHJY / UnixProgramming environments / Unix
OHJY/ SymbianProgramming environments / Symbian
Olio-ohjelmointiObject oriented programming
Projekti ITerm project for external customers, programming
Projekti IITerm project for external customers, often included programming
Rinnakkainen ohjelmointiParallel / concurrent programming
RTCSReal time computer systems
Tietokantojen perusteetIntroduction to databases
Unix perusteetIntroduction to Unix

In some of those courses, doing actual programming by the students might have been a relatively small part of the course. And some of the courses were not offered every year. Just not to inflate the amount of actual programming done in some of these courses.

But – if you compare these strongly programming focused courses of that time to the list of current programming or strongly technical courses in the study program:

Finnish course nameEnglish course name
Laitteet ja tietoverkotDevices and Data networks
Ohjelmointi 1Programming 1
Ohjelmointi 2Programming 2
Tietorakenteet ja algoritmitData Structures and algorithms
TietokannatDatabases
Ohjelmointi 3Programming 3
Ohjelmointi 4Programming 3
Ohjelmistojen laatu ja testausSoftware Quality and testing
Bachelor projectProgramming project for external customers
Master’s projectSystems development /analysis project for external customers

So at that time around 2010, we had a total of 24 very technical/programming courses in old study program. Currently we have only 10.

There are courses on software engineering and such nowadays too, but they usually do not include learning to construct things and spending a relatively significant amount of time doing that – that is what I mean by a technical course here, and what was done earlier.

The current study program at the MSc level does not have a single course focused on programming. No more than 5-6 years ago, we still had at least one, Embedded software development environments, focusing (mostly) on distributed mobile programming (taught by me and some other teachers). Before that, we (including me) taught, together with Tampere University of Technology, Mobile systems programming course (Symbian, J2ME). All discontinued.

Currently we have nothing about parallel / concurrent programming in the study program. Last week I did one very small demo to at least show an extremely little thing about concurrency in my course on Data structures and algorithms. To let the students at least to be aware that something like this actually exists and could be done. So like 15 minutes of that topic in the whole study program.

Principles of programming languages, logic, compilers — totally gone from the study program in just over ten years.

You know (and I know) that there are as many opinions than there are you-know-what, but in my personal honest opinion, this is not good. Considering the needs of the local software industry.

Of course the technical topics of today would be perhaps different and obviously should be up to date with modern technologies. But if these kinds of topics and the deeply technical perspective on things is missing, there is not even the chance to discuss if they would or should be updated.

Well, maybe this is just another case for this:

Image of an old man yelling at the clouds from the Simpsons
Old man yelling at cloud, again

Multiple Git repository status awareness app

A year ago I started to implement a GUI app that I could use to track the 250-300+ student projects of my Data structures and algorithms course. The motivation for the tool was to answer the question:

How can you manage four courses with nearly 1000 students when you only have two full time teachers and two part-time supportive teachers to manage all teaching, evaluating and supporting the students in their learning in all of these courses?

Me

The plan was, that using this tool, I could more easily be aware of the statuses of the many student projects in this one course. And then when necessary, do something about possible issues.

Like, knowing that a student is left behind (no commits to the project in the last week or two), gives me a possibility to ask if there is anything I as a teacher could do to help the student to proceed in the course.

And if one or several of the unit tests of the various course programming tasks fail, especially if the task was supposed to be finished already, I could go and check the reason(s). Either by asking the student or taking a look at the git repository of the student myself.

The version last year required me to run shell scripts that would automatically retrieve the up to date code of the student from their remote repository using git pull. Output was directed to a log file the app then parsed to view the content. Similarly, tests were executed in batch from shell scripts with Maven (mvn test), result written to another log file. Again, the app would parse that log file to show in a graph how the tests succeeded or failed.

A while ago I decided that I would like to integrate all the functionality within the GUI app and ditch the separate shell scripts. Also, I decided that the information about the commits and test results would be saved into a database. This way, when app launch is now much faster since it does not need to parse the various log files to show content every time the app is launched.

Instead, when launched, the app reads the repository information, git log data and the test results from a database file. App launches much faster with immediately visible data. When I want to update the commit data for all student repositories, I just press the refresh button in the app toolbar and the app starts to pull data for each repository from the remote repository URLs.

Anonymised student repositories with commit and test data.

When I want to update the test data, pressing another button (the hammer button in the toolbar) starts to execute tests that are due, saving the test results in the app database. I can also refresh an individual repo from remote or execute tests for a single project to get a quick update on the status of the student’s project.

Until now I’ve focused on getting the tabular data visible. Yesterday, I implemented a similar commit grid view you can see in a person’s GitHub profile. This color grid shows the commits visualised for all student repositories:

Commit grid visualisation,

In this grid, time proceeds vertically from up towards bottom of the grid view. Each repository is one thin column on the grid. The timeline starts from the date the course started, proceeding down.

The grid ends at the current date in the bottom of the grid. So when the course proceeds the grid gets taller. Since this course displayed here started on September, the grid here is 42 days “tall”. This will give me a very high level visual awareness of level of activity among all the students in the course.

Obviously the usefulness of the tool depends on the fact (?) that students push their commits to the remote repository often, preferably daily or at least weekly. If they do not, we teachers cannot see them and this tool does not show them. As you can see, some of the repositories are in red, meaning there has not been a commit for over 14 days. Orange repositories indicate the most recent commit being over a week old.

Red and orange colors may mean that the student has decided to do most of the course progrmming just before the deadline. A common though not the best choice. So seeing lots of red at this point does not necessarily mean big issues with passing the course. We’ll see…

I’ve been constantly trying to motivate the students to do commits and pushing often. It is beneficial for them too – you get a backup of your work in the remote, and when you need teachers’ assistance, teachers have immediate access to the code from the remote.

Since the first real deadline of the course will be after two weeks, it is time for me to start using the information from the tool:

  • I can easily send email to the student not having recent commits, by clicking on the (redacted) blue text where student name is displayed – that will initiate an email I will send to the student.
  • Clicking on the repository URL (also redacted) will open the browser and take me to the remote repository web page of that student.
  • Another (redacted) blue line will open the local folder in Finder for me to start looking at the student project directory on my machine.

Those repositories in blue are all OK, and (probably) I do not need to be concerned with those. Especially if the scheduled tests also pass. The purpose of the tool is to let me focus on those students that probably need attention to be able to pass the course in time.

Some implementation details:

  • Implemented on macOS using Xcode, Swift and SwiftUI.
  • Uses Core Data as the app database, with five database tables and ten relationships between the tables.
  • Executes git and mvn test commands in child processes using Process class.
  • SwiftUI Table used for tabular content.
  • Commit grid is draw in a SwiftUI view using Canvas and GraphicsContext.
  • Uses the SwiftUI redacted(reason:) function to hide student information for demonstration purposes.
  • Student and repository data is imported from a tab separated text file exported from Moodle. There, student enter their information and the remote repository URL in a questionnaire form. The form data is then exported as a tsv file, which is imported to the app and all student data is written to the database. No need to enter the student data manually.

Decoding and encoding class hierarchies in Swift

A while ago I was implementing (for fun) a chat client to work with a chat server used in teaching in a GUI programming course. The client is implemented with Swift and SwiftUI.

In the GUI programming course, students get the server and a sample console client, both implemented in Java. The goal for the students is to both design and implement a GUI chat application. Learning goals are related to GUI design, usability design and implementation of a GUI in a selected language and GUI framework. The server is accessed over TCP and data format is JSON.

One tricky thing was to figure out how the Swift Codable could handle a class structure with a base class Message, having different types of messages as subclasses. For example, ChatMessage (having the sender, message, timestamp, etc.), a ListChannelsMessage (containing the available channels on the server side to join), et cetera.

The Java console client class diagram, containing the same message classes as the Swift app.

The Swift Codable does not directly and simply bend to this kind of a class hierarchy. I searched the net and found a good basis here, but it didn’t fully show how to do both decoding and encoding with a class structure like I had.

So obviously, for fun, I banged my head against the wall until I got it working. I was supposed to write a blog post about that, but haven’t had the time.

But today someone in Mastodon asked the exact question; how to do something like this. A good motivation for me to actually do something about that! I didn’t want to publish the whole Swift Chat client app, since students are still able to start working on this project, and someone might want to select Swift/SwiftUI as the GUI for their app.

So instead, I extracted the code to show how to use Codable and JSONSerialization together to handle a class hierarchy like this to encode and decode objects to JSON and back. The code is now available as a simple example project in GitHub.

I shared the repository to the Mastodon discussion. What was exciting for me is that one of the core persons in developing the Swift language itself favourited my reply! 🤯