I hereby claim:
- I am dbrady on github.
- I am davidbrady (https://keybase.io/davidbrady) on keybase.
- I have a public key ASCU2G-o7IcAgrhUI8FSzm7ePC9Bcf8gMD1UuQZIEnYF0Ao
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| # Names of classes and methods have been changed to protect the innocent. Namely | |
| # my sweet, innocent, cherubic, and hopefully continuing, employment. | |
| class MessageTwiddler | |
| # Okay, so: say I want to make a class method private. What's the best idiom | |
| # for doing this in Ruby circa 2017? | |
| # In Ruby 2.0 I can do Options 1 or 2: | |
| # Option 1 - Original Flavor, Most Explicit |
| # Names of classes and methods have been changed to protect the innocent. Namely | |
| # my sweet, innocent, cherubic, and hopefully continuing, employment. | |
| class MessageTwiddler | |
| # Okay, so: say I want to make a class method private. What's the best idiom | |
| # for doing this in Ruby circa 2017? | |
| # In Ruby 2.0 I can do Options 1 or 2: | |
| # Option 1 - Original Flavor, Most Explicit |
| class Person | |
| def poop | |
| puts "I pooped today!" | |
| end | |
| # One common way to make a class method is to declare it amongst the instance | |
| # methods prefixed with self... | |
| def self.poop! | |
| puts "Everybody pooped today!" | |
| end |
| EDIT: Was gonna tweetstorm this, then decided to just gist it. Enjoy. ;-) | |
| Tweetstorm about deceptive code incoming. | |
| First Point: People believe comments over the code, even if the code is obvious: x=1; /* put 2 in x */ <-- people believe the 2 | |
| Second Point: People maintain code without maintaining (or sometimes even reading) the comments for that code | |
| Third Point: Programmers love to optimize. Makes us feel smart. We think it makes us LOOK smart. But that way lies madness... | |
| So. Dateline: Salt Lake City, 2002. I find this piece of assembly code: "XOR EAX, EAX ; PUT 1 IN EAX" | |
| XOR any number with itself, you get 0. So the comment here was wrong, but if you don't know the XOR trick, it's outright deceptive | |
| If you DO know the trick, it's still distracting and makes you stop and question your sanity for a moment | |
| So I tracked down the commit history for the commit, and here's what happened (exit tweetstorm here if you don't want full history) |
| #!/usr/bin/env ruby | |
| require 'debug_inspector' | |
| def find_matchers(keys) | |
| matchers = [] | |
| matcher_suffixes = ["IS"] | |
| keys.any? do |key| | |
| matcher_suffixes.any? do |suffix| | |
| var = "%s_%s" % [key.upcase, suffix] | |
| matchers << [var, ENV[var]] if ENV.key?(var) |
| 09:21:58 dbrady@orthanc:~ ruby-2.0.0-p247 | |
| ∫ ruby -W4 temp.rb | |
| true | |
| 09:22:05 dbrady@orthanc:~ ruby-2.0.0-p247 | |
| ∫ cat temp.rb | |
| class Ponk | |
| def initialize(x) | |
| @x = x | |
| end |
| ;; Don't turn on linum-mode by default, it crashes org-mode. Ok to | |
| ;; turn it on for various modes, however. | |
| (require 'linum) | |
| (global-set-key "\C-c l" 'linum-mode) | |
| (defun enable-linum-mode () | |
| (linum-mode t)) | |
| ; ---------------------------------------------------------------------- | |
| ; Automatically enable linum mode for various modes |