Eater of Cheese, Rider of Bikes, Coder of Ruby
31 stories
·
1 follower

Earth-Moon Fire Pole

10 Shares

Earth-Moon Fire Pole

My son (5y) asked me today: If there were a kind of a fireman's pole from the Moon down to the Earth, how long would it take to slide all the way from the Moon to the Earth?

Ramon Schönborn, Germany

First, let's get a few things out of the way:

In real life, we can't put a metal pole between the Earth and the Moon.[1]For one, someone at NASA would probably yell at us. The end of the pole near the Moon would be pulled toward the Moon by the Moon's gravity, and the rest of it would be pulled back down to the Earth by the Earth's gravity. The pole would be torn in half.

Another problem with this plan. The Earth's surface spins faster than the Moon goes around, so the end that dangled down to the Earth would break off if you tried to connect it to the ground:

There's one more problem:[2]Ok, that's a lie—there are, like, hundreds more problems. The Moon doesn't always stay the same distance from Earth. Its orbit takes it closer and farther away. It's not a big difference,[3]You may occasionally see people get excited about the "supermoon," a full Moon that appears slightly larger because it happens at the time of the month when the Moon is closest to Earth. But really, the full Moon always looks surprisingly large and pretty when it's near the horizon, thanks to the Moon illusion. In my opinion, it's worth going outside and looking at the Moon whenever it's full, regardless of whether it's super or not. but it's enough that the bottom 50,000 km of your fire station pole would be squished against the Earth once a month.

But let's ignore those problems! What if we had a magical pole that dangled from the Moon down to just above the Earth's surface, expanding and contracting so it never quite touched the ground? How long would it take to slide down from the Moon?

If you stood next to the end of the pole on the Moon, a problem would become clear right away: You have to slide up the pole, and that's not how sliding works.

Instead of sliding, you'll have to climb.

People can climb poles pretty fast. World-record pole climbers[4]Of course there's a world record for pole climbing. can climb at over a meter per second in championship competition.[5]Of course there are championship competitions. On the Moon, gravity is much weaker, so it will probably be easier to climb. On the other hand, you'll have to wear a spacesuit, so that will probably slow you down a little.

If you climb up the pole far enough, Earth's gravity will take over and start pulling you down. When you're hanging onto the pole, there are three forces pulling on you: The Earth's gravity pulling you toward Earth, the Moon's gravity pulling you away from Earth, and centrifugal force[6]As usual, anyone arguing about "centrifugal" versus "centripetal" force will be put in a centrifuge. from the swinging pole pulling you away from Earth.[7]At the distance of the Moon's orbit and the speed it's traveling, centrifugal force pushing away is exactly balanced by the Earth's gravity—which is why the Moon orbits there. At first, the combination of the Moon's gravity and centrifugal force are stronger, pulling you toward the Moon, but as you get closer to the Earth, Earth's gravity takes over. The Earth is pretty big, so you reach this point—which is known as the L1 Lagrange point—while you're still pretty close to the Moon.

Unfortunately for you, space is big, so "pretty close" is still a long way. Even if you climb at better-than-world-record speed, it will still take you several years to get to the L1 crossover point.

As you approach the L1 point, you'll start to be able to switch from climbing to pushing-and-gliding: You can push once and then coast a long distance up the pole. You don't have to wait to stop, either—you can grab the pole again and give yourself a push to move even faster, like a skateboarder kicking several times to speed up.

Eventually, as you reach the vicinity of the L1 point and are no longer fighting gravity, the only limit on your speed will be how quickly you can grab the pole and "throw" it past you. The best baseball pitchers can move their hands at about 100 mph while flinging objects past them, so you probably can't expect to move much faster than that.

Note: While you're flinging yourself along, be careful not to drift out of reach of the pole. Hopefully you brought some kind of safety line so you can recover if that happens.

After another few weeks of gliding along the pole, you'll start to feel gravity take over, speeding you up faster than you can go by pushing yourself. When this happens, be careful—soon, you'll need to start worrying about going too fast.

As you approach the Earth and the pull of its gravity increases, you'll start to speed up quite a bit. If you don't stop yourself, you'll reach the top of the atmosphere at roughly escape velocity—11 km/s[8]This is why anything that falls into the Earth hits the atmosphere fast enough to burn up. Even if an object is moving slowly when it's drifting through space, when it gets close to the Earth it gets accelerated up to at least escape velocity by that final segment of the trip down into the Earth's gravity well.—and the impact with the air will produce so much heat that you risk burning up. Spacecraft deal with this problem by including heat shields, which are capable of absorbing and dissipating this heat without burning up the spacecraft behind it.[9]People often ask why we don't use rockets to slow down, to avoid the need for a heat shield. You can read this article for an explanation, but the bottom line is that changing your speed by 11 km/s takes either a tank of fuel the size of a building or a tiny heat shield, and the tiny heat shield is a lot easier to carry. Thanks to heat shields, slowing down is much easier than speeding up—which requires the aforementioned giant fuel tank. (For more on this, see this What If question).

Heat shields only work for slowing down; if there were a way to use the same heat shield mechanism to speed up, space travel would get a lot easier. Sadly, no one's figured out a practical way to build a "reverse heat shield" rocket. However, while the idea seems silly, in a sense it's sort of the principle behind both Project Orion and laser ablation propulsion.
Since you have this handy metal pole, you can control your descent by clamping onto it and controlling your rate of descent through friction.

Make sure to keep your speed low during the whole approach and descent—and, if necessary, pausing to let your hands or brakepads cool down—rather than waiting until the end to try to slow down. If you get up to escape velocity, then at the last minute remember that you need to slow down, you'll be in for an unpleasant surprise as you try to grab on to the pole. At best, you'll be flung away and plummet to your death. At worst, your hands and the surface of the pole will both be converted into exciting new forms of matter, and then you'll be flung away and plummet to your death.

Assuming you descend slowly and enter the atmosphere in a controlled manner, you'll soon encounter your next problem: Your pole isn't moving at the same speed as the Earth. Not even close. The land and atmosphere below you are moving very fast relative to you. You're about to drop into some extremely strong winds.

The Moon orbits around the Earth at a speed of roughly one kilometer per second, making a wide circle[10]Yes, I know, orbits are conic sections which in the case of the Moon is technically not exactly a circle. It's actually a pentagon. every 29 days or so. That's how fast the top end of our hypothetical fire pole will be traveling. The bottom end of the pole makes a much smaller circle in the same amount of time, moving at an average speed of only about 35 mph relative to the center of the Moon's orbit:

35 miles per hour doesn't sound bad. Unfortunately for you, the Earth is also spinning,[11]I mean, unfortunately in this specific context. In general, the fact that the Earth spins is very fortunate for you, and for the planet's overall habitability. and its surface moves a lot faster than 35 mph; at the Equator, it can reach over 1,000 miles per hour.[12]It's common knowledge that Mt. Everest is the tallest mountain on Earth, measured from sea level. A somewhat more obscure piece of trivia is that the point on the Earth's surface farthest from its center is the summit of Mt. Chimborazo in Ecuador, due to the fact that the planet bulges out at the equator. Even more obscure is the question of which point on the Earth's surface moves the fastest as the Earth spins, which is the same as asking which point is farthest from the Earth's axis. The answer isn't Chimborazo or Everest. The fastest point turns out to be the peak of Mt. Cayambe, a volcano north of Chimborazo. And now you know.[13]Mt. Cayambe's southern slope also happens to be the highest point on Earth's surface directly on the Equator. I have a lot of mountain facts.

Even though the end of the pole is moving slowly relative to the Earth as a whole, it's moving very fast relative to the surface.

Asking how fast the pole is moving relative to the surface is effectively the same as asking what the "ground speed" of the Moon is. This is tricky to calculate, because the Moon's ground speed varies over time in a complicated way. Luckily for us, it doesn't vary that much—it's usually somewhere between 390 and 450 m/s, or a little over Mach 1—so figuring out the precise value isn't necessary.

Let's buy a little time by trying to figure it out anyway.

The Moon's ground speed varies pretty regularly, making a kind of sine wave. It peaks twice every month as it passes over the fast-moving equator, then reaches a minimum when it's over the slower-moving tropics. Its orbital speed also changes depending on whether it's at the close or far point in its orbit. This leads to a roughly sine-wave shaped ground speed:

Well, ready to jump?

Ok, fine. There's one other cycle we can take into account to really nail down the Moon's ground speed. The Moon's orbit is tilted by about 5° relative to the Earth-Sun plane, while the Earth's axis is tilted by 23.5°. This means that the Moon's latitude changes the way the Sun's does, moving from the northern tropics to the southern tropics twice a year.

However, the Moon's orbit is also tilted, and this tilt rotates on an 18.9-year cycle. When the Moon's tilt is in the same direction as the Earth's, it stays 5° closer to the Equator than the Sun, and when it's in the opposite direction, it reaches more extreme latitudes. When the Moon is over a point farther from the equator, it has a lower "ground speed," so the lower end of the sine wave goes lower. Here's the plot of the Moon's "ground speed" over the next few decades:

The Moon's top speed stays pretty constant, but the lowest speed rises and falls with an 18.9-year cycle. The lowest speed of the next cycle will be on May 1st, 2025, so if you want to wait until 2025 to slide down, you can hit the atmosphere when the pole is moving at only 390 m/s relative to the Earth's surface.

When you do finally enter the atmosphere, you'll be coming down near the edge of the tropics. Try to avoid the tropical jet stream, an upper-level air current which blows in the same direction the Earth rotates. If your pole happens to go through it, it could add another 50-100 m/s to the wind speed.

Regardless of where you come down, you'll need to contend with supersonic winds, so you should wear lots of protective gear.[15]For aerodynamic reasons, this gear should probably make it look like you're wearing a very fast airplane. Make sure you're tightly attached to the pole, since the wind and various shockwaves will be violently battering and jolting you around. People often say, "It's not the fall that kills you, it's the sudden stop at the end." Unfortunately, in this case, it's probably going to be both.[17]If it helps, people have survived supersonic ejections before—and even a supersonic aircraft disintegration—so there's hope.

At some point, to reach the ground, you're going to have to let go of the pole. For obvious reasons, you don't want to jump directly onto the ground while moving at Mach 1. Instead, you should probably wait until you're somewhere near airline cruising altitude, where the air is still thin, so it's not pulling at you too hard—and let go of the pole. Then, as the air carries you away and you fall toward the Earth, you can open your parachute.

Then, at last, you can drift safely to the ground, having traveled from the Moon to the Earth completely under your own muscle power.

(When you're done, remember to remove the fire pole. That thing is definitely a safety hazard.)

Read the whole story
jordanbrock
53 days ago
reply
Perth, Western Australia
popular
54 days ago
reply
Share this story
Delete

Every Last Jedi

1 Comment and 3 Shares

This is a spoiler-filled first set of reactions to Star Wars: The Last Jedi.

The ultimate courage of what Rian Johnson has done here, is that he fully embraced what it is to be a director who obviously grew up as true fan of Star Wars, and retconned the whole universe into a new understanding of The Force. It’s the kind of revolutionary rethinking of the most successful pop culture franchise of all time that I would have thought would not be possible by anyone but George Lucas, and certainly not under the auspices of Disney. But here we are.

Though it’s well-grounded in the first definitions of The Force that we were introduced to in the original trilogy, The Last Jedi presents a radically inclusive new view of the Force that is bigger and broader than the Jedi religion which has thus-far colored our view of the entire Star Wars universe. (This is also why lost-cause diehards will likely always hate this film.)

On a personal level, it really makes me smile to know that in Carrie Fisher’s last film, in her most famous role, she’d get to know that the vision of what the franchise was about would be broadened to include everyone. Now, every kid who ever picked up a broomstick and pretended to be Luke Skywalker with a lightsaber is canonically one with the Force. It’s a wonderful summation of what Star Wars, at its best, represents in culture.

It’s also a brave film for its willingness to subvert the expectations of the most hardcore fans. In many ways, The Last Jedi is anti-fan service. Tonally, it’s totally different than the other films in the series. Flashbacks and editing sequences like when Rey first sees the Force feature a wildly different direction style than Lucas ever would have tried. Jokes like the initial Poe-Hux call are completely out of character for the voice of the other films (especially the prequels). And the Jedi are no longer an infallible inherited priesthood, but a religion of self-absorbed, usually short-sighted monks who neglect the beauty of the Force in favor of exploiting it for their own power. Any one of these would antagonize those who were overly invested in the old order; all of them together is rank heresy.

But for an open-minded viewer, there are wonderful touches throughout. Rey gets to be a whole person, who grounds the film and is brave and grows, without ever being reduced to a love interest or damsel in distress. Similarly, Rose gets to be not just the first Asian American woman to be featured in Star Wars, but the avatar of the theme of the entire film. The porgs porg it up. Lots of stuff is red. The sound design uses silence more effectively than any blockbuster film since Attack of the Clones. There’s not much Threepio. It’s all pretty great.

Most of all, it sets us up for a third film where, for the first time in 37 years, we don’t know what’s going to happen next with Star Wars. Restoring our sense of wonder or mystery or surprise about the most culturally dominant franchise of all time is one of the toughest challenges any mainstream director could pull off. Succeeding in that challenge makes The Last Jedi a wonderful gift to every kid who ever swung a broomstick lightsaber.

Read the whole story
jordanbrock
210 days ago
reply
Perth, Western Australia
Share this story
Delete
1 public comment
jhamill
171 days ago
reply
Just saw it again today. I am so glad Rey did not end up as a love interest. I love angry old Luke Skywalker. I'm so happy they didn't keep him as the hopeful kid from the original trilogy. I mean, how can you not be angry after spending the last 10ish years alone on an island thinking about how you think you messed up?
California
sirshannon
171 days ago
I'm afraid to go back and watch my current top 2 SW movies because I'm afraid my memories of them may be the only thing keeping The Last Jedi in the number 3 spot.

Seven Years

9 Comments and 34 Shares
[hair in face] "SEVVVENNN YEEEARRRSSS"
Read the whole story
jordanbrock
210 days ago
reply
Perth, Western Australia
popular
212 days ago
reply
Share this story
Delete
9 public comments
chrisrosa
211 days ago
reply
😢
San Francisco, CA
rjstegbauer
213 days ago
reply
Touching and beautiful! One of your best.
alt_text_bot
213 days ago
reply
[hair in face] "SEVVVENNN YEEEARRRSSS"
ameel
213 days ago
reply
<3
Melbourne, Australia
MaryEllenCG
213 days ago
reply
::sniffle::
Greater Bostonia
kyleniemeyer
213 days ago
reply
😭
Corvallis, OR
louloupix
213 days ago
reply
That's why I still watch it..Time to time they deliver...
Celine17
203 days ago
j'ai toujours autant de mal à comprendre la trame...
marcrichter
213 days ago
reply
Awesome. I'm speechless.
tbd
deezil
214 days ago
reply
OKAY I'M CRYING AT MY DESK NOW.
Louisville, Kentucky
sfrazer
214 days ago
God damnit, Randal.
deezil
213 days ago
For those that don't know the whole story: Approximately 7 years ago (imagine that) Randall posted this on the blog https://blog.xkcd.com/2010/11/05/submarines/ and made some vague references to tough times in the comics. On in to 2011, he posted this on the blog, and things seemed to be scary but hopeful. https://blog.xkcd.com/2011/06/30/family-illness/ . He's made mention several times about it over the years inside the comics, and I really believe that "Time" was made for some express purpose as to get his emotions out. But this update seriously is making a grown 32 year old man weep openly at his desk (thankfully I have a door that closes), as I always wondered how things were. Things look good, and this makes my heart happy.

Saudi Arabia may go broke before the US oil industry buckles

1 Share

If the aim was to choke the US shale industry, the Saudis have misjudged badly, just as they misjudged the growing shale threat at every stage for eight years. "It is becoming apparent that non-OPEC producers are not as responsive to low oil prices as had been thought, at least in the short-run," said the Saudi central bank in its latest stability report.

"The main impact has been to cut back on developmental drilling of new oil wells, rather than slowing the flow of oil from existing wells. This requires more patience," it said.

One Saudi expert was blunter. "The policy hasn't worked and it will never work," he said.

By causing the oil price to crash, the Saudis and their Gulf allies have certainly killed off prospects for a raft of high-cost ventures in the Russian Arctic, the Gulf of Mexico, the deep waters of the mid-Atlantic, and the Canadian tar sands.

Consultants Wood Mackenzie say the major oil and gas companies have shelved 46 large projects, deferring $200bn of investments.

The problem for the Saudis is that US shale frackers are not high-cost. They are mostly mid-cost, and as I reported from the CERAWeek energy forum in Houston, experts at IHS think shale companies may be able to shave those costs by 45pc this year - and not only by switching tactically to high-yielding wells.

Advanced pad drilling techniques allow frackers to launch five or ten wells in different directions from the same site. Smart drill-bits with computer chips can seek out cracks in the rock. New dissolvable plugs promise to save $300,000 a well. "We've driven down drilling costs by 50pc, and we can see another 30pc ahead," said John Hess, head of the Hess Corporation.

It was the same story from Scott Sheffield, head of Pioneer Natural Resources. "We have just drilled an 18,000 ft well in 16 days in the Permian Basin. Last year it took 30 days," he said.

The North American rig-count has dropped to 664 from 1,608 in October but output still rose to a 43-year high of 9.6m b/d June. It has only just begun to roll over. "The freight train of North American tight oil has kept on coming," said Rex Tillerson, head of Exxon Mobil.

He said the resilience of the sister industry of shale gas should be a cautionary warning to those reading too much into the rig-count. Gas prices have collapsed from $8 to $2.78 since 2009, and the number of gas rigs has dropped 1,200 to 209. Yet output has risen by 30pc over that period.

Until now, shale drillers have been cushioned by hedging contracts. The stress test will come over coming months as these expire. But even if scores of over-leveraged wild-catters go bankrupt as funding dries up, it will not do OPEC any good.

The wells will still be there. The technology and infrastructure will still be there. Stronger companies will mop up on the cheap, taking over the operations. Once oil climbs back to $60 or even $55 - since the threshold keeps falling - they will crank up production almost instantly.

OPEC now faces a permanent headwind. Each rise in price will be capped by a surge in US output. The only constraint is the scale of US reserves that can be extracted at mid-cost, and these may be bigger than originally supposed, not to mention the parallel possibilities in Argentina and Australia, or the possibility for "clean fracking" in China as plasma pulse technology cuts water needs.

Mr Sheffield said the Permian Basin in Texas could alone produce 5-6m b/d in the long-term, more than Saudi Arabia's giant Ghawar field, the biggest in the world.

Saudi Arabia is effectively beached. It relies on oil for 90pc of its budget revenues. There is no other industry to speak of, a full fifty years after the oil bonanza began.

Citizens pay no tax on income, interest, or stock dividends. Subsidized petrol costs twelve cents a litre at the pump. Electricity is given away for 1.3 cents a kilowatt-hour. Spending on patronage exploded after the Arab Spring as the kingdom sought to smother dissent.

The International Monetary Fund estimates that the budget deficit will reach 20pc of GDP this year, or roughly $140bn. The 'fiscal break-even price' is $106.

Far from retrenching, King Salman is spraying money around, giving away $32bn in a coronation bonus for all workers and pensioners.

He has launched a costly war against the Houthis in Yemen and is engaged in a massive military build-up - entirely reliant on imported weapons - that will propel Saudi Arabia to fifth place in the world defence ranking.

The Saudi royal family is leading the Sunni cause against a resurgent Iran, battling for dominance in a bitter struggle between Sunni and Shia across the Middle East. "Right now, the Saudis have only one thing on their mind and that is the Iranians. They have a very serious problem. Iranian proxies are running Yemen, Syria, Iraq, and Lebanon," said Jim Woolsey, the former head of the US Central Intelligence Agency.

Money began to leak out of Saudi Arabia after the Arab Spring, with net capital outflows reaching 8pc of GDP annually even before the oil price crash. The country has since been burning through its foreign reserves at a vertiginous pace.

The reserves peaked at $737bn in August of 2014. They dropped to $672 in May. At current prices they are falling by at least $12bn a month.

Khalid Alsweilem, a former official at the Saudi central bank and now at Harvard University, said the fiscal deficit must be covered almost dollar for dollar by drawing down reserves.

The Saudi buffer is not particularly large given the country's fixed exchange system. Kuwait, Qatar, and Abu Dhabi all have three times greater reserves per capita. "We are much more vulnerable. That is why we are the fourth rated sovereign in the Gulf at AA-. We cannot afford to lose our cushion over the next two years," he said.

Standard & Poor's lowered its outlook to "negative" in February. "We view Saudi Arabia's economy as undiversified and vulnerable to a steep and sustained decline in oil prices," it said.

Mr Alsweilem wrote in a Harvard report that Saudi Arabia would have an extra trillion of assets by now if it had adopted the Norwegian model of a sovereign wealth fund to recyle the money instead of treating it as a piggy bank for the finance ministry. The report has caused storm in Riyadh.

"We were lucky before because the oil price recovered in time. But we can't count on that again," he said.

OPEC have left matters too late, though perhaps there is little they could have done to combat the advances of American technology.

In hindsight, it was a strategic error to hold prices so high, for so long, allowing shale frackers - and the solar industry - to come of age. The genie cannot be put back in the bottle.

The Saudis are now trapped. Even if they could do a deal with Russia and orchestrate a cut in output to boost prices - far from clear - they might merely gain a few more years of high income at the cost of bringing forward more shale production later on.

Yet on the current course their reserves may be down to $200bn by the end of 2018. The markets will react long before this, seeing the writing on the wall. Capital flight will accelerate.

The government can slash investment spending for a while - as it did in the mid-1980s - but in the end it must face draconian austerity. It cannot afford to prop up Egypt and maintain an exorbitant political patronage machine across the Sunni world.

Social spending is the glue that holds together a medieval Wahhabi regime at a time of fermenting unrest among the Shia minority of the Eastern Province, pin-prick terrorist attacks from ISIS, and blowback from the invasion of Yemen.

Diplomatic spending is what underpins the Saudi sphere of influence in a Middle East suffering its own version of Europe's Thirty Year War, and still reeling from the after-shocks of a crushed democratic revolt.

We may yet find that the US oil industry has greater staying power than the rickety political edifice behind OPEC.

Read the whole story
jordanbrock
1074 days ago
reply
Perth, Western Australia
Share this story
Delete

My experience with Minitest and RSpec

1 Comment

I’ve been using RSpec in earnest for the past 6 months now, so I thought it’s time to write a blurrrgh poast comparing RSpec with Minitest. I’ve used Minitest for years, and RSpec only for 6 months, so please keep that in mind when reading!

PLEASE REMEMBER, I don’t care what test framework you use, as long as you are testing your code. This is a post just about my experience with these two frameworks. In other words, this is an opinion piece.

INTRO!!!

I really believe that all test frameworks are essentially the same. No test framework can do something that’s impossible for another to do. It’s just code. So what differentiates test frameworks? I would say the main difference would be user interface. So I’m really going to compare user interfaces between these frameworks.

Things I like about RSpec.

By far and away, my favorite thing about RSpec is that if there is a failure, it prints how to run just that one test at the bottom of the output. I can easily copy and paste that line and run just the one test. For people who don’t know, here is an example:

describe "something" do
  it "works" do
    expect(10).to equal(11)
  end

  it "really works" do
    expect(11).to equal(11)
  end
end

When you run this, the output looks like this:

[aaron@TC tlm.com (master)]$ rspec code/fail_spec.rb 
F.

Failures:

  1) something works
     Failure/Error: expect(10).to eq(11)
       
       expected: 11
            got: 10
       
       (compared using ==)
     # ./code/fail_spec.rb:3:in `block (2 levels) in <top (required)>'

Finished in 0.00504 seconds (files took 0.20501 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./code/fail_spec.rb:2 # something works
[aaron@TC tlm.com (master)]$ 

All you have to do to rerun just the one failing spec is to copy and paste that one line like this:

rerun demo

I don’t have to think or type, I just “copy, paste, run”. I like to think of this as a “learn as you play” feature.

The other thing I like about RSpec is that it ships with a colored output formatter, so if you do rspec --color, you’ll get colored output. I’ve used Minitest for years without colored output, but I’ve come to really like the colored output from RSpec. It helps me quickly see the most important parts of the test output, the assertion failure, and stack traces (though I highly suspect that the RSpec core team all use black backgrounds in their terminals because sometimes the colors aren’t so nice on my white terminal).

Things I like about Minitest

The main thing that I like about Minitest is that a Minitest test is just a Ruby class. Here is an example test similar to the RSpec sample I showed earlier:

require 'minitest/autorun'

class Something < Minitest::Test
  def test_works
    assert_equal 11, 10
  end

  def test_really_works
    assert_equal 11, 11
  end
end

I like this because I know exactly where the test_works method is defined. It’s no different than any other class in Ruby, so I don’t have to learn anything new. I like it because I am a heavy user of CTags, so I can easily jump to test methods or classes inside my editor. Another thing that’s nice about using regular Ruby classes is that when I need to refactor my tests, I just use my normal refactoring skills: I extract methods, classes, modules, change to inheritance, etc. I use the same refactoring techniques on my test files as I do on my library files. I think that is where Minitest really shines.

Things I dislike about RSpec

RSpec is a DSL for writing tests. I think this is probably RSpec’s largest weakness. I am a programmer, I can read code, so I don’t particularly care whether or not my test code “reads like English”. I don’t understand the value of the DSL, especially when I have a nearly 4000 line specfile that I’d like to refactor. How do I go about refactoring? I can extract methods:

describe "something" do
  def helper
    11
  end

  it "works" do
    expect(10).to eq(helper)
  end

  it "really works" do
    expect(11).to eq(helper)
  end
end

But where is the helper method defined? What’s its visibility? Can I put it in a module? Can I use inheritance? Who can call it? Can I call super from the extracted method? If so, where does super go? These are not the types of questions I want to be pondering when I have 3000 test failures and really long spec files to read through. My mind spins off in to thoughts like “I wonder how RSpec works?”, and “I wonder what my cat is doing?”

From what I can gather, calling describe in RSpec essentially defines a class. But if that’s the case, why not just use Ruby classes? Then I don’t need to guess about method visibility, modules, inheritance, etc. Not to mention, the library code that I’m working with is just using Ruby classes. Why do I need to switch to some other language for testing?

Nesting a describe seems to perform inheritance, but only for certain things like before blocks. If you run this code:

describe "something" do
  before do
    puts "hi!"
  end

  it "works" do
    expect(10).to eq(helper)
  end

  it "really works" do
    expect(11).to eq(helper)
  end

  context "another thing" do
    before do
      puts "hello!"
    end

    it "really really works" do
      expect(11).to eq(helper)
    end
  end

  def helper
    11
  end
end

You’ll see “hi!” printed 3 times, once for each it, and “hello!” printed once. For the nested context, I would like to print “hello!” before it prints “hi!”. In a normal inheritance situation, I would change the call to super. I am not sure how to do what I just described without learning a new thing (I think I would need let but I don’t know). For now, I’m coping with this by refactoring to classes outside of the specs themselves, then calling the objects from the specs. Essentially “composition” in my tests.

Another thing that bugs me is that if I do try to refactor my RSpec tests, and I change any lines, then the line that I copy and pasted to run just the one test won’t work anymore. I have to figure out the new line. I can use the name of the test by specifying the -e flag on RSpec, but then I lose the “copy, paste, run” feature that I love so much.

Anyway, I will stop picking on RSpec now. To me, RSpec seems to have some sort of identity crisis and is caught somewhere between “a language for writing tests” and “just Ruby”. That is RSpec’s biggest weakness.

Things I dislike about Minitest

If RSpec does one thing better than Minitest, I would say that the command line UI easily outshines Minitest. Here is one example.

I can run one test at a time like so:

$ ruby code/fail_test.rb -n Something#test_works

This will run the test_works method on the Something class. The problem for me is that it’s not clear to do that when you see the failing test output. If we run the whole suite, the output looks like this:

[aaron@TC tlm.com (master)]$ ruby code/fail_test.rb 
Run options: --seed 5990

# Running:

.F

Finished in 0.002047s, 977.0396 runs/s, 977.0396 assertions/s.

  1) Failure:
Something#test_works [code/fail_test.rb:5]:
Expected: 11
  Actual: 10

2 runs, 2 assertions, 1 failures, 0 errors, 0 skips
[aaron@TC tlm.com (master)]$

Looking at this, how would you know how to run just that one test? With RSpec, it’s no problem. I was able to learn how to run just one test the first time I ever used RSpec. I didn’t read any docs, just ran the tests, and the info was right there. Coming from RSpec, you might need to think you could do this:

$ ruby code/fail_test.rb:5

But of course that doesn’t work because you’re just using Ruby on the command line.

Here is a short video of me running the single test:

demo

The disadvantages of this over RSpec’s output is I have to type a few characters and know a commandline interface in advance. You might think “it’s just a few characters”, but every time I have to type something is a potential for a mistake that I’ll have to correct, which takes even more time. I really think the advantages of “copy, paste, run” can’t be understated. (Yes, I know there are tools like autotest for both Minitest and RSpec that will run tests for you, but sometimes I can’t / don’t use them)

The other thing I wish Minitest would do is to ship with a color formatter like RSpec does. I am used to the color output from RSpec, and I don’t really want to go back. It really helps me focus on what’s important about my test failures.

Conclusion

Both of these frameworks have things I like and dislike. Being able to reuse my debugging and refactoring skills in my tests is pretty important to me, especially since I deal with lots of legacy code. This is why I’ll stick with Minitest in my personal projects. However, I am sure I will get better at refactoring and debugging in RSpec tests, and when I get better at it, I will share what I learn.

Now, do I care which one you use? No. As long as you test your code, I am happy. A professional developer should be able to work in either one of these because they essentially do the same thing: test your code.

Read the whole story
jordanbrock
1267 days ago
reply
"Do I care which in you use? No."
Perth, Western Australia
Share this story
Delete

How Software Works

1 Comment and 4 Shares

Here's a lesson in how software development works.

Say you'd like to port a popular arcade game to your home video console. You can give a guy like Tod Frye four months to do a good-enough version of Pac-Man. It'll sell 7 million copies, even though it looks like this:

Pac-Man 2600

Or, you can wait for 30 years of refinement and improvement in understanding of Atari software development, give someone three years to develop their own version of Pac-Man and end up with a near-flawless clone of the arcade original.

It will sell zero million copies.

Read the whole story
jordanbrock
1267 days ago
reply
I played the hell out of the Atari Pac-Man. I'd never played the arcade version (small town with only 2 game cabinets to play on) so my memories of the game are of beige dashes :)
Perth, Western Australia
Share this story
Delete
Next Page of Stories