Saturday, May 31, 2025

Polyglot - Hello World in 7 Languages

To those who love to learn languages, I understand the appeal. Being able to communicate with a wide array of people you might meet is an empowering feeling. New ideas are unlocked that had been hidden away in previously inaccessible texts.

Similarly, in the world of programming, building familiarity with other programming languages exposes you to new ideas and gives you a deeper understanding of how programs work. Possessing broad capabilities prevents becoming boxed in with opportunities limited to a narrow set of technologies - some of which are undoubtedly becoming obsolete.

To begin to get a flavor for how today's most popular programming languages are in some ways similar while also distinct, we'll look at what it takes to run what is perhaps the simplest program in most languages: a program that says Hello World.

Here are the arguably top seven languages in today's programming circles:

  1. Python
  2. C
  3. C++
  4. Java
  5. C#
  6. JavaScript
  7. Go

For each, we'll take a quick look at a program that prints Hello World along with the tooling and commands required to run each sample. I'm building each of these on a Linux desktop using command-line tools. (I prefer to avoid IDEs if possible, thoughts for another time.)

 Lets hit it.

 Python

A longtime favorite of mine, I began exploring Python years ago to interview for a job and was instantly drawn to it's clean and straightforward syntax. It comes as no surprise that its popularity has steadily grown. The Python interpreter comes preinstalled in many operating systems, making it perhaps the simplest language in today's list to try out.

Here is hello-world.py:

 def main():
  print('Hello World')
  return 0
 
 
 
if __name__ == '__main__':
  main()

To run it, we can execute the command

python hello-world.py

Now experienced Python programmers may point out, this is far from the simplest Hello World program in Python. It could be as simple as 

print('Hello World')

For the sake of consistency though, we wrap our code in a main function to match the conventions present in many other languages. Also, the __name__ == '__main__' check will allow code to be executed only if the module is being run directly. It will not execute if the file is being loaded as a Python module imported by another script. 

Onward to the next:

C

This was the first programming language I've learned, which I think has been a valuable way to start. Certainly the oldest language from our list, it's still widely used today. It's comparative simplicity sometimes requires extra work, managing memory usage stands out as a clear example, but it offers a greater degree of control. When carefully written, C can offer high performance and it's often the foundation for operating systems and other programming languages. Here's a Hello World program in C hello-world.c:

#include<stdio.h>
 
int main(void) {
  printf("Hello World\n");
  return 0;
}

The C compiler is often already available in an OS (Linux and MacOS at least) so it's easy to get started. We first compile the program into an executable, and then run it. The process can look like this:

gcc -o hello-world hello-world.c

./hello-world

Neat!

C++

Next we turn our attention to a highly popular language which extends C with the cleverly named C++. When I began learning C++ in high school (at the time it was the language used in the AP Computer Science exam), it's claim to fame was the addition of classes to support Object Oriented programming, a trend which every other language in this list continues (to at least some degree). It continues to be a popular choice for high performance applications and has a wider degree of helpful language features compared to the simpler C.

When it comes to our Hello World example, the differences appear relatively minor. This is hello-world.cpp:

#include <iostream>
using namespace std;
 
int main() {
  cout << "Hello World\n";
  return 0;
}

Compiling and running was similarly straightforward compared to C. The compiler was already present in the Linux OS I was using:

g++ -o hello-world hello-world.cpp

Java

I learned Java during my first programming internship and picking it up from C++ was fairly quick. It's claim to fame was the promise to "write once, run everywhere" thanks to it's unique approach to compile Java programs into a bytecode that could be run in an interpreter. This made it one of the few languages to offer a hybrid approach to running the programs, it was initially compiled and yet also interpreted.

Here's HelloWorld.java, pretty similar to what we've seen so far with one visible difference being that this program is declared as a class, which is traditionally required for all Java programs.

public class HelloWorld {
   
  public static int main(String[] args) {
    System.out.println("Hello World");
  }
}


To run a Java program, you can use the java command which comes pre-installed in most Operating Systems. To compile the source code though, the Java Development Kit must be installed to run the Java compiler: javac.

javac HelloWorld.java 

java HelloWorld

Next up, a language that is in some ways similar to Java: C#.

C#

I recall learning about C# in college and trying it out a bit. Coming from Java, it felt very similar and this may have been intentional as the word on the street was that Microsoft had created C# as a competitor to Java when they were prevented from extending the language for use in their own applications. At the time, Java had taken the world by storm and C# brought similar ideas to the Microsoft ecosystem.

Here's a Hello World program in C#, hello-world.cs:

using System;
 
public class HelloWorld
{
    public static int Main()
    {
        Console.WriteLine("Hello World");
        return 0;
    }
}

When it comes to running the above code, the dotnet program can both compile the code and also execute the compiled program. To perfrom compilation though, the dotnet compiler requires that a project file describe the source code and the type of program to be created. Using an IDE like Visual Studio, the program file is often generated for you. Sticking to my approach though of using command line tools only, the same can be accomplished using the dotnet command when the following csproj file is in the same directory as our source code hello-world.csproj:

 <Project Sdk="Microsoft.NET.Sdk">
 
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
 
</Project>

With the project file in place, the program can be compiled and then run using these two commands:

dotnet build
dotnet run

Next, we'll change gears to something a bit different: JavaScript.

JavaScript

While similarly named to Java, the language has very little in common. The programming syntax looks like Java, C, really most of the languages we've looked at, but under the hood it works very differently. JavaScript was initially launched as a language to run inside of Web Browsers and so it has historically been closely aligned with web applications. I started learning it when I began creating web pages and for a time I was programming in it heavily professionally. Concepts like prototypical inheritance and functions as first class objects make it possible to construct logic and dynamic behavior in JavaScript which is difficult to express in other languages.

A few years back, the NodeJS project made it possible to run JavaScript programs directly in the OS instead of being limited to only run in a browser context. This Hello World example uses the node command to interpret the following hello-world.js program:

function main() {
  console.log('Hello World');
}
 
main();

As with Python, this example is slightly more complex than strictly needed, for consistency. This program could be as short as console.log('Hello World');. 

Running this JavaScript program can be executed with the node command. which I had to install on Linux.

node hello-wolrd.js

Now we're ready for our final language Go.

Go

This is the most recent language on our list and one that I've learned over the years at work. In some ways it blends the simplicity of C with the conciseness of Python. With it's similarity to two of my favorite languages I was instantly hooked. Some of the unique design goals I recall that motivated the creation and design of Go include simplifying parallel processing - thanks to a built-in co-routine feature called goroutines - and also making it easy to reason about the flow of complex programs - hence the elimiation of throwing exceptions in favor of functions returning multiple values, one of which would be an error indicator. 

Here's a simple Hello World program in Go, hello-world.go:

package main
 
 
import "fmt"
 
 
func main() {
    fmt.Println("Hello World")
}


The compiler / interpreter for Go was already present in Linux, and running the above program was as simple as executing this command:

go run hello-world.go

Fun!

In Closing

Looking at the languages and comparing how to do the same things in each can be a fascinating exercise that deepens understanding and appreciation for how unique each programming language can be. This has been a long time fascination for me and inspired explorations like how to write classes in C, how to load libraries dynamically in Linux, and differences in how closures work in different languages. Hopefully this quick survey of Hello World examples has been instructive and inspires new explorations.

While writing the same program in 7 languages isn't the most innovative endeavor, a nice side benefit is that I now have a development environment set up for each of these languages. Another stepping stone to bigger and more exciting ideas.




 


Saturday, September 30, 2023

Guitar Wiring - Phase Switch and Blend Pot

Half the fun of building a partscaster is to experiment with unique guitar circuitry. The first guitar that I made has been a platform for experimentation and the journey continues. A couple of things bugged me about the first iteration of this guitar's wiring, so I decided to try a couple of new idea.

One was to use a knob that changes the balance between the neck pickup and the bridge pickup. This is done using what's called a blend/balance potentiometer. In the middle position, there is no added resistance to either pickup, then when turned one way or the other there is added resistance (lower volume) from one of the two pickups.

The second idea, was to add a switch to provide an out-of-phase sound. The effect is to create a thinner brighter sound because some of the waveforms that come from the two pickups are canceling each other out. Perhaps the most famous example of out of phase pickups is in a guitar called Greeny. Here's the wiring diagram:




This was a fun experiment. Though after using this guitar for a while now, I find though that I rarely touch the blend pot, nor do I use the phase switch. The fact that the phase switch only effects the middle position when both pickups are on makes it a little limited. Also, if the blend pot isn't in the balanced center spot, the out of phase effect is greatly limited. Having a switch to brighten up the sound is still something I'm interested in and I'm wondering if putting in a high pass filter using a capacitor would be a more effective technique since it could apply to all pickup selection positions.

Tuesday, August 17, 2021

The 2021 Guitar - In Search of the Guitar That Can Do It All

On any given Sunday, I play covers that call for a few different electric guitar styles. I like to get as close to the original sound as possible without the hassle of bringing three or four different guitars. (The Kemper mimics the sounds of multiple different amps, so that side of the equation is taken care of.) What if I could get all of those great sounds, the brightness and clarity of single coil pickups, the power and mid-range sweetness of humbuckers, in a single guitar? Here's my latest attempt.

At it's heart, this is a Telecaster inspired machine. The grit and cutting voice of a wound-hot Tele pickup has become one of my favorite sounds and the clarity and chiminess of a Tele bridge pickup gives the Tele a versatility that works for many styles. To the Tele foundation, I added a high output humbucker pickup and stuck it in the middle position. This is a bit unusual as most humbucker equipped guitars have two pickups, with higher output on the bridge pickup. Using the humbucker in this spot provides a sound that pushes the amp much harder than the other pickups while emphasizing the mid-range frequencies, just what is needed to round out the sonic versatility of this guitar.

Here's this new guitar in action, first the neck pickup, thin and chimey, then the the grittier middle humbucker pickup:

The controls for the guitar are standard modern tele controls: three way switch for the neck and bridge pickups (neck, both, bridge) with a single volume and tone control. To accomodate the additional middle pickup, I added a volume knob which can by pulled out to switch the coils into parallel, pushed down they are in series. There is a three-way toggle switch on the horn of the guitar which selects between the standard tele circuit, the middle humbucker only, or both. Using the two switches (tele blade switch, toggle on the horn) any combination of pickups can be selected. As an added bonus, the tone knob can also be pulled out to bypass the tone circuit, letting all of those glorious highs slip through.

This wiring diagram describes the full circuit for the guts of the guitar:

As for the look, I went for a somewhat aged 50s tele: Butterscotch blonde with a bit of relicing to show some where, especially around the lower bout where my elbow tends to run the body of the guitar.

Now for the detailed specs:

  • Body
    • Shape: Telecaster (traditional)
    • Wood: Alder
    • Finish: Nitrocellulose Laquer (Blonde undercoat, Butterscotch topcoat) then lightly reliced using high grit sandpaper. Covered with a final coat of Tru-oil.
    • Pickguard, solid black
    • Bridge: vintage brass sadles - compensated for improved intonation
  • Neck
    • Shape: Telecaster with Vintage/Modern truss rod access
    • Wood: Solid maple
    • Profile: Warmoth Boatneck
    • Radius: Warmoth compound radius (10"-16")
    • Frets: Stainless steel size 6150 (medium jumbo)
    • Finish: Tru-oil
    • Tuners: vintage style - string inserts in the top
  • Electronics
    • Pickups:
    • Pots: 250k push pull pots for tele volume and tone controls, 500k push pull pot for middle pickup volume control
    • Switches: Three way blade switch for tele controls, three way LP-style toggle switch for selecting between tele controls and middle pickup
    • Tone Capacitor: .022uF
    • Tone Bleed Circuits: .001uF capacitor with 150K-ohm 1/4-watt resistor in parallel. This is used on both volume knobs.

This was a fun build and is a blast to play. Is this the only guitar I'll be bringing to gigs? Only time will tell.

Thursday, September 17, 2020

Partscaster: T style with P-Rails

Super pleased with this guitar that I put together from custom parts a short while ago:

One of my life-long passions has been creating music. For the past decade and a half, the form that musical expression has taken is in playing the guitar. I've played most Sundays in church for the past several years and over time, I've been exploring different variations on amps, effects, and guitars to try to find the perfect balance of tones, to fit the mood of the moment in music.

Since many of the songs we play are by different groups, who each use different instruments, I've been looking for a way to have a wide variety of different sounds on tap. Ideally, this wouldn't require carting half a dozen different guitars and amps on stage each weekend. This started me looking for different styles of guitar pickups that are versatile and mimic a number of different popular configurations. When I learned about Seymour Duncan's P-Rails pickups, they sounded like a perfect solution for the kind of versatility I sought.

These pickups include a P90 pickup as well as a "rail" style coil, both in a tidy package that fits a space for most humbucker pickups. If wired to switch between the P90, the rail pickup, or both, this one pickup could do triple-duty; matching three common pickup styles. Seymour Duncan also provides a great way to handle the switching between these different modes in their Triple Shot mounting rings. These are essentially pickup rings that also include two small switches, and by flipping through different combinations, the pickups can be run as: P90-only, rail-only, both in parallel, and both in series. My mind was swimming with possibilities.

With the pickups sorted out, now the question was, what kind of platform should these pickups be put into? I've recently been enjoying Telecaster guitars, and the traditional shape and style of an early 1950s Telecaster has a timeless appeal that seemed like an inconspicious way to bring a surprising amount of versatility on stage. Rather than buy a Tele to rip it apart, I thought I could start fresh, and it seemed like building my own Tele-style guitar from parts might not be too far a stretch for me, as little woodworking experience as I had had at this point. The place many people turn for custom guitar parts Warmoth, which has a great reputation for high quality custom work. I choose a Telecaster shape routed for Humbucker pickups, made of Alder (same as the American Standard Telecaster I also have).

For the neck of the guitar, I had a couple of unique things in mind. First was the thickness of the neck. I have relatively long fingers, and the thin necks on some electric guitars tend to cause discomfort on long playing sessions. I've found thicker necks to be much more comfortable, so I decided to pick a Boatneck profile when ordering from Warmoth. The second non-traditional detail that I had in mind was to spring for stainless steel frets. I dislike the idea of the frets wearing down over the years as I play, and I wanted to build something that I'd enjoy playing for years to come. The durability of stainless frets might mean that I'll never need to refret this neck, which sounds like a win to me.

The last question was the finish. Traditionally, the early Fender guitars were finished with nitrocellulose laquer, and even today many high end instruments use this as the weatherproof coating. While in some ways inferior to modern materials, there are two aspects to this finish that I found attractive: ease of applying the finish and repairing mistakes (thanks to its ability to "burn in" to previous layers) and the way that it hardens and wears over time. The worn-in look is quite popular these days, especially on telecasters, and while I have no plans to artificially relic this guitar, I'd love to watch how the finish ages over the years. I decided to apply the finish myself, so I bought a few rattle cans of nitrocellulose laquer in butterscotch transparent and clear. I applied a few coats of clear as a sealer, then around 4 coats of butterscotch, followed by around 10 coats of clear on top. The neck of the guitar I sprayed with clear only. After waiting a couple of weeks for it to dry, I wet-sanded with a series of increasingly high grits of sandpaper. Starting from around 180 grit, I worked up slowly to 4000. It was pretty nerve-wracking at the start, seeing the shiny, but a bit orange-peel-y, finish turn dull and flat. Not until over 2000 grit did it start to shine again.

The painting all finished, it was time to put it together! For the wiring, I thought it would be cool to try a 4-way switch with positions for neck pickup only, bridge pickup only, both in parallel, and both in series (to match the multiple ways to wire each pickup). This would create a dizzying array of pickup combinations - 40, to be precise, which is probably too many, but hey, if you've got it why not! The last detail of the wiring which is somewhat unusual is the "treble bleed circuit" which consists of a capacitor + resistor on the volume potentiometer. It allows some of the high frequencies to continue to "bleed" through the volume control as it is turned down. The effect is that as the volume is turned down, the sound gets "thinner" and more bright, rather than darker and more muddy which would naturally happen on a volume pot without this added detail. I've loved this feature of my American Standard Telecaster, so I decided to duplicate it here.

Here's the schematic for the wiring:
Over the course of a few months, I worked on this over the weekends and vacations and finally wrapped it all up around Christmas time. Without further ado, the pictures:

Here are the specs at a glance:

Sunday, August 23, 2020

Cryptopals

I've had a longstanding interest in cryptography and recently dove into a set of exercises that teach basic concepts of cryptanalysis. I highly recommend it if you are looking to learn more about cryptography: Cryptopals.

Early Telecasters A Visual History

Along with software development, my other passion is for making music. There have been a few instruments I've specialized in over the years, but my far and away favorite at the moment is electric guitar, specifically a Fender Telecaster. For the past couple of years, I've been playing a 2015 American Standard. Here are a few pictures:



One of the things that amazes me about this instrument is the classic design which has undergone very few changes since this instrument was first introduced in 1950. As one of the very first mass produced electric guitars, the Telecaster continues to influence modern music as well as the design of electric guitars. Most electric guitar makers sell a "T" style guitar in their lineup.

Lets look back at a brief visual history of the first decade of the Telecaster family of guitars.

1950

Beginning in 1950, the Fender Electric Instrument Manufacturing Company began selling a couple of styles of electric guitar. First, the single pickup Esquire, followed shortly by the two pickup Broadcaster.

Esquire

One of the surprising details to me about this guitar, is the presence of a three-way selector switch. In most electric guitars, the selector switch activates different combinations of the pickups in the guitar. Most single pickup guitars omit a selector switch (see for example, the Gibson Les Paul Junior). So what is a selector switch doing on a single pickup guitar?

In the wiring for an Esquire, the middle position matches what most would consider a normal setup for a single pickup guitar with two knobs. In this position, the volume and tone knobs control the output from the pickups. When the switch is up towards the neck of the guitar, an additional capacitor is in the output chain in place of the tone knob. This cuts out many of the high frequencies in the output and produces a somewhat muddy sound more reminiscent of a bass guitar. This video has a great demonstration of the Esquire tones. A demonstration of the tones begins around 3:27 in the video. This circuit position in particular is not typically found on a modern electric guitar, pretty unique! The final position, down towards the bridge is a circuit that bypasses the tone control entirely and is the least filtered of the circuit options. Only the volume control is changing the output, so you get the widest possible set of frequencies. There are a few guitars out there today that dispense with a tone control. One example is the Jim Root Telecaster, however it is a very different beast than the 1950 Fender Esquire.

And now for the look:

While the single pickup guitar was the first to be widely available, from the beginning, Fender had planned to produce a two pickup guitar. In fact, these early Esquire guitars reportedly had a cutout for the neck pickup ready to go but hidden away under the pickguard. And that brings us to the next guitar available in 1950: the Broadcaster.

Broadcaster
With it's two pickups mounted on a solid ash body, this is very recognizably the first example of what is today the Telecaster. Originally named the Broadcaster, it would soon have to be renamed due to a trademark dispute. Few guitars carry the Broadcaster name.


While the Broadcaster has the recognizable two pickup configuration, two knobs, and a three way selector, the wiring is very different from what would later become what is now considered normal Telecaster wiring. In these early models, the three selector switch toggled between the following settings. (Note, more details on this original Broadcaster wiring can be found here.) Here's what the different positions in a Broadcaster switch do:

The position with the switch down towards the bridge includes the output of the bridge pickup, with no tone adjustment similar to this setting in the Esquire. However, rather than ignore the tone know, in this position, the "tone" knob is a "blend" control which adds in the output from the neck pickup. Turned one way, the neck pickup is all the way in, the other way it's all the way out. Next, the middle position includes the full output of only the neck pickup (no tone modification). The final position, up towards the neck, includes only the neck pickup with a capacitor that filters out the high frequencies. I found it fascinating that in the original Broadcaster wiring, there's no variable tone control, just pickup selection with one option being a fixed tone cut. The closest-to-bridge switch position is most similar to the middle position in modern Telecasters. Although, in a modern telecaster, there's a constant balance of output between the picksups when both are active.

A good example of the tones that come from this wiring can be found in this video. Although this isn't an original Broadcaster, it demonstrates the different behaviors of this pickup switch. Here's another example. For a video showcasing an actual 1950 Broadcaster, check out this video from Norman's Rare Guitars.

1951

Over the course of 1951, the Broadcaster would be renamed to the Telecaster. Aside from the name change, the guitars' design was essentially unchanged.
Broadcaster

In early 1951, Fender continued making Broadcaster guitars. However, the Gretsch company notified Fender that the Broadcaster name on their guitar conflicted with their trademarked Gretsch Broadkaster drum set. It doesn't sound like the two companies went to court over the name. I wonder how it would have gone had Fender decided not to change the name. Gretsch also produced electric guitars at the time, and continues to make and sell them today. In 1951, none of the Gretsch guitars were named Broadcaster, though they do today sell a Broadkaster Guitar.

Nocaster

Following the notice from Gretsch guitars, Fender began producing their formerly-known-as-Broadcaster guitars with no model name on the decal. The headstock of the guitar was labelled only with the name Fender, hence guitars produced in their period are dubbed "Nocaster" guitars. Aside from the name change on the headstock, the Nocaster is visually similar to the Broadcaster that came before it. The body is painted a translucent Butterscotch Blond with a single-ply black pickguard:


These Nocaster guitars are quite rare as they were produced for only a partial year. By year's end, these guitars bore their new and final name.

Telecaster

In late 1951, the guitar received the name that it is known by today: the Telecaster. Other than the new name on the headstock, these guitars were identical to those produced earlier in the year.


While these guitars now bear their modern name, the wiring of the pickups is significantly different than what they carry today. Modern style pickup wiring was introduced in the late 1952.

Esquire

Fender continued to produce Esquires as well in 1951. In addition to the "Butterscotch Blond" color, the Esquire was also available in a "Blond" color which was a translucent white. The finish on these guitars tend to yellow significantly as they age, so most old guitars have a noticable yellow tint to them. Here are a few pictures:


Few other instruments have been in continuous manufacture as the humble Telecaster and it still plays a major role in modern music. Here's to the next 70 years.