When learning a new language, some folks prefer to read the language documentation, or work through simple exercises like you might find on http://exercism.io — but I prefer to have something more like an actual project. I find that holds my focus a little better, and that I do a better job of absorbing the new language syntax and features if I’m using them for something real.
In this talk, I’m going to outline why writing a static website generator is the perfect task for this sort of language learning project. I’ll cover the code you’ll need to write in order to develop a simple template-based website generation system, and show how this particular project actually manages to hit all the points you need to understand to claim basic understanding of a language.
4. used to be a biologist, sort of
fell sideways into IT, originally
via Perl but currently sort of
polyglot-ish
ex-biologist
perl tribe
polyglot coder4 — why&how2learn • #tpcislc • @genehack
5. I submitted this talk with this title,
because Iʼve been telling people this
for the past couple years -- “wanna
learn a new language? you should
write a static site generator” -- and I
kinda figured I should maybe explain in
more detail and maybe try to justify it
just a little bit
a static site generator
should be your next
language learning project
5 — why&how2learn • #tpcislc • @genehack
6. And during the course of actually
writing the talk -- as frequently
happens -- I figured out that the
title I pitched it under kinda wasnʼt
what the talk wanted to be. This
title is a better description of the
talk I ended up actually writing.
the why and the how of
learning
a new programming language
6 — why&how2learn • #tpcislc • @genehack
7. one of the basic ideas here is
that continual learning is super
important in our line of work
premise:
lifelong
learning
is critical.
7 — why&how2learn • #tpcislc • @genehack
8. the only constant thing is people
telling you over and over that
the only constant thing is
change.8 — why&how2learn • #tpcislc • @genehack
9. who here has heard this
before?
“learn at least one
new language
every year.”
— david thomas & andrew hunt, “the pragmatic programmer”, 1999
9 — why&how2learn • #tpcislc • @genehack
10. or, this more modern variant...
“learn at least one new
javascript framework
every month.”
— me, this talk, right here right now
10 — why&how2learn • #tpcislc • @genehack
11. some of the languages i’ve “learned”
basic
pascal
applescript
11 — why&how2learn • #tpcislc • @genehack
12. some of the languages i’ve “learned”
perl
ruby
python
12 — why&how2learn • #tpcislc • @genehack
13. some of the languages i’ve “learned”
javascript
php
c13 — why&how2learn • #tpcislc • @genehack
14. some of the languages i’ve “learned”
lisp
clojure
scala14 — why&how2learn • #tpcislc • @genehack
15. some of the languages i’ve “learned”
node
swift
c♯15 — why&how2learn • #tpcislc • @genehack
16. how do you
learn a
language?16 — why&how2learn • #tpcislc • @genehack
20. i'm trying to learn how to
garden and i'm starting out by
having a small raised bed. you
can see here gesture that my
hand-sowing technique still
needs a lot of work
learning
projects
20 — why&how2learn • #tpcislc • @genehack
21. my language learning project of choice:
static site
generators
21 — why&how2learn • #tpcislc • @genehack
22. whatis a static site generator?
22 — why&how2learn • #tpcislc • @genehack
24. static site generator just takes
some sort of input, usually text
files, and then generates a
web site from those inputs
some inputs
➡
a website24 — why&how2learn • #tpcislc • @genehack
25. this is strictly my definition, but to my mind,
once you have a database involved, it's no
longer a static site generator -- databases
push you over the line into CMS territory
image source: https://i.pinimg.com/736x/
39/fc/
a1/39fca1f4193640cded1d84d0d7c55c
9c--disney-movies-disney-cruiseplan.jpg
nodatabases!
25 — why&how2learn • #tpcislc • @genehack
32. this 'open all' button down here
will spawn a new tab for each one
of these links. so the SSG code
here is turning the data not only
into HTML, but into a list of URLs
in some javascript code that runs
when you click that button
32 — why&how2learn • #tpcislc • @genehack
39. so why are
ssgs great for
learning?
39 — why&how2learn • #tpcislc • @genehack
40. thereʼs a quick early payoff
and then thereʼs a lot of
potential to go other places
iterative
& incremental
40 — why&how2learn • #tpcislc • @genehack
41. think about what you need to
do
they hit on all the
classics41 — why&how2learn • #tpcislc • @genehack
42. basic “hello world” ssg: turn 1
input file into 1 web page
hello
world
as a ssg
42 — why&how2learn • #tpcislc • @genehack
44. (at this stage, you can cheat
and hardcode most of the
HTML in print statements)
1. read input from file
2. process the input
3. write output to file
44 — why&how2learn • #tpcislc • @genehack
70. and thatʼs when you need to
deal with loops and getting all
the files out of a directory,
maybe skipping over some
files, recursion into the
directory, etc.
next:two input files
70 — why&how2learn • #tpcislc • @genehack
71. this is also when youʼre going
to want a templating engine
because hardcoding html in
your code is only going to take
you so far
as well:
templates!
71 — why&how2learn • #tpcislc • @genehack
72. which probably means figuring
out how to install libraries/
packages/deps/whatever the
language calls them
which means:
figuring out
packages72 — why&how2learn • #tpcislc • @genehack
73. (note: writing your own
templating system is a
different learning project)
note:probably don’t
write your own template engine
73 — why&how2learn • #tpcislc • @genehack
77. support for blog-like workflows (which
means 1 input file generating more
than one page and 1 page being
generated from more than one input
file) which means tracking more
internal state during program
execution, which means diving into
data structures
add a
weblog77 — why&how2learn • #tpcislc • @genehack
78. folding in other processing
(e.g., SASS -> CSS
processing) which means
figuring out how to invoke and
manage external processes
add other
processors
78 — why&how2learn • #tpcislc • @genehack
79. a real CLI app with sub-
commands -- more library
usage! code organization!
add a subcmd-style
app79 — why&how2learn • #tpcislc • @genehack
80. and then you can get
fancy…
80 — why&how2learn • #tpcislc • @genehack
85. once youʼve done a good
chunk, go back and rewrite the
earlier bits to be more
idiomatic
go back & take another
look
85 — why&how2learn • #tpcislc • @genehack
86. donʼt just write your favorite
language in the new language,
figure out how the new
language is supposed to work
don’twrite your $oldlangin your
$newlang.
86 — why&how2learn • #tpcislc • @genehack
89. figure out
how to make that happen
89 — why&how2learn • #tpcislc • @genehack
90. both in terms of
“maintain interest in it”
90 — why&how2learn • #tpcislc • @genehack
91. & in terms of
“be good at it”
91 — why&how2learn • #tpcislc • @genehack
92. maybe an SSG isnʼt the right
learning project for you, maybe
projects arenʼt the right learning
mechanism for you -- but you
need to figure out what the right
mechanism, the right project is,
so you can keep on learning
disclaimer:
this talk is based on
my opinions and experiences
92 — why&how2learn • #tpcislc • @genehack