Skip to content

Instantly share code, notes, and snippets.

View cies's full-sized avatar

Cies Breijs cies

View GitHub Profile
@cies
cies / exceptions.md
Created November 7, 2019 13:55
xceptions in general and in Java/Kotlin/TS in particular

Exceptions in general and in Java in particular

The use of exceptions for anything but unrecoverable errors is greatly contested in programming. In this article we try to shed some light on this matter. But before we start digging deeper, here some considerations:

  • Unrecoverable is not very well defined. Sometimes it makes sense for software to crash: print some final log lines, try to do some cleanups and abort. Sometimes it does not: when we are in some code that simply needs to fail hard at that particular task/job/request (and surely log the "bug hinting error") but remain in service. Unrecoverable could also mean: cannot continue without a retry.

  • There is a common phrase "exceptions should be used for exceptional conditions; things you don't expect to happen" which does not add much to the discussion. What is truly exceptional is about as vague as truly unrecoverable.

  • Some languages, notably Java (but not Kotlin!), allow for "checked" exceptions. In Java these checked exceptions (inheriting fr

@cies
cies / exceptions.md
Last active November 8, 2019 09:03
Exceptions in general and in Java/Kotlin/TS in particular

Exceptions in general and in Java in particular

The use of exceptions for anything but unrecoverable errors is greatly contested in programming. In this article we try to shed some light on this matter. But before we start digging deeper, here some considerations:

  • Unrecoverable is not very well defined. Sometimes it makes sense for software to crash: print some final log lines, try to do some cleanups and abort. Sometimes it does not: when we are in some code that simply needs to fail hard at that particular task/job/request (and surely log the "bug hinting error") but remain in service. Unrecoverable could also mean: cannot continue without a retry.

  • There is a common phrase "exceptions should be used for exceptional conditions; things you don't expect to happen" which does not add much to the discussion. What is truly exceptional is about as vague as truly unrecoverable.

  • Some languages, notably Java (but not Kotlin!), allow for "checked" exceptions. In Java these checked exceptions (inheriting fr

@cies
cies / elm-course.md
Last active March 5, 2021 12:57
Prepare for the Elm Course

Install Elm and IntelliJ

For the course we will use the programming language Elm.

It is possible to use an online Elm environment name Ellie: in that case there is nothing for you to install.

But you can also install Elm and a code editor (IntelliJ) with the Elm plugin. This has some advantages:

  • You do not depend on the internet working
@cies
cies / intro-to-elm.md
Last active March 5, 2021 11:01
A beginner's introduction to Elm (0.19.1)

Elm: Elegant browser programs

Elm is a programming language that compiles to JavaScript (the main language understood by web browsers).

Contrary to some other programming languages (like C, C++, Java or Rust), Elm is not "general purpose", it is designed specifically to create web applications.

What makes Elm unique:

  • Easy to get started, as it...

Simple games ideas for trying out Elm

For some of these game you will need "random numbers".

Here's the official guide on doing random in Elm. To get the example to work in Ellie you need to add a module definition on top (the compile error will guide you in the right direction) and add the Random package from the "Package" menu (see package icon) on the left.

The game ideas:

  • Write function that translates a text to Pig Latin and back.

Vereisten voor de Elm cursus

Korte link naar deze pagina: bit.ly/3kL1FIT

Ieder heeft een van de volgende twee setups nodig:

  • Met Elm en IntelliJ geinstalleerd (zie hier de installatie instructies):
    • IntelliJ met myproject open waar het plus min voorbeeld in staat
  • een terminal met elm repl (kun je stukjes testen)
@cies
cies / reversed-subtraction.rb
Created November 9, 2022 07:38
Research patterns in "reverse substracting" numbers from themselves
#!/usr/bin/env ruby
# Bit of code to research patterns in "reverse substracting" numbers from themselves. Observations:
# * Mostly they reduce to zero; this can be by several routes:
# * Quick
# * 9's route (also: 99, 909, 999, 9009, 9999, 90009, 99099, 99999, etc.)
# * 54-45 route (also: 54945, 549945, 5499945, 54999945, etc.)
# * End up in a loop, which is always by route of a 2 sets of "magic numbers":
# * 2187, 21987, 219987, 2199987, 21999987, etc.
@cies
cies / gradle_snippet.kt
Created May 31, 2023 10:02
Make Gradle print its task plan
// This prints the dependencies of each task in the current execution graph
gradle.taskGraph.whenReady(
closureOf<TaskExecutionGraph> {
println("About to run ${allTasks.size} tasks: (use `-i` to see why tasks are skipped, use `--rerun-tasks` to prevent UP-TO-DATE checks)")
allTasks.forEachIndexed { i, task ->
val dependenciesString =
if (task.dependsOn.isEmpty()) {
""
} else {
task.dependsOn.joinToString(", ", " (depends on ", ")") { dependency ->