?

Log in

No account? Create an account
   Journal    Friends    Archive    Profile    Memories
 

set -e story - morfizm


Apr. 27th, 2018 03:20 pm set -e story

A brilliant story from http://mywiki.wooledge.org/BashFAQ/105

Why you shouldn't use set -e

(Nah, I am using it anyway. Screw portability.)


Once upon a time, a man with a dirty lab coat and long, uncombed hair
showed up at the town police station, demanding to see the chief of
police. "I've done it!" he exclaimed. "I've built the perfect
criminal-catching robot!"

The police chief was skeptical, but decided that it might be worth
the time to see what the man had invented. Also, he secretly thought,
it might be a somewhat unwise move to completely alienate the mad
scientist and his army of hunter robots.

So, the man explained to the police chief how his invention could tell
the difference between a criminal and law-abiding citizen using a
series of heuristics. "It's especially good at spotting recently
escaped prisoners!" he said. "Guaranteed non-lethal restraints!"

Frowning and increasingly skeptical, the police chief nevertheless
allowed the man to demonstrate one robot for a week. They decided that
the robot should patrol around the jail. Sure enough, there was a
jailbreak a few days later, and an inmate digging up through the
ground outside of the prison facility was grabbed by the robot and
carried back inside the prison.

The surprised police chief allowed the robot to patrol a wider area.
The next day, the chief received an angry call from the zookeeper.
It seems the robot had cut through the bars of one of the animal cages,
grabbed the animal, and delivered it to the prison.

The chief confronted the robot's inventor, who asked what animal it
was. "A zebra," replied the police chief. The man slapped his head and
exclaimed, "Curses! It was fooled by the black and white stripes!
I shall have to recalibrate!" And so the man set about rewriting the
robot's code. Black and white stripes would indicate an escaped
inmate UNLESS the inmate had more than two legs. Then it should be
left alone.

The robot was redeployed with the updated code, and seemed to be
operating well enough for a few days. Then on Saturday, a mob of
children in soccer clothing, followed by their parents, descended
on the police station. After the chaos subsided, the chief was told
that the robot had absconded with the referee right in the middle of
a soccer game.

Scowling, the chief reported this to the scientist, who performed a
second calibration. Black and white stripes would indicate an escaped
inmate UNLESS the inmate had more than two legs OR had a whistle on
a necklace.

Despite the second calibration, the police chief declared that the robot
would no longer be allowed to operate in his town. However, the news
of the robot had spread, and requests from many larger cities were
pouring in. The inventor made dozens more robots, and shipped them off
to eager police stations around the nation. Every time a robot grabbed
something that wasn't an escaped inmate, the scientist was consulted,
and the robot was recalibrated.

Unfortunately, the inventor was just one man, and he didn't have the
time or the resources to recalibrate EVERY robot whenever one of them
went awry. The robot in Shangri-La was recalibrated not to grab a
grave-digger working on a cold winter night while wearing a ski mask,
and the robot in Xanadu was recalibrated not to capture a black and
white television set that showed a movie about a prison break, and so
on. But the robot in Xanadu would still grab grave-diggers with ski
masks (which it turns out was not common due to Xanadu's warmer climate),
and the robot in Shangri-La was still a menace to old televisions (of
which there were very few, the people of Shangri-La being on the average
more wealthy than those of Xanadu).

So, after a few years, there were different revisions of the
criminal-catching robot in most of the major cities. In some places,
a clever criminal could avoid capture by wearing a whistle on a string
around the neck. In others, one would be well-advised not to wear orange
clothing in certain rural areas, no matter how close to the Harvest
Festival it was, unless one also wore the traditional black triangular
eye-paint of the Pumpkin King.

Many people thought, "This is lunacy!" But others thought the robots
did more good than harm, all things considered, and so in some places
the robots are used, while in other places they are shunned.

The end.

5 comments - Leave a commentPrevious Entry Share Next Entry

Comments:

From:birdwatcher
Date:April 28th, 2018 12:48 am (UTC)
(Link)
Надо же так жгуче ненавидеть эвристики.
From:morfizm
Date:April 28th, 2018 01:21 am (UTC)
(Link)
Это памятник пре-ML-ному поколению.

По-хорошему, конечно. надо тренировать set -e на датасете и не городить сложных conditions.

Machine Learning
(https://xkcd.com/1838/)
From:birdwatcher
Date:April 28th, 2018 01:27 am (UTC)
(Link)
Кстати, Windows так в 90-е годы интерпретировали вообще все бинарники, и ничего.
From:saint_dragon
Date:April 28th, 2018 05:58 am (UTC)
(Link)
Про set -e ничего не знаю, но сказка забавная, однако, странно, что сбежавшему из тюрьмы самой первой мыслью не придет в голову переодеться, чтоб не выделяться из толпы... И еще странно, что такие крутые роботы были, а интернета и синхронизации калибровки через интернет между разными роботами - нет, я видимо слишком сильно ничего не понимаю в роботах...
From:morfizm
Date:May 8th, 2018 08:07 am (UTC)
(Link)
> однако, странно, что сбежавшему из тюрьмы самой первой мыслью не придет в голову переодеться, чтоб не выделяться из толпы...

Про мимикрию, подстраиваясь под особенности робота, в тексте пишут: "In some places, a clever criminal could avoid capture by wearing a whistle on a string around the neck"

Насчёт синхронизации - я не удивлюсь, если окажется, что этот текст в оригинале написан ещё до повсеместного интернета :)

Эта сказка - аллегория, иллюстрирующая фундаментальную проблему реализации фичи "set -e" в разных шеллах... проблема в том, что есть много ситуаций-исключений, все не переберёшь, поэтому где-то учтены одни, а где-то другие. Всё кое-как живёт, пока ты знаком с текущей экосистемой, но ломается, если ты со своими старыми предположениями портируешь скрипт в другой *никс или на другой шелл.