Cargo Culture and Majic numbers

User avatar
Pigeon
Posts: 18055
Joined: Thu Mar 31, 2011 3:00 pm

Cargo Culture and Majic numbers

Post by Pigeon » Fri Oct 26, 2012 10:31 pm

Cargo cult science

Cargo cult science refers to practices that have the semblance of being scientific, but do not in fact follow the scientific method The term was first used by the physicist Richard Feynman during his commencement address at the California Institute of Technology, United States, in 1974.

Cargo cults—the religious practice that has appeared in many traditional tribal societies in the wake of interaction with technologically advanced cultures—focus on obtaining the material wealth (the "cargo") of the advanced culture by building mock aircraft, landing strips, and the like.

Cargo cult programming

Cargo cult programming is a style of computer programming that is characterized by the ritual inclusion of code or program structures that serve no real purpose.

Cargo cult programming is typically symptomatic of a programmer not understanding either a bug he or she was attempting to solve or the apparent solution (compare shotgun debugging, voodoo programming). The term cargo cult programmer may also apply when an unskilled or novice computer programmer (or one not experienced with the problem at hand) copies some program code from one place and pastes it into another place, with little or no understanding of how the code works, or whether it is required in its new position.


User avatar
Pigeon
Posts: 18055
Joined: Thu Mar 31, 2011 3:00 pm

Re: Cargo Culture

Post by Pigeon » Fri Oct 26, 2012 10:36 pm

Majic

In the context of computer programming, magic is an informal term for abstraction - it is used to describe code that handles complex tasks while hiding that complexity to present a simple interface. The term is somewhat tongue-in-cheek and carries good connotations, implying that the interface simplifies an otherwise difficult or tedious task.

In recent years, however, a negative interpretation of the term has been gaining popularity. In this usage, "magic" refers to procedures which make calculations based on data not clearly provided to them, by accessing other modules, memory positions or global variables that they are not supposed to (in other words, they are not referentially transparent). According to most recent software architecture models, even when using structured programming, it is usually preferred to make each function behave the same way every time the same arguments are passed to it, therefore following one of the basic principles of functional programming. When a function breaks this rule, it is often said to contain "magic".

Code: Select all

function Magic() {
  global $somevariable;
 
  echo $somevariable;
}
 
$somevariable = true;
 
Magic();

While the code above is clear and maintainable, if it is seen in a large project, it is often hard to understand where the function Magic() gets its value from. It is preferred to write that code using the following concept:

function noMagic($myvariable) {
  echo $myvariable;
}
 
$somevariable = true;
 
noMagic($somevariable);



User avatar
Pigeon
Posts: 18055
Joined: Thu Mar 31, 2011 3:00 pm

Re: Cargo Culture

Post by Pigeon » Fri Oct 26, 2012 10:39 pm

Deep Majic

In computer programming, deep magic refers to techniques that are not widely known, and may be deliberately kept secret. The number of such techniques has arguably decreased in recent years, especially in the field of cryptography, many aspects of which are now open to public scrutiny.

The Jargon File makes a distinction between deep magic, which refers to (code based on) esoteric theoretical knowledge; black magic, which refers to (code based on) techniques that appear to work but which lack a theoretical explanation; and heavy wizardry, which refers to (code based on) obscure or undocumented intricacies of particular hardware or software. All three terms can appear in source code comments of the form:

Deep magic begins here...

Heavy Wizardry

Code or designs that trade on a particularly intimate knowledge or experience of a particular operating system or language or complex application interface.

Distinguished from deep magic, which trades more on arcane theoretical knowledge. Writing device drivers is heavy wizardry.

Black Magic

A technique that works, though nobody really understands why.


User avatar
Royal
Posts: 10562
Joined: Mon Apr 11, 2011 5:55 pm

Re: Cargo Culture

Post by Royal » Fri Oct 26, 2012 10:53 pm

:popcorn:


Always wondered about this. Holy football monkey jesus I'm interested in this stuff!

User avatar
Pigeon
Posts: 18055
Joined: Thu Mar 31, 2011 3:00 pm

Re: Cargo Culture

Post by Pigeon » Fri Oct 26, 2012 10:59 pm

Majic numbers and hexspeak

Hexspeak, like leetspeak, is a novelty form of variant English spelling using the hexadecimal numbers. Created by programmers who wanted a magic number, hexspeak words can serve as a clear and unique identifier with which to mark memory or data.

Using hexadecimal notation, which includes the digits 0123456789ABCDEF, it is possible to spell several words.

Notable magic numbers

Many computer processors, operating systems, and debuggers make use of magic numbers, especially as a magic debug value.

0x8BADF00D ("ate bad food") is used by Apple in iOS crash reports, when an application takes too long to launch, terminate, or respond to system events.

0x1BADB002 ("1 bad boot") Multiboot header magic number.

0xB16B00B5 ("big boobs") was required by Microsoft's Hyper-V hypervisor to be used by Linux guests as their "guest signature".[4] This offending code was later changed to 0x0DEFACED ("defaced").

0xBAADF00D ("bad food") is used by Microsoft's LocalAlloc(LMEM_FIXED) to indicate uninitialised allocated heap memory when the debug heap is used.

0xBADDCAFE ("bad cafe") is used by Libumem to indicate uninitialized memory area

0xCAFEBABE ("cafe babe") is used by Mach-O to identify Universal object files, and by the Java programming language to identify Java bytecode class files.

0xCAFED00D ("Cafe Dude") is used by Java as a magic number for their pack200 compression.

0xD15EA5E ("disease") is a flag that indicates regular boot on the Nintendo GameCube and Wii consoles.

0xDEADBABE ("Dead Babe") is used by IBM Jikes RVM as a sanity check of the stack of the primary thread

0xDEADBEEF ("dead beef") is frequently used to indicate a software crash or deadlock in embedded systems. DEADBEEF was originally used to mark newly allocated areas of memory that had not yet been initialized -- when scanning a memory dump, it is easy to see the DEADBEEF.

It is used by IBM RS/6000 systems, Mac OS on 32-bit PowerPC processors and the Commodore Amiga as a magic debug value. On Sun Microsystems' Solaris, it marks freed kernel memory. On OpenVMS running on Alpha processors, DEAD_BEEF can be seen by pressing CTRL-T. The DEC Alpha SRM console has a background process that traps memory errors, identified by PS as "BeefEater waiting on 0xdeadbeef".

0xDEADC0DE ("dead code") is used as a marker in OpenWRT firmware to signify the beginning of the to-be created jffs2 filesystem at the end of the static firmware.

0xDEADDEAD ("dead dead") is the bug check (STOP) code displayed when invoking a Blue Screen of Death either by telling the kernel via the attached debugger, or by using a special keystroke combination. This is usually seen by driver developers, as it is used to get a memory dump on Windows NT based systems. An alternative to 0xDEADDEAD is the bug check code 0x000000E2, as they are both called MANUALLY_INITIATED_CRASH as seen on the Microsoft Developer Network.

0xDEADFA11 ("dead fall") is used by Apple in iOS crash reports, when the user force quits an application.

0xDEAD10CC ("dead lock") is used by Apple in iOS crash reports, when application holds on to a system resource while running in the background.

0xDEFEC8ED ("defecated") is the magic number for OpenSolaris core dumps.

0xFACEFEED ("face feed") is used by Alpha servers running Windows NT. The Alpha Hardware Abstraction Layer (HAL) generates this error when it encounters a hardware failure.

0xFEE1DEAD ("feel dead") is used as a magic number in the Linux reboot system call.

0xE011CFD0 is used as magic number for Microsoft Office files. In little endian this reads D0CF11E0, "docfile0".

0x0000000FF1CE ("office") is used as the last part of product codes (guid) for Microsoft Office components (visible in registry under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall registry key).

0x00BAB10C ("oo-ba-block") is used as the magic number for the ZFS uberblock.

C15C:0D06:F00D ("cisco dog food") used in the IPv6 address of http://www.cisco.com on World IPv6 Day. "Dog food" refers to Cisco eating its own dog food with IPv6.

face:b00c ("facebook") used in the IPv6 address of http://www.v6.facebook.com

0xDEADD00D ("dead dude") is used by Android in the Dalvik virtual machine to indicate a VM abort.

0xCEFAEDFE ("face feed") is used by Apple in iOS as a header for binary files. In little endian this reads FACEFEED, "Face Feed".


User avatar
Pigeon
Posts: 18055
Joined: Thu Mar 31, 2011 3:00 pm

Re: Cargo Culture and Majic numbers

Post by Pigeon » Fri Oct 26, 2012 11:28 pm

Always thought this was interesting. From the Jargon file.

A Story About ‘Magic'

Some years ago, I (GLS) was snooping around in the cabinets that housed the MIT AI Lab's PDP-10, and noticed a little switch glued to the frame of one cabinet. It was obviously a homebrew job, added by one of the lab's hardware hackers (no one knows who).

You don't touch an unknown switch on a computer without knowing what it does, because you might crash the computer. The switch was labeled in a most unhelpful way. It had two positions, and scrawled in pencil on the metal switch body were the words ‘magic' and ‘more magic'. The switch was in the ‘more magic' position.

I called another hacker over to look at it. He had never seen the switch before either. Closer examination revealed that the switch had only one wire running to it! The other end of the wire did disappear into the maze of wires inside the computer, but it's a basic fact of electricity that a switch can't do anything unless there are two wires connected to it. This switch had a wire connected on one side and no wire on its other side.

It was clear that this switch was someone's idea of a silly joke. Convinced by our reasoning that the switch was inoperative, we flipped it. The computer instantly crashed.

Imagine our utter astonishment. We wrote it off as coincidence, but nevertheless restored the switch to the ‘more magic’ position before reviving the computer.

A year later, I told this story to yet another hacker, David Moon as I recall. He clearly doubted my sanity, or suspected me of a supernatural belief in the power of this switch, or perhaps thought I was fooling him with a bogus saga. To prove it to him, I showed him the very switch, still glued to the cabinet frame with only one wire connected to it, still in the ‘more magic’ position. We scrutinized the switch and its lone connection, and found that the other end of the wire, though connected to the computer wiring, was connected to a ground pin. That clearly made the switch doubly useless: not only was it electrically nonoperative, but it was connected to a place that couldn't affect anything anyway. So we flipped the switch.

The computer promptly crashed.

This time we ran for Richard Greenblatt, a long-time MIT hacker, who was close at hand. He had never noticed the switch before, either. He inspected it, concluded it was useless, got some diagonal cutters and diked it out. We then revived the computer and it has run fine ever since.

We still don't know how the switch crashed the machine. There is a theory that some circuit near the ground pin was marginal, and flipping the switch changed the electrical capacitance enough to upset the circuit as millionth-of-a-second pulses went through it. But we'll never know for sure; all we can really say is that the switch was magic.

I still have that switch in my basement. Maybe I'm silly, but I usually keep it set on ‘more magic’.

1994: Another explanation of this story has since been offered. Note that the switch body was metal. Suppose that the non-connected side of the switch was connected to the switch body (usually the body is connected to a separate earth lug, but there are exceptions). The body is connected to the computer case, which is, presumably, grounded. Now the circuit ground within the machine isn't necessarily at the same potential as the case ground, so flipping the switch connected the circuit ground to the case ground, causing a voltage drop/jump which reset the machine. This was probably discovered by someone who found out the hard way that there was a potential difference between the two, and who then wired in the switch as a joke.


User avatar
Pigeon
Posts: 18055
Joined: Thu Mar 31, 2011 3:00 pm

Re: Cargo Culture and Majic numbers

Post by Pigeon » Sat Oct 27, 2012 12:30 am

On the other side

Heisenbug

A bug that disappears or alters its behavior when one attempts to probe or isolate it.

This usage is not even particularly fanciful; the use of a debugger sometimes alters a program's operating environment significantly enough that buggy code, such as that which relies on the values of uninitialized memory, behaves quite differently.

Antonym of Bohr bug


User avatar
Royal
Posts: 10562
Joined: Mon Apr 11, 2011 5:55 pm

Re: Cargo Culture and Majic numbers

Post by Royal » Sat Oct 27, 2012 2:31 am

Pigeon wrote:On the other side

Heisenbug

A bug that disappears or alters its behavior when one attempts to probe or isolate it.

This usage is not even particularly fanciful; the use of a debugger sometimes alters a program's operating environment significantly enough that buggy code, such as that which relies on the values of uninitialized memory, behaves quite differently.

Antonym of Bohr bug

So this is why woman go to extremes when they start to realize they are wrong.

User avatar
Pigeon
Posts: 18055
Joined: Thu Mar 31, 2011 3:00 pm

Re: Cargo Culture and Majic numbers

Post by Pigeon » Sat Oct 27, 2012 3:17 am

that's not a bug; it's a feature.

User avatar
Royal
Posts: 10562
Joined: Mon Apr 11, 2011 5:55 pm

Re: Cargo Culture and Majic numbers

Post by Royal » Sat Oct 27, 2012 11:01 pm

Can we create a new category of programming called "Rain Dancing"

Post Reply