Posts in the “programming” category

LOGO used “TO” like Scala and Ruby use “def”

I ran across the following page in the book Clean Code, and it really caught my attention. In short, there is a programming language named LOGO that apparently used to keyword TO in the same way languages like Scala and Ruby use “def.” This is described near the bottom of the page in the following image, in the area I highlighted:

Clean Code - The TO keyword in the LOGO programming language

I’ve never used LOGO, but that sounds like a clever approach, and since I ran across this discussion, I have to say, it’s had an effect on my methods. Every time I type “def,” I think “TO,” and it makes me think a little bit more about how I want to write my method.

For more information on book, check out the Clean Code book.

How to use SQL SELECT, GROUP BY, ORDER BY, and COUNT (all in one)

It feels like my SQL skills are pretty average these days, but that’s only because I haven’t had to do anything hard in a while. But just now I was happy to write this little SQL SELECT query that does a GROUP BY, an ORDER BY, and a COUNT, yielding the results shown in the image:

select nid, count(nid) as count_nid from term_node
where tid in (3,1,11,10,9,8,7)
group by nid
order by count_nid DESC

I’m going to use this query — or one very similar to it — to get a list of nodes (nid) that have the most tag ids (tid) from the list of tid in the query. In theory, the nodes (blog posts) that have the most tags in common should be the most related to each other. So, in my Scrupal6 replacement for Drupal 6, this query is a way to get “related” content for a given blog post. (The tid list shown comes from node id 4, so I need to also exclude nid=4 from the results. I also need to add a limit clause to the query.)

If you ever need to do a group by, order by, and count in one SQL query, I hope this example is helpful.

Docker cheat sheet (cheatsheet)

This is the beginning of a Docker cheat sheet. I couldn’t find any out here that I liked, so I’m starting to create my own, which will hopefully be organized the way I like it.

This content is cross-posted at My Valley Programming Docker cheat sheet.

Docker Basics

Recommended as a first command on a Docker system:

docker version     # should show Client and Server sections

Docker Lifecycle

This section mostly comes from (https://github.com/wsargent/docker-cheat-sheet):

To be a programmer is to develop a carefully managed relationship with error

“To be a programmer is to develop a carefully managed relationship with error. There’s no getting around it. You either make your accommodations with failure, or the work will become intolerable.”

~ Ellen Ullman (via this tweet)

This quote makes me think of all those years of exception-handling with Java. I never knew there was a better way to handle errors, so I developed a strategy of letting my exceptions bubble up to the controller level (as in model/view/controller), where I would deal with them. These days I know I can use Option/Some/None in Scala, as well as Try/Success/Failure.

Phrases to use instead of “foo bar baz”

As I get close to releasing the Second Edition of the Scala Cookbook, I’m trying to use the “foo bar baz” phrase less often, and trying to find better and more meaningful phrases. Thanks to Arrow and The Flash, one phrase I’m using is “Big Belly Burger.”

If you know any great phrases to use to help rid the world of “foo bar baz,” let me know here on Twitter. Here are a few I just looked up:

bond, james bond 
clear eyes full hearts can’t lose (friday night fights)
elementary, my dear Watson 
fasten your seatbelts 
frankly my dear 
gonna need a bigger boat 
hasta la vista (baby)
here’s looking at you kid
I see dead people 
just keep swimming
make my day
no crying in baseball 
not in kansas any more 
of all the gin joints 
open the pod bay doors, HAL 
pass the beernuts (Cheers)
play it again sam
show me the money
shaken, not stirred
Soylent Green is people 
the walking dead 
too much fruit (in the house)
who’s on first?
why so serious?
you talking to me? 
you’ll thank me later

An article on the problems with OOP

There seems to be a lot of OOP-bashing lately, which I’m not a fan of, but this article titled Goodbye, OOP makes decent points about the problems with inheritance, encapsulation, and polymorphism. IMHO, OOP still makes sense in certain areas, including GUIs like Java Swing and JavaFX, so I’m not ready to throw it out completely or bash it.

Land of Lisp (book)

Land of Lisp is one of the most interesting, quirky books I’ve read in quite a while. IMHO, Lisp can be a tough language to read, but the author, Conrad Barski, keeps it interesting.

A little Lisp interpreter

In the last post about Mary Rose Cook, the reason I originally found her work again today is because she wrote a Little Lisp interpreter in JavaScript. (116 lines of code.) As shown in the image, the beginning of the article is a very quick introduction to Lisp.