Einer der Besten von Xkcd aller Zeiten:

Fortunately, the charging one has been solved now that we’ve all standardized on mini-USB. Or is it micro-USB? Shit.

Leider ist der Eintrag nur auf Amerikanisches Englisch verfügbar. Der Inhalt wird unten in einer verfügbaren Sprache angezeigt. Klicken Sie auf den Link, um die aktuelle Sprache zu ändern.

Yes, I am still using AntTweakBar. As you might know, the development of AntTweakBar is discontinued. At some point in the future, I will switch. Currently, I consider imgui the best successor. But I haven’t had time to look into imgui. So, when I resurrected an old small tool of mine, it still used ATB, and I did not want to recode all of this. But out of „because-I-can,“ I decided  to update all dependencies to their newest versions. As a result the ATB integration with GLFW 3 did not work any longer. A couple of callback functions where changed between GLFW 2 and GLFW 3. I ended up rewriting my glue code between those two libraries.

Here it is, if any of you ever come across the same issue. First the callbacks:

static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
#ifdef HAS_ANTTWEAK_BAR
  if (action == GLFW_PRESS || action == GLFW_REPEAT)
  {
    int twMod = 0;
    bool ctrl;
    if (mods & GLFW_MOD_SHIFT) twMod |= TW_KMOD_SHIFT;
    if (ctrl = (mods & GLFW_MOD_CONTROL)) twMod |= TW_KMOD_CTRL;
    if (mods & GLFW_MOD_ALT) twMod |= TW_KMOD_ALT;

    int twKey = 0;
    switch (key)
    {
    case GLFW_KEY_BACKSPACE: twKey = TW_KEY_BACKSPACE; break;
    case GLFW_KEY_TAB: twKey = TW_KEY_TAB; break;
    //case GLFW_KEY_???: twKey = TW_KEY_CLEAR; break;
    case GLFW_KEY_ENTER: twKey = TW_KEY_RETURN; break;
    case GLFW_KEY_PAUSE: twKey = TW_KEY_PAUSE; break;
    case GLFW_KEY_ESCAPE: twKey = TW_KEY_ESCAPE; break;
    case GLFW_KEY_SPACE: twKey = TW_KEY_SPACE; break;
    case GLFW_KEY_DELETE: twKey = TW_KEY_DELETE; break;
    case GLFW_KEY_UP: twKey = TW_KEY_UP; break;
    case GLFW_KEY_DOWN: twKey = TW_KEY_DOWN; break;
    case GLFW_KEY_RIGHT: twKey = TW_KEY_RIGHT; break;
    case GLFW_KEY_LEFT: twKey = TW_KEY_LEFT; break;
    case GLFW_KEY_INSERT: twKey = TW_KEY_INSERT; break;
    case GLFW_KEY_HOME: twKey = TW_KEY_HOME; break;
    case GLFW_KEY_END: twKey = TW_KEY_END; break;
    case GLFW_KEY_PAGE_UP: twKey = TW_KEY_PAGE_UP; break;
    case GLFW_KEY_PAGE_DOWN: twKey = TW_KEY_PAGE_DOWN; break;
    case GLFW_KEY_F1: twKey = TW_KEY_F1; break;
    case GLFW_KEY_F2: twKey = TW_KEY_F2; break;
    case GLFW_KEY_F3: twKey = TW_KEY_F3; break;
    case GLFW_KEY_F4: twKey = TW_KEY_F4; break;
    case GLFW_KEY_F5: twKey = TW_KEY_F5; break;
    case GLFW_KEY_F6: twKey = TW_KEY_F6; break;
    case GLFW_KEY_F7: twKey = TW_KEY_F7; break;
    case GLFW_KEY_F8: twKey = TW_KEY_F8; break;
    case GLFW_KEY_F9: twKey = TW_KEY_F9; break;
    case GLFW_KEY_F10: twKey = TW_KEY_F10; break;
    case GLFW_KEY_F11: twKey = TW_KEY_F11; break;
    case GLFW_KEY_F12: twKey = TW_KEY_F12; break;
    case GLFW_KEY_F13: twKey = TW_KEY_F13; break;
    case GLFW_KEY_F14: twKey = TW_KEY_F14; break;
    case GLFW_KEY_F15: twKey = TW_KEY_F15; break;
    }
    if (twKey == 0 && ctrl && key < 128)
    {
      twKey = key;
    }
    if (twKey != 0)
    {
      if (::TwKeyPressed(twKey, twMod)) return;
    }
  }
#endif
}

static void charCallback(GLFWwindow* window, unsigned int key)
{
#ifdef HAS_ANTTWEAK_BAR
  if (::TwKeyPressed(key, 0)) return;
#endif
}

static void mousebuttonCallback(GLFWwindow* window, int button, int action, int mods)
{
#ifdef HAS_ANTTWEAK_BAR
  if (::TwEventMouseButtonGLFW(button, action)) return;
#endif
}

static void mousePosCallback(GLFWwindow* window, double xpos, double ypos)
{
#ifdef HAS_ANTTWEAK_BAR
  if (::TwEventMousePosGLFW((int)xpos, (int)ypos)) return;
#endif
}

static void mouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
{
#ifdef HAS_ANTTWEAK_BAR
  static double pos = 0;
  pos += yoffset;
  if (::TwEventMouseWheelGLFW((int)pos)) return;
#endif
}

static void resizeCallback(GLFWwindow* window, int width, int height)
{
#ifdef HAS_ANTTWEAK_BAR
  ::TwWindowSize(width, height);
#endif
}

Of course, you can omit the #ifdefs if you don’t care. Add your own codes to the functions after ATB has been handled.

Then, it’s just your typical initialization of GLFW callbacks:

::glfwSetKeyCallback(window, keyCallback);
::glfwSetCharCallback(window, charCallback);
::glfwSetMouseButtonCallback(window, mousebuttonCallback);
::glfwSetCursorPosCallback(window, mousePosCallback);
::glfwSetScrollCallback(window, mouseScrollCallback);
::glfwSetWindowSizeCallback(window, resizeCallback);

Even the powerful, tart Granny Smith cultivar is proving ineffective against new Gran-negative doctors.

Ja, albern. Aber ich hab so gelacht. Tatsächlich, während ich diesen Post hier schreibe und den Strip wieder lesen … ich kicher die ganze Zeit. Bescheuert. Und gleichzeitig vielleicht eine der bösesten Satiere seit langem.

Vor einiger Zeit haben zwei Kollegen etwas Zeit und Aufwand investiert um unsere Haupt-Code-Base und unsere Build-Chain auf Visual Studio 2017 und den C++17-Standard zu haben. Eine sinnvolle Aktion. Aber natürlich war das auch Grund genug, dass ein anderer Kollege und ich dann rumgewitzelt haben, dass wir unseren Code downgraden sollten, auf C++03, C++98, oder vielleicht sogar direkt auf C. Keine sorge, wir haben alle vier gut gelacht. Oder?

Zu der Zeit hat mich der Rumwitzel-Kollege auf einen Artikel von aras-p über „Modern C++ Lamentations“ aufmerksam gemacht. Lesen! Der ist gut. Und denkt nicht „das ist vielleicht in der Computerspieleindustrie so, trifft aber für mich nicht zu.“ Ich arbeite nicht in der Computerspieleindustrie, und auf meine Arbeit trifft das ganze Zeug ziemlich 100%ig zu.

Meiner Meinung nach ist  „modernes“ C++ zu komplex, zu aufgeblasen, zu angeberisch: „schaut her wie cool mein code ist“. Hier wird ganz das Ziel verfehlt, nämlich Probleme zu lösen.

[…] to me this feels like someone decided that “Perl is clearly too readable, but Brainfuck is too unreadable, let’s aim for somewhere in the middle”.

Viele neue Sprach-Features sind sinnvoll, andere sind vielleicht nur „cool“. Natürlich sieht das jeder anders und findet andere Aspekte sinnvoll. Es gibt aber Dinge die objektiv gesehen schlecht sind. Der Artikel von aras-p zeigt hier schön die Probleme von Compile Time und Debug Performance. Das sind berechtigte Gründe.

C++ compilation times have been a source of pain in every non-trivial-size codebase I’ve worked on. […] Yet it feels like the C++ community at large pretends that is not an issue, with each revision of the language putting even more stuff into header files, and even more stuff into templated code that has to live in header files.

In der Schule war ich Hobby-Programmierer; dann Student in Software Engineering und Teilzeit-Programmierer nebenher; dann habe ich meinen Doktortitel in Informatik gemacht, Schwerpunkt in Computergraphik und Visualisierung, und habe parallel eine großes modulare, high-performance Visualisierungssoftware geschrieben; dann war ich Senior Software Engineer in einer Firma mit einer recht großen Software; und jetzt bin ich Manager eines Teams von Software-Entwicklern. Ich denke ich kann sagen, ich hab die meiste Zeit meines Lebens programmiert. Ich mach immer noch Kleinigkeiten und kleine Bug fixes in unserem Code, selbst als Manager. Vermutlich denk sich mein Team, ich soll endlich die Finger von „ihrem Code“ lassen. Werde ich nicht. Aber, was ich sagen will:

Ich bin praktisch mein ganzes Leben schon Programmierer. Und dabei habe ich in weiter über einem Duzend verschiedener Sprachen gearbeitet (während dem Schreiben dieses Artikels kam ich auf 15, ohne Script-Sprachen. Aber wahrscheinlich hab ich auch welche vergessen.) Mit dieser Erfahrung nehme ich mir heraus zu sagen:

C++ ist nicht die beste Programmiersprache. Modernes C++ hat nicht alles besser gemacht.

Bitte! Fangt (wieder) an euch zu fragen „wie löse ich dieses Problem“, anstatt „wie löse ich dieses Problem mit variadic Templates in Lambdas mit Ranges, weil das alles so cool ist“.

Als ich an der Universität meine Vorlesung zu „C++ für Computergraphik“ gehalten habe, da konnte man die ganzen unterschiedlichen Typen der heranwachsenden Programmierer klar und deutlich sehen. Und das gibt es diese eine besondere Teilspezies der „Programmierkünstler“. Programmierer die ihren Code für Kunst halten, und über all diese gewöhnlichen Programme erhaben. Das werde ich jetzt erstmal nicht weiter kommentieren. Aber ich glaube festgestellt zu haben, dass diese Typen in Umgebungen wo C++ eingesetzt wird sehr häufig anzutreffen sind. Leider.

Als Abschlussbemerkung: Wenn ich heute ein neues Programmierprojekt starte, und ich darüber nach denke welche Programmiersprache(n) ich dafür einsetze, dann ist C++ nicht mehr oben auf der Liste.

Leider ist der Eintrag nur auf Amerikanisches Englisch verfügbar. Der Inhalt wird unten in einer verfügbaren Sprache angezeigt. Klicken Sie auf den Link, um die aktuelle Sprache zu ändern.

One of my old computer science professors, back in the days, used to say, if you use a debugger while you are writing your code, you are a bad programmer. My, oh my. What an idiot. It makes perfect sense to utilize a debugger as you proceed in completing your program. It’s a simple variant of divide and conquer. Let’s make sure one part does work, before we move on to the next. So, you see, I really value my debugger.

Many small tools I write are simple console applications. I do like graphical user interfaces a lot. And I prefer a graphical user interface over a command line interface any time. But for some small tools, especially ones which do not even require any interaction, setting up a graphical user interface is just too much work. So, even so it really is very old-school, console applications are often the right choice.

This brings us to developing console applications and utilizing the debugger. Visual Studio has a very nice feature for this scenario, when working with c++: it keeps the console window open and reuses it. At first this might seem useless. I know a lot of people which just close the window every time their application stops. But there is a clear and huge benefit from this function: since the console window stays open, you can inspect you application’s output for as long as you like without having to keep the debugger attached or starting your application in a separate console. This actually is really handy.

For csharp console applications, however, this feature does not exist. I really do not know why. And, I hope the Microsoft will deliver this feature soon for csharp applications as well. But for now, csharp has this horrible behavior that the console window closes as soon as the application exits. And this brings us back into the past, where we need some mechanism to keep the window open. One possibility is to utilize the debugger, which is attached anyway, to pause the application. I don’t want to do this using “normal” break points, as I use break points to do actual debugging. Meaning, I often delete all break points, and then only set those I need. Having to take care for some “special” break points would be a pain in the … well, you know.

Luckily, we can break the debugger by code. Whipping up some utility class, I got this here:

static class DebugHelper
{
  [Conditional("DEBUG"), MethodImpl(MethodImplOptions.AggressiveInlining), DebuggerHidden]
  static public void Break()
  {
    bool launch;
    var env = Environment.GetEnvironmentVariable("LAUNCH_DEBUGGER_IF_NOT_ATTACHED");
    if (!bool.TryParse(env, out launch))
      launch = false;
    if (launch || Debugger.IsAttached)
    {
      if (Debugger.IsAttached || Debugger.Launch())
        Debugger.Break();
    }
  }
}

Now, I can just call DebugHelper.Break(); anywhere I like.

They are removed in release builds. And the aggressive optimization removes the helper function from the stack, so that the debugger always breaks at the call of my helper function, and not within.

For now, this is handy. And, I really hope, that in the near future this will be obsolete.

Ich bin ein visueller Kerl. Das heißt, ich mag alle möglichen Arten von visuellen Repräsentationen abstrakter Daten. Natürlich mag ich also auch die ganzen fetzigen Badges die überall im Internet rumfahren. Es macht also nur Sinn dass ich die auch selber nutze.

Shields.io stellt Badges für Source-Code-Zeug zur verfügung. Und so, ohne Umschweife, hier ist die visuelle Zusammenfassung aller Nuget-Pakete die ich betreue:

Es ist Zeit einen meiner Lieblingsstrips von xkcd zu rebloggen: tar

I don’t know what’s worse–the fact that after 15 years of using tar I still can’t keep the flags straight, or that after 15 years of technological advancement I’m still mucking with tar flags that were 15 years old when I started.

Es gibt viele solche Tools die noch heute benutzt werden, obwohl sie von Anfang an Müll waren. Jaja, das Beispiel hier macht sich über Nix lustig. Es gibt aber auch viele ähnliche Beispiele aus dem MS-Windows-Ökosystem.

Ich mach mich gar nicht über diese Tools lustig. Ich mach mich über die Leute lustig die noch heute diese Tools befürworten!

Ich habe meinen alten Webhoster hinter mir gelassen und meine Webseite umgezogen.

Das war jetzt dringend nötig.

Ich hab auch das WordPress aktualisiert. Nun scheint das Plugin für mehrsprachige Posts nicht mehr richtig mit dem Editor zu funktionieren. Naja. Das ist ein Problem für ein anderes Mal.

Leider ist der Eintrag nur auf Amerikanisches Englisch verfügbar. Der Inhalt wird unten in einer verfügbaren Sprache angezeigt. Klicken Sie auf den Link, um die aktuelle Sprache zu ändern.

HtmlAgilityPackAs can be read on the internet: HtmlAgilityPack is not for beautiful, aka human readable, html files.

“[…] it’s a ‘by design’ choice.” [https://stackoverflow.com/a/5969074]

So everyone redirects you to some other library.

Now, I am a bit stubborn. I want to use HtmlAgilityPack and I want to have indented, human-readable html files. The magic is within text nodes in the DOM. So, I wrote two utility functions to help me out.

First, to get rid of all unwanted whitespaces. This one might be a bit aggressiv, but it was ok for me:

static private void removeWhitespace(HtmlNode node) {
  foreach (HtmlNode n in node.ChildNodes.ToArray()) {
    if (n.NodeType == HtmlNodeType.Text) {
      if (string.IsNullOrWhiteSpace(n.InnerHtml)) {
        node.RemoveChild(n);
      }
    } else removeWhitespace(n);
  }
}

And, second, to create white spaces for line breaks and indentions:

internal static void beautify(HtmlDocument doc) {
  foreach (var topNode in doc.DocumentNode.ChildNodes.ToArray()) {
    switch (topNode.NodeType) {
      case HtmlNodeType.Comment: {
          HtmlCommentNode cn = (HtmlCommentNode)topNode;
          if (string.IsNullOrEmpty(cn.Comment)) continue;
          if (!cn.Comment.EndsWith("\n")) cn.Comment += "\n";
        } break;
      case HtmlNodeType.Element: {
          beautify(topNode, 0);
          topNode.AppendChild(doc.CreateTextNode("\n"));
          //doc.DocumentNode.InsertAfter(doc.CreateTextNode("\n"), topNode);
        } break;
      case HtmlNodeType.Text:
        break;
      default:
        break;
    }
  }
}

private static bool beautify(HtmlNode node, int level) {
  if (!node.HasChildNodes) return false;

  var children = node.ChildNodes.ToArray();
  bool onlyText = true;
  foreach (var c in children) {
    if (c.NodeType != HtmlNodeType.Text) onlyText = false;
  }
  if (onlyText) return false;

  string nli = "\n" + new string('\t', level);

  foreach (var c in children) {
    node.InsertBefore(node.OwnerDocument.CreateTextNode(nli), c);
    if (c.NodeType == HtmlNodeType.Element) {
      if (c.HasChildNodes) {
        if (beautify(c, level + 1)) {
          c.AppendChild(c.OwnerDocument.CreateTextNode(nli));
        }
      }
    }
  }
  return true;
}

As you might see, the code is pretty hacky. But, it works for me. Maybe, it also works for you, or it can be a starting point.