Coding

Entries mainly about programming, but not nececssarily specific to WWII Online

Alexa addendum

The other day I gave Amazon a hard time for the difficulty of extending Alexa for your own in-house needs. Well, “skills” are actually more accessible than I thought and there are some tutorials – setup … something … in “under an hour“,  or write a controller with “python with flask-ask“.

That brings it a lot closer to being in the hands of the lay-maker, but the setup on Amazon’s side leaves things in a state that will probably result in much sloppiness. I’m also not clear, yet, whether you are limited to “tell” and “ask” directives or if you can create first-class Alexa commands with it.

Going to get a hub and some lights today, get that working, and then some time this week I’ll see if I can implement “Alexa, open Notepad”.

Challenge to Assistant developers

Apple, Google, Microsoft and Amazon are all competing in the digital assistant field. There are pros and cons to each. Yesterday I received an Amazon Echo Dot (2nd gen) and I’ve been dabbling with it. So far Alexa reminds me more of the command-driven voice apps I tinkered with on the CBM Amiga decades ago than she does of Hal, but there is promising progress.

You’ve heard me rant about Cortana, I don’t have a Siri to tinker with and while I’ve had a highly positive experience with Google’s voice recog, for some reason I just haven’t used it in anger – I’ll try and remedy that in the next week or so.

But having the discrete device like this finally gave form to the notion that’s been percolating in the back of my head this last year or so of watching the assistants emerge: Makers.

One of these assistants needs to cross the bridge for home enthusiasts that empowers them to interact with their devices and applications in their terms.

I should be able to rustle up a few dozen lines of code and create my own little agent that transforms into a feature of my assistant exclusive to me and my ecosystem. Once I can do that, someone will build tools to make it easier and more accessible for idea people who aren’t interested in learning to program.

The problem is that to thrive, it’s going to have to be open. Hold your horses there, I’m not anti-proprietary, I’m just stating this simple fact. Apple and Siri aren’t contenders because the winner is going to be enabling a farmer who got his kids to write a raspberry-pi controller to check on his irrigation system from 10 miles away.

I don’t see Alexa being the winner, because her value in is selling Amazon Prime and Amazon Prime Music subscriptions. I suspect anything beyond that is gravy of the cold, lumpy kind from an Amazon perspective, but I’m happy to be proven wrong.

That leaves Google and Cortana.

Google sells advertising, but they have a history of open APIs. Bringing makers into the fold and enabling personalization has all kinds of value potential to Google, starting with bringing you into the android fold, disinsentivizing you from using Apple or Amazon, etc.

Microsoft is built on the success of open architecture and they’re making a large push to support IoT stuff, so this would be a return to roots for Microsoft that could really make WinIoT attractive, so long as they can manage to focus on the role of a driver and not try to restrict it to “must run on Windows”.

There is one more potential contender, though: Facebook.

Mark has shown an interest in exactly this kind of field with Jarvis. They’ve invested a lot in AI, they like releasing the stuff they build into the community. Their mission statement is “to make the world more open and connected”. This notion fits in with the ideas behind Facebook’s internet.org

It’s not that it’s currently impossible to do these things, but there’s a huge barrier to entry. For example, the simple task of turning on (or off) my PC? Voice control is largely going to be about inter-action; set the heating in another room, check on the house while you’re away, remind me of something in 30 minutes when I might be in a different room or building or vehicle…

(*Edit: You can actually build your own Alexa skills. But it’s definitely not entry-level stuff)

Pi for kids?

Last year I gave my nephews an arduino starter kit as a present. They’re really bright, so it just made sense to them. Faster than I could demonstrate that wiring up the button and the lights let them create a control they’d already figured it out and wanted to know what else it could do.
 
I realize now it was handing someone of my generation a battery, some cash, and saying “you can power anything with this”. It fuels the path of creativity without nurturing it.
 
This year I was going to give them a raspberry-pi starter kit but it’ll just wind up being a way to run games if there’s not something to fuel and guide their imagination a little.
 
“It can do anything electronic”. “Like what?” “Uh, like, uhm, drive a motor” “Oh, to do what?” “Look, this is why I’m a programmer, just imaginate some stuff, squirt!”
 
And they’re too young for me to point them at “forums”. So:
 
I’m hoping some of you might be able to recommend maybe some kits, books, perhaps online courses or guides for a variety of beginner, entry/kid-level projects that include the programming but perhaps focus on the more physical aspect of doing things. They’re *not* gonna want a series of tutorials on how to make different patterns of blinking lights, they’re going to want something that demonstrates practical potentials and – ideally – gives them reason to go to the store with their parents and see the aisle of potential components they might tap into to fire off their little imaginations.
 
Ideas?

Virtualized desktops vs multi-boot

I’m trying to figure out a good way to compartmentalize/containerize my various Windows desktop usage modes: Development, gaming and general use. This seems like a good way to combat a number of things such as the surface-area of each model (exposure to risk) and things like registry bloat etc.

With fast boot times, multi-boot isn’t a terrible idea. But I kind of have this notion in my head of having a graphical Dom 0 (Win10, Ubuntu, something) where I can see my guests as windows and use them thusly, paste, drag’n’drop between them, etc, but have the option to quickly transition them to full screen at any time.

I found (thanks to Bill Hulley) that KVM can do some of this (https://bufferoverflow.io/gpu-passthrough/) but it sounds brittle/fragile to me, and I’m increasingly wary of this level of hackery for supporting such aggressively-evolving systems as GPUs, stuff gets abandoned, APIs and ABIs change, a maintainer drops out…

Having two user accounts might be an option, but they share the same HKLM and things like MSVC aren’t great at being discrete.

Windows Containers sound interesting, but I don’t know that there’s a way for the app inside a container to expose a GUI on the host, all the instructions I’ve found so far are for server-based containers. So for now, I’m just gonna continue putting all my eggs into the one basket :)

Would the interviewer be right?

Please avoid stating which problem these are solutions for.

During a recent discussion the following code was suggested

int desc(const Node* node, int d)
{
  int l = d, r = d;
  if (node->l) l = desc(node->l, d + 1);
  if (node->r) r = desc(node->r, d + 1);  // edit: thanks, Nico
  return max(l, r);
}
int d2(const Node* root)
{
  return root ? desc(root, 1) : 0;
}

One of the folks in the discussion shook his head and said: “If this was an interviewer, they would want you to do it in one function, though”. Then he presented this:

int d1(const Node* root)
{
  if (root == nullptr) return 0;
  return max(d1(root->l) + 1, d1(root->r) + 1);
}

Then he made the assertion “this is what an interviewer would be looking for”.

Happy new year

To the random individual still tuned in, a happy new year to you.

I’m still at Facebook, no evidence of it being the evil empire folks want to believe it is. Rather, a collection of folks who worry about the same things you do, who care about privacy not least because their mom is on Facebook too.

I’ve been playing Crypt of the Necrodancer, Faster than Light (which I didn’t play when it was hot and new) and a lot of Kerbal Space Program.

I’m starting to feel I’m done with KSP now, though; I can launch to orbit, even recover small payloads from orbit with a recovery ship, I’ve built a (crappy) station.

I squeezed some extra longevity out of the game with mods including MechJeb (an autopilot, so I could focus on building rather than flying, because I just find the flying part tedious key-holding). But I haven’t flown a rover, built a base on another planet, manned mission to Duna etc.

It may be because I don’t feel “free” to experiment with stuff before I launch it into space. I’ve built rovers and driven around KSC with them but I’ve no clue how I would get it into space and drop it anywhere useful. (It doesn’t help that stock fairings are broken in 1.0.5 and turn any rocket into Tippy McSplodey).

Development-wise, nothing exciting to report at the moment. I’m building up a hankering to get my teeth into C++14 and ++17 properly, but I’m lacking a good project to work on and a good description of what the changes are to actually rustle up a project.

Talking with the new team at CRS/Playnet, I’m filled with a lot of confidence. I think the clean break is going to prove good for the guys, they’re clearing away the dead bodies that the old team — self included — were stumbling around. I’m really looking forward to them having a successful 1.35 launch. We left them a lot of landmines, so … be gentle on them.

And now for something completely similar.

So I’m back on the job market. Lots of ideas and inspiration from my time at Blizzard, a really great place to work. No, I won’t tell you. I already have a few job apps out, and I’m trying to stick to the US west coast and gaming.

I’ve been in the games industry proper for near 12 years now, and while that’s where I’m going to look first, I’m going to be open to possibilities back in the real world.

Right now I’m toying with the idea of a C++-centric code templator I’m thinking of calling “C[]” (C-squared); something that can handle trivial cases like “take this list of words and generate an enum statement and an array of strings” to the ability to generate multiple complex code modules from shared definitions.

Private private members

Private private members

Visualization of the concept in “Breaking up is hard to do“.

GNU sizeof, how odd

Apparently, GCC doesn’t like the following second version of this simple piece of code:

size_t sizeInt = sizeof(int);    // Compiles on GCC, ICC and VS.
size_t sizeInt = sizeof((int));  // Compiles on ICC and VS.

GCC complains:

expected primary-expression before ‘int’

Sigh.

Breaking up is hard to do (to member functions)

Want to bounce this off some other coders before I make a language-change proposal of it:

C#’s “partial” class type lets you spread a class definition across multiple files. But mostly people use it as a way to make private code definitions private – split large functions up into little nuggets that don’t get exposed in the primary API while still having membership status to access member variables, etc.

The downside is: it actually lets you add crap to the class in your own definitions, forming part of the need for the “sealed” accessor type in C#.

In C++ your choice is (a) huge member functions, (b) Pimpls, (c) classes that list zillions of private members in their public API.

Seems to me, a simple combination of existing keywords would let you create non-public, compilation-unit scoped temporary member functions so you can break a large member function up without all the hassles that come from breaking a member function into private local non-member functions.

Specifically the term “private”.

By marking them this way, the following constraints/restrictions/behaviors would naturally fall out of the current language definition:

  • Cannot be virtual (if it goes in the vtable, it goes in the ‘class’ def,
  • Cannot be abstract (since you’d have to declare it in the class),
  • Cannot share a name with a well-defined member function or variable,
  • Not visible to derived classes even if they are in the same compilation unit, (as applies to any ‘private’ member)
  • Cannot be an operator, (that could lead to some nightmare situations)
  • Cannot be static (static members aren’t limited to ‘public’ access, so there are actually good use cases for ‘private static’)
/// Header file Foo.h
class Foo {
public:
  Foo() : m_bar(“”), m_i(0) {}
  void bigFunction();
  void otherFunction();
private:
  void privateFunction();
};

 

/// Foo1.cpp
#include “Foo.h”

private void Foo::helper1() {
  m_bar = “hello”;
  m_i = 1;
}

private inline void Foo::helper42() const; // prototype variant.

void Foo::bigFunction() {
  helper1();      // member call
  …
  helper42();	// member call
}

void Foo::helper42() const {
  m_bar = “world”;
  m_i = 42;
}

class Bar : public Foo {
  …
  void barMember() {
    helper42(); // Error: it was private to Foo.
  }
};

 

/// Foo2.cpp
#include “Foo.h”

private void Foo::helper1() {
  // Legal, because helper1() was private-unit-scoped in Foo1.cpp and is thus not visible here.
}

private void Foo::privateFunction(const char* const message) {
  // ERROR: The finger print is different but the name conflicts with an established
  // ERROR: member function name, so this isn't legal.
}

void Foo::otherFunction() {
  helper1();	// Invokes the helper1() declared in Foo2.cpp above.
  …
  helper42();	// Error: helper42 is only unit-visible in CPP file #1.
}