Pages

Thursday, August 27, 2020

Day 9: What a Week

Work Has Been Crazy

To all the teachers out there who have to keep smiling while also having anything else in their life demand their attention, I SALUTE YOU!  We've been having intermittent server woes since Tuesday morning at my j-o-b, but my wife has kindly pointed out we can't do new topics every day, so we've been reviewing things this week that we went over last week: primitives, flow control, basic objects, arrays and collections.

Today We Cover String Manipulation

In her example code, she has been using file names that have reusable folders leading up to their location (to represent sound files in her game).  After a quick lesson in String manipulation, she will be able to simplify all those paths using a variable to cover the destination path.  She is also going to extend her randomized Fight class to choose names of Hero objects from a pool, emulating a gladiator-style tournament.

I'm debating giving her a pop quiz tomorrow.  I love my kid, but I feel like she needs to visually see an indicator of her progress.  The good news is, I have been quizzing her verbally since the day we started and I know it's clicking.  I also installed Eclipse and have started letting her use an IDE to simplify code execution during our lessons.  I still require her to prove she remembers how to compile from the command-line, but being able to modify code and click "run" helps us cover a lot more ground in an hour.

[NEW] Open-Source Library of the Week: JLayer

I have decided to introduce one new library a week for her to get an idea of what is out there, how it is packaged up, and how to search for things you might need.

Name Category License Description
JLayerAudioLGPLmp3 decoder/player/converter
<!--https://mvnrepository.com/artifact/javazoom/jlayer-->
<dependency>
    <groupId>javazoom</groupId>
    <artifactId>jlayer</artifactId>
    <version>1.0.1</version>
</dependency>
JLayer bypasses all the painful parts of Java audio (ridiculous MP3 woes, frame rates, cpu glitches, etc.), allowing you to simply create sound objects and play them. There are no blood sacrifices required, no pro services sound engineers on-hold. It just works the way you expect everything in life to work (but that usually doesn't). It works like it says: simply. 

Be advised: JLayer uses a reciprocal license (LGPL). For clear explanation of what using this type of OSS license requires of you, please go to opensource.org.

Wednesday, August 26, 2020

Day 7/8: Rushed

 I gave her two days to chew on the topics we've covered.

Monday, August 24, 2020

Day 6: Arrays and Collections

Object Evolution

She has recognized and learned how useful instance variables are to her game.  I think part of why she is getting this so quickly is that I introduced her to making her own dice-based games when she was 5.  With games like Pathfinder/D&D, Shadowrun, and Battletech obviously a bit much for someone that age, it was still valuable to get her a few dice and show her how to map out what each of the values mean when rolled (after which we spent hours coming up with insane monsters to randomly run into in our adventures).

Fights usually went something like this:  "roll a d6 when encountering a hostile creature, 1 = creature bored runs away, 2=miss, 3=hit for d4 damage, 4=d10 damage, 5=d20, 6=headshot monster dies."

Within her game's list of components, each:
  • Hero has a name, life, gold, weapon,
  • Weapon has a name, attack, effect,
  • Attack has a name, value, range, 
  • Monster has a name, life, weapon, boss.

She has also realized that she needs to store additional sets of items that may be plural (some obvious, some not-so-obvious):
  • Combo → a list of attacks performed in order that trigger a special attack
  • SpriteList → a set of image tiles that describe movement over time
  • Gang → a group of Monster objects that when killed as a whole drop additional loot
  • LootTable → potential loot drops with chance rates per Monster or Gang


Additional Math Operations

To realize the benefit of sprites and loot, we will also be discussing the modulus operator (%).  The simplest way of performing smooth tiled movement over time is to have a group of sprites for each direction that cycle (independent of CPU speed).  This can be accomplished by utilizing a universe timer, with each object possessing it's own offset (to keep the same object types from visually aligning), and then switching to the next sprite as the universe iterates.  Modulus is used to trigger looping within the fixed sprite list length (using the remainder keeps us from ever stepping beyond the max size).  We will also expand on her understanding of Random, seeds, and how to produce non-trivial random ranges.

Friday, August 21, 2020

Day 5: Basic Objects, Flow Control, and Randomization

Following the Game Theme

She really seemed to enjoy today's lesson.  The running joke is, a good session with dad is 2 hours.  A bad session with dad can't be over soon enough.  Out of 5 lessons, we had two really good sessions, but none of them were what I would classify as bad.  I'm learning what keeps my daughter's attention.  I shouldn't be so surprised to find out she:
  • demands to be the one typing the actual code
  • wants examples to do something, not just output a String
  • and finally, the more obnoxious the better.
Today's lesson consisted of picking up where we left off yesterday, converting the primitives from our main method in our Hero class to instance variables with getters and setters.  She picked up on the notion of the class representing an archetype as opposed to a physical instance MUCH faster than I did (and I was 18 the first time I tried grasping object-oriented programming).

She decided to implement a Hero that could (and would) only attack other instances of the Hero class, and being a hero, would talk smack well in advance of an attack.  After each attack, each instance of the Hero class would then ask the other person to stop (being a Hero and all).  Finally, being heroes, they would refuse to stop fighting once engaged, demanding that each see the fight through to the finish in an honorable fashion (i.e. to the death).

Sound Effects to the Rescue

While attacking (and subsequently being attacked), she decided each Hero would verbalize their might (or their displeasure at being whacked).  At this point, I introduced our first set of external project assets.  I had her open up Audacity and record a handful of threats and a good number of hurt exclamations.  Last year I bought her the most amazing microphone (a Blue Yeti), and it really made today's lesson that much better because of the quality of her recordings.

Using basic if/else-if logic, I had her modify the Hero class to use text threats and complaints by default, with simple overrides for providing sounds when available.  She then added in her sounds and we were off to the races, pitching scenarios and ideas for the apparent game we are going to write now that she realizes this is how games are made.

Randomization FTW

Finally, we created a loop of our two Hero instances hitting each other for the same amount (which proved to be predictably boring).  We quickly moved on to the notion of random max hits with a chance for misses, with a fight ending after at least one of the heroes death (or both if we are really lucky).  She also quickly grasped the need for adjusting the seed for randomization so we didn't see player one repeatedly beat the fire out of player two.  The lesson was a resounding success, and she is overflowing with ideas which I am trying to convince her to write down while she is excited.  Epiphanies are fleeting and should be honored quickly to avoid being forgotten.

Thursday, August 20, 2020

Day 4: Primitives, Variables, and Operators

 Notes from Yesterday

  • The object metaphor already clicks with her.  So proud.
  • Thank you, Notch, for helping sell Java to my kid.
  • Matilda wrote, compiled, and ran her first program today.
  • She keeps asking me all the right questions.


Coding Direction

She seems most interested in games, so we are going to go down that route when exploring object-oriented aspects of the language and polymorphism.  Today, we are sticking with the easy stuff: storing different immediate values in variables and performing PMDAS operations on them.  We'll cap the activity with the introduction of the modulo operation and the magic you can perform with it.


Plan of Attack

While adhering to the curriculum I put together as much as possible, I have left myself some leeway in regard to specific metaphors and elements.  In the case of my daughter, we have already begun having random conversations about in-game items of the same category and those items that might inherit or have overridden characteristics.  Thank you Terraria for spanning all of these and more.  Their wiki with its visually grouped items is especially useful for conveying the usefulness of objects, interfaces, and reused enumerable attributes.
  1. Learn how to store and change attribute values manually and randomly.
  2. Learn how to associate those attributes with a class.
  3. Learn when attribute sets are reusable.
  4. Learn how to combine classes and attributes into more complex objects.
  5. Learn how to dynamically determine type info.
  6. Learn how to use those complex representations to emulate a fight.

Wednesday, August 19, 2020

Day 3: Code

Notes from Yesterday

  • My kid is excited, which makes everything easier.
  • Apparently they don't teach kids UNIX in third grade.
  • 30 minutes later and she knows basic commands.
  • Raspbian has some OSGI woes in regard to Eclipse. 
  • We were able to successfully attach her fancy Bluetooth keyboard and mouse.
  • Sublime does not have an ARM version and is closed-source.  Shame. Shame. Shame.
  • Lots of sites are claiming the OpenJDK implementation for ARM is slow.  I may have to find a replacement JVM once we get into heavyweight components: video, multi-threaded web, parallel file processing, etc. The issue won't impact us for awhile, but I really despise Oracle's licensing model and I've been burned by IBM in the past. We may be forced to pursue OpenJ9.


Java Lessons Begin

Today's Goal:  to have her creating simple Java classes and running them from the command-line.

NOTE: Having taught a good number of people to program in Java, I know for a fact the students who learn from the command-line are much better at debugging issues than those who start immediately with an IDE. I'd like to thank one of my college professors for this insight.  He required all of us to learn how to manage pixels and manipulate world coordinates using linear algebra and calculus before allowing us to use native OpenGL transformations.  Knowing how it all works steers your decision-making later on, and helps you eek out performance gains where others have no options.

If you are asking "why Java?", you may not be aware of the following:
  1. Java has truly free options, as opposed to reciprocally licensed compilers and virtual machines, unlike other programming languages that hinder you from distributing your products without fees and addendums.
  2. Java is available on all platforms (WORA / Write Once Run Anywhere)
  3. Java has commercial-grade JVM's available for industry-level performance.
  4. Most web hosting service providers support Java for server-side complexity: ecommerce, database, queuing, additional security, NLP, etc.
  5. Learning Java will make you a much better Javascript programmer.
  6. Java has hardware acceleration hooks available (graphics, audio, cpu, etc.).
  7. You can call other languages from Java (in lieu of being sandboxed).
  8. Java now has non-blocking IO and full multichannel network support.
  9. Java is auto-documenting.  Replace javac with javadoc and you generate documentation in printable and revision-controllable HTML.
  10. Java has rigid certification paths: business developer, web component dev, architect, etc.
  11. Java has hardware hooks enabling interaction and control of accessible hardware.
  12. Java is well-managed via Maven (meaning you have direct control over which versions are used to produce your compiled product)
  13. Java has a very active community.  Google searches yield tons of answers.
  14. Java security is transparent and vulnerabilities can be discovered using numerous open-source tools and off-the-shelf products.
  15. Java vulnerabilities and proposed remediation options are published hourly via NIST, as opposed to other languages where you hope your code is safe.
  16. Java open-source libraries are now well-published in regard to safe use, vulnerability count, and operational risk via OpenHub.
  17. I know Java and am willing to share my code with anyone who asks (20+ years of everything).

Tuesday, August 18, 2020

Day 2: Software Preparation

Linux Smiled On Us

  • The screen is crystal clear: no banding, no black bars.
  • The audio card works without recompiling the kernel.
  • HDMI is broadcasting audio and video properly.
  • WIFI attached at 5GHz.

First, I took an inventory last night after the little one went to sleep.  The following software is already installed and available.  After this list, I will show the questions and options resulting from that list and what I plan on installing with her during our session this afternoon.

Preinstalled with Raspberry Pi 4B Desktop Kit:

CategoryNameDescription
Operating SystemRaspberry Pi OSLinux FTW.
Java IDEGreenfootA classroom-based IDE.
JVMOpenJDK 11Fantastic choice, avoiding Oracle licensing woes.
Text Editorvi, nano, etc.Forcing a 9-year old to use vi sounds unfair.
BrowserChromiumGood enough.
Revision ControlGit 2.2So happy.
Image EditorNoneNone
Audio EditorNoneNone

Changes We Will Make (and Why):

CategoryNameDescription
Operating SystemRaspberry Pi OSShe uses iOS and Windows at school. Enough tyranny.
Java IDEEclipse/STSFor native Git integration and Maven support.
JVMOpenJDK 11Fantastic choice, avoiding Oracle licensing woes.
Text EditorSublimeTextFree editor that enforces mindfulness (no printing).
BrowserChromiumThis doesn't matter much. In our code, we will be using pure DOM implementation jars for container tests.
Revision ControlGit 2.2Seriously happy. We have a NAS securely hosting Git.
Image EditorGIMPThere is no other.
Audio EditorAudacityAbsolutely fantastic. Go open-source or go home.

Monday, August 17, 2020

Day 1: Hardware Preparation

Since Matilda has already been exposed to desktop computers, I thought it would be a good idea to teach her about portable computers, drivers, and carbon footprints while learning to control all of those with code.  There are tons of options with an eco-friendly footprint; however, the following list is both low-cost, low power, small footprint, and low-heat.  I've listed the hardware I chose for her lessons with a brief explanation of why each piece was selected:

  1. Raspberry Pi 4 Desktop Kit / 8GB $140
    • Raspberry Pi 4B
    • extremely low power consumption (can run off a solar panel)
    • low heat production / small footprint
    • great for coupling with a robot/drone
    • dual 4k monitor support
    • has integrated wifi 2.4/5GHz and bluetooth
    • includes a fully-installed linux OS
    • comes with a mouse + keyboard w/integrated USB hub
    • version 4B is 64-bit + quad core (insane)
  2. Elecrow 10.1 inch 1080p IPS Monitor $115
    • fully encapsulated portable screen (most are floating screens with exposed prongs)
    • uses an extremely bright IPS screen
    • does NOT include a touchscreen (longer life)
    • extremely low power consumption (can run from USB using a $7 adapter)
    • uses native 1080p HDMI resolution and has integrated speakers
    • [best of all] all the connections are hidden in a cavity behind the screen
  3. ROMOSS 30000mAh Rechargeable Power Bank $35
    • affordable while providing hours of power
    • easily recharged using even a tiny 6W solar backpack panel
    • includes USB2.0, Type-C, and higher voltage USB 3.0 fast-charge ports.
    • has a visual indicator that displays battery level

All items booted up properly.  No dead pixels showed up on the screen (yay).  All items ran directly from power bank without requiring any wall adapters.  Daughter digs the raspberry colored cables on the keyboard and mouse (phew).

Measured EmitterWatts/hourkg of CO2/year
Current Desktop400350
Raspberry Pi 4B3.416.5

Sunday, August 16, 2020

Nothing Else Matters

Today marks a change in the permanent direction of this blog, in the hope that my daughter realizes just what it means to me to have the chance to be the one to teach her how to code.  I've seen her curiosity and I have waited to see her mental acuity match it.  Each day, I'm going to log our progress, as this will be a huge change for both of us.  I love my wife for all the many differences we have and the entirely new perspective she has granted me into so many other things I never would have bothered with; however, with my child I have observed and acknowledge a shared knack for our ability to observe complexity and to break it down into simple, understandable components.  Now it's time to show her how to put those parts back together.

Matilda, you come from a legacy of amazingly strong, witty, smart, compassionate, and patient women.  Make them all proud as they watch over your progress and never let anyone confuse your patience with weakness.  Your beauty is only one aspect of your prism.  Disagree. Question. Laugh! but be loud when doing it.  Carve your place in history and know that your mother and I love everything about you.

Matilda's Predecessors