2013-01-24

Languages for Learning

Here is a list of languages that seem to me useful to learn in the sense that between them they cover all the major concepts that exist in other languages, yet they are all individually small enough that you can easily learn the particular language and keep it in your head.

I think that one should be able to become somewhat proficient in any of these languages with about a month of reasonably serious study. Experimentally, I seem to be able to keep about 3 of these going as far as casual study at the same time.

I believe that most interesting language concepts are expressed in some way by at least two languages in this list. So each major concept should have at least two potential implementation to compare.

  • c
  • scheme
  • forth
  • prolog
  • erlang
  • sml
  • lua
  • tcl
  • ruby
  • awk
  • javascript
  • go

I think that from this base one could pick up almost any industry language with a decent understanding of the concepts. So given about a year of exploratory study of these languages (perhaps 1 per month?), one should be well equipped to handle learning any of the more complex languages currently used.

other things to learn

To be an effective programmer, here are a few other things it really would help to have a grounding in as far as general use / concepts.

  • html / css
  • sql
  • assembly language (I think any one would give you the concepts that are useful)
  • command line (probably preferably unix based)

An argument can be made that these are / aren’t languages in the same sense of programming language concepts covered by the earlier list of languages. However, ones life as a programmer will be subtly constrained to the extent that one is not familiar with these technology areas.

Standard

2013-01-23

The Surprising Use Case For Vim

I’ve spent a lot of time trying out different text editors. among the reasons that I continue to come back to Vim, there is one that is surprisingly powerful, and somewhat unexpected.

The reason: I can print from Vim on every computer I’ve installed it on.

Most other cross-platform editors fail as far as printing documents on some OS or another (often Windows). Vim is the only one that I’ve seen reliably print everywhere I’ve tried it. As a bonus, it can print just as well from the terminal as from the gui.

Standard

2013-01-18

coloring vim after 80 characters or more

from this stackoverflow question,

to enable columns to be colored differently in vim for certain columns or ranges:

for everything after column 80 to be colored:

let &colorcolumn=join(range(81,999),",")

for column 80 to be highlighted, and everything after 110:

let &colorcolumn="80,".join(range(111,999),",")
Standard

2013-01-17

unsticking ssh

i often move from place to place with my laptop.

sometimes i forget that i’m still logged into a remote site before changing wifi networks. when that happens my ssh session will get stuck. if i do it from an xterm, i can just close it, but if i’m using the real console, there’s not a way to restart.

here is the trick that seems to work.

"enter"~.

that is, hit enter/return, then type tilda, then period.

that’s what works for me to exit the hung ssh connection.

Standard

2013-01-10

Polyglot Friendly Languages

Here are languages that I think of as having small enough cores that they can be conceptualized easily by someone who is not working full time in that language.

For the most part they are conceptually small enough that it is possible to imagine a normal but dedicated person being able to implement a version of them given sufficient effort.

Small Core Languages

  • C
  • Go
  • Tcl
  • Lua
  • Awk
  • JavaScript
  • Erlang
  • Prolog
  • SML
  • Scheme
  • Forth
Standard

2013-01-02

using luabind

here is just a quick rundown of what i did to get the hello world example here for luabind to work.

here is the example code in c++:

#include <iostream>
#include <luabind/luabind.hpp>

void greet()
{
        std::cout << "hello world\n";
}

extern "c" int init(lua_state* l)
{
        using namespace luabind;

        open(l);

        module(l)
        [
                def("greet", &greet)
        ];

        return 0;
}

then i compiled it into a shared library using the following commands:

g++ -i/usr/include/lua5.1 -fpic -c hello.cpp
g++ -shared -o hello.so hello.o -lluabind

note: luabind has to be linked in the second step, not in the first.

then from lua i ran the following commands:

> init = loadlib("./hello.so", "init")
> init()
> greet()
hello world
Standard

2012-12-31

the baker’s answer to the needle peddler (mother goose)

i need not your needles, they're needless to me;
for kneading of needles were needless, you see;
but did my neat trousers but need to be kneed,
i then should have need of your needles indeed.

zero or one?

as i was going to st. ives,
i met a man with seven wives,
each wife had seven sacks,
each sack had seven cats,
each cat had seven kits:
kits, cats, sacks, and wives,
how many were going to st. ives?
Standard

2012-12-28

on mathematical "truth"

here is a recent comment i made on hacker news:

"actually, i'd say that in mathematics, things are provably true given that
the initial assumptions are true. however, mathematics does not so far as i
know deal with the truth of those initial assumptions (axioms), it simply
accepts them as true.
    
where this gets interesting is that you can say, what if this axiom was not
true? let's assume it's not. and then possibly come up with a whole new system
of mathematics (like non-euclidean geometry) which may turn out to have actual
use in previously unsolvable problems."

first a caveat, i am not a mathematician. although i received a ba in mathematics from the university of north texas somewhere around 1997, i have always felt like i must have somehow tricked them and did not really deserve the degree. i still think that i probably exited college with about the mathematical understanding of an equivalent math minor who really studied.

regardless, the idea of mathematical systems still fascinate me and i think about them from time to time. one of the interesting things about math is that it is both made up and eternal at the same time. that is, at the lowest level, the concepts of math are composed of pure thought, and there is no way to prove that the basic substrate of mathematics is "true". however, given that we accept on faith these basic low level tenets (usually called something like "axioms") then mathematics is the exercise of finding all the interesting logical consequences of those axiomatic statements. for example, given a universe or system where parallel lines cannot cross (and associated other necessary axioms), then one can prove that the sum of the interior angles of a triangle is always 180 degrees (or pi radians).

here we see one of the most interesting aspects of mathematics, which unfortunately tends to be glossed over in basic mathematics courses. for in one sense, the whole thing is founded on a system of statements that we simply accept at the start. so from that point of view it is made up. we could conceivably come up with other foundational statements to accept and then we would actually have a different system of mathematics. and this happens from time to time. someone said something like, "what if parallel lines could cross?" – and now we have an entire field of mathematics called "non-euclidean geometry".

however, despite the fact that these systems are as i’ve previously described "made up", they are also eternal. that is, given that the laws of logic hold (consider that question a bonus exercise), those systems that we derive from our axioms hold forever, in whatever universes those axioms are valid. therefore, as before, given a universe or system where parallel lines cannot cross (and associated other necessary axioms), then one can prove that the sum of the interior angles of a triangle is always 180 degrees (or pi radians).

now outside of pure mathematics, math is usually used by non-mathematicians as a notation or language to describe certain concepts or processes that correspond to situations in the real world. these users, generally, are using math because it is a useful tool, not because they have a deep feeling of the truth or untruth of the mathematical statements they make, but rather, because the mathematical tool they are using, somehow matches the situation or data they are analyzing. as a result they are hopeful that since they are able to fit their current data to some mathematical concept, that concept may be used to predict future behavior of the same or similar situations.

for these users, mathematical terminology is often employed without a real analysis of whether it has any foundational connection to the issue being described. looking at the introductory literature for physics or chemistry will reveal a number of instances where a physical behavior follows a certain mathematical function. sometimes the scientists do not know why the behavior follows that function, simply that it does. and in those cases they are content to use that knowledge in spite of their inability to explain the connection.

however, users can be confident that at least the mathematical exposition of their statements can be assumed to hold as long as the foundational principles of our shared mathematical understanding remain true. whether their statements have anything to do with our shared reality, is only as certain as their ability to tie observed reality to their chosen mathematical notation.


c++: my 10 percent

this morning, i realized that the way that i really want to use c++ is not c with classes, but c with stl.

i’d be relatively happy to use c++ just as c but with the extra containers that the stl provides.

in my mind this would involve using structs as the primary data structure instead of classes. i know that in c++ there’s not much difference, but i’m imagining here keeping structs to their default c behavior and only using classes when c++ behavior is desired.

i did realize that you probably want to still use classes when you are dealing with resources. basically anywhere you’d need to clean up a resource that a struct would hold, use a class instead.

an thought i had while considering all this is that go provides something fairly close to this subset of functionality.

Standard

20121225

words, truth and reality

the problem with playing with words or truth or reality is that if you play with them for long enough, you forget what they actually are.


what is a vector?

i was talking to my wife today about this comment on hacker news and i realized i keep in my head several simultaneous but non-obvious definitions for the term "vector". there are at least 3 different common understandings of this word, depending on what field of science or technology you are familiar with.

physics, math, chemistry(?):

from my time as a math/physics major in college i was familiar with the term vector in a technical sense as meaning "a magnitude and a direction". or, symbolically, an arrow, whose size indicates the magnitude of the represented quantity.

so for the canonical example: john, walking at 5 kilometers per hour is a speed, but john, walking at 5 kilometers per hour to the northeast is a vector.

programming, computer science:

in programming, it appears that the term vector usually means something like a re-sizable array. that is, a contiguous sequence of memory locations that can hold arbitrary values, but which unlike a c language array, can be resized transparently to allow more (or less) values to be added to the structure after it’s initial creation.

i believe this terminology was popularized from it’s usage as a data type in c++. java seems to use the same terminology. it seems to go by the term "array slice" in go unless i’m getting confused (which is possible).

in this form, it is contrasted with a linked list, which is a (potentially) non-contiguous group of memory structures that are linked one to another because each constituent substructure holds the address of the "next" substructure in the list. typically a linked list can hold arbitrary values, and new values can be inserted at arbitrary points and at arbitrary times, by rewriting the memory references on either side of the new data item.

a vector can also be contrasted with an "array" (used here in the c language sense) which in this analysis is the simplified or degenerate form of a vector in that an array is contiguous but fixed in form once defined. that is, an array is defined to hold a certain number and type of elements, and once defined, the memory is set aside and allocated. however, once defined, one cannot change the number of elements in an array. instead one must create a new array with the desired size and then copy the desired elements into the new array.

under the covers, if you took a snapshot of a vector at a point in time, it would like like a c array.

update: see here for a very good explanation of c arrays vs implementing higher level language "vectors".

biology, medicine, social sciences(?):

in these fields the term vector refers to something like the idea of a "path". that is, the route that some item takes to get from one point to another. in graph terms it is probably something like a directed edge, or perhaps a sequence of directed edges.

for example, if there is a parasite that moves from birds to humans via the mechanism of birds pooping on cars, and humans cleaning up the bird poop, then i believe the poop would be considered the vector. but perhaps if birds pooped and rats ate the poop and then bit humans to transfer the parasite, the rats would be the vector. or perhaps the vector would be more technically poop -> rat -> human. i’m less sure on this last point.

consider the compound term "disease vector" as a similar example.

are there other common definitions of the term "vector" that people know and use? if so, i’d be interested to hear.

update: see patrick moran’s comment (copied below) for two other uses that are often assumed in technical documents.

you might also note the use of vector in computer science to mean a small static sized array that one can act one with simd instructions. the whole process is known as vectorizing your code, one individual segment of some (2, 4, 8, maybe more) numbers next to each other is known as a vector. processors that work with them are known as vector processors.

http://en.wikipedia.org/wiki/vectorization_(parallel_computing)

there is also vector as in vector graphics (as opposed to raster graphics). this describes image representations like svg that can be thought of as programmatically drawing the image rather than representing it as a 2d array of pixels. this use of vector is different from the math/physics one in that the vectors are arbitrary curves, not necessarily straight lines. http://en.wikipedia.org/wiki/vector_graphics

Standard