Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
module Greeter
def greet(name)
"HELLO, #{Name.normalize(name)}!"
end
module Name
def self.normalize(name)
name.strip.upcase
end
end

Establish a quality-centric mindset

Having high quality standards for your project is a matter of practicality, not pride. To understand why, it helps to remember that "bad code" is typically hard to understand, hard to test, hard to change, and hard to reuse. Regardless of how useful your project is to the world right now, these problems will get in the way of its future progress.

Any one of these negative traits of bad code can make a maintainer's job painful, but when you combine all four of them it is like wearing a pair of lead boots while trying to run a marathon. Even if you are capable of supporting your project in its current state, these hindrances will gradually chip away at your ability to be responsive to the needs of your users while simultaneously eating up time and energy that you could be using to improve your project's strengths rather than fighting against its weaknesses. Once you head down this road, your project stops being fun to work on, and starts feeling more like a burden.

Once

module PrawnCalender
module DocumentExtensions
def calender(*a)
draw CalenderWidget.new, *a
end
end
class CalenderWidget
# ...
end
require_relative "helper"
### Parse the sections of the document into a params dictionary
parser = FormLetter::Parser.new
parser.rewrite(:emails, :deadline)
parser.rewrite(:date) { Date.today.strftime("%b %d, %Y") }
# this would come from a database or other source,

I appreciate all form of contribution, but for some contributors a greater sense of awareness about how OSS works would go a long way. The more you leave undone in a pull request or the more you leave unanswered in a bug report, the more “work in progress” your contribution adds to a project.

So for example, say you report a bug, but you only explain it with a sentence or two of english -- no stack trace, no minimal example reproducing the problem, and no tests. At that point, there’s nothing I can do except ask you to provide more information to help me investigate further, unless your problem is very obvious the moment I look at it.

Once we at least have the means to reproduce a bug, we need to make sure it’s isolated and not coming from some lower level problem. That means writing further sets of examples, and poking around in the source until we’re fairly sure where the bug is coming from.

Once that source of the problem has been identified, we need to work on a fix, but we need to take care to make

- - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - - - X X X X X X X X X X X X - - - - - - -
- - - X X - - - - - - - - - - - - X X - - - - -
- - - X - - - - - - - - - - - - - - - X - - - -
- - - X - - - X X X - - - X X X - - - - X - - -
- - X X - - - - - X X - X X - - - - - - - X - -
- - X - - - - - X X X - X X - - - - - - - X - -
- - X - - - - - X X X - - X - - - - - - - X - -
- - X X - - - - - - X X - X X - - - - - X - - -
-module(chopstick).
-export([start/1, loop/2]).
start(Number) ->
spawn(chopstick, loop, [Number, nobody]).
loop(Number, Owner) ->
receive
{take, Owner} -> loop(Number, Owner);
{take, NewOwner} when Owner =:= nobody ->
-module(bowling).
-export([score/1, test/0]).
test() ->
9 = score([{7, 2}]),
% 4 6 8 9 5 0 3 1 0 4
40 = score([{1,3},{2,4},{3,5},{5,4},{2,3},{0,0},{1,2},{1,0},{0,0},{1,3}]),
% 4 6 8 12 5 0 3 1 0 4
my_time_func(F) ->
{MegaS@T1, S@T1, MicroS@T1 } = erlang:now(),
F(),
{MegaS@T2, S@T2, MicroS@T2 } = erlang:now(),
(MegaS@T2 - MegaS@T1)*1000000 + (S@T2 - S@T1) + (MicroS@T2 - MicroS@T1)/1000000.
my_tuple_to_list({}) -> [];
my_tuple_to_list(T) ->
[erlang:element(1, T) | my_tuple_to_list(erlang:delete_element(1, T))].