Random Articles (Page 115)

Have a deep view into what people are curious about.

πŸ”— Rule of Three (Computer Programming)

πŸ”— Computing πŸ”— Computing/Software

Rule of three ("Three strikes and you refactor") is a code refactoring rule of thumb to decide when similar pieces of code should be refactored to avoid duplication. It states that two instances of similar code don't require refactoring, but when similar code is used three times, it should be extracted into a new procedure. The rule was popularised by Martin Fowler in Refactoring and attributed to Don Roberts.

Duplication is considered a bad practice in programming because it makes the code harder to maintain. When the rule encoded in a replicated piece of code changes, whoever maintains the code will have to change it in all places correctly.

However, choosing an appropriate design to avoid duplication might benefit from more examples to see patterns in. Attempting premature refactoring risks selecting a wrong abstraction, which can result in worse code as new requirements emerge and will eventually need to be refactored again.

The rule implies that the cost of maintenance certainly outweighs the cost of refactoring and potential bad design when there are three copies, and may or may not if there are only two copies.

Discussed on

πŸ”— Third Normal Form

πŸ”— Databases

Third normal form (3NF) is a database schema design approach for relational databases which uses normalizing principles to reduce the duplication of data, avoid data anomalies, ensure referential integrity, and simplify data management. It was defined in 1971 by Edgar F. Codd, an English computer scientist who invented the relational model for database management.

A database relation (e.g. a database table) is said to meet third normal form standards if all the attributes (e.g. database columns) are functionally dependent on solely the primary key. Codd defined this as a relation in second normal form where all non-prime attributes depend only on the candidate keys and do not have a transitive dependency on another key.

A hypothetical example of a failure to meet third normal form would be a hospital database having a table of patients which included a column for the telephone number of their doctor. The phone number is dependent on the doctor, rather than the patient, thus would be better stored in a table of doctors. The negative outcome of such a design is that a doctor's number will be duplicated in the database if they have multiple patients, thus increasing both the chance of input error and the cost and risk of updating that number should it change (compared to a third normal form-compliant data model that only stores a doctor's number once on a doctor table).

Codd later realized that 3NF did not eliminate all undesirable data anomalies and developed a stronger version to address this in 1974, known as Boyce–Codd normal form.

Discussed on

πŸ”— 1997 Lego Spill

πŸ”— Environment πŸ”— Disaster management πŸ”— Lego πŸ”— Cornwall

A maritime incident occurred on 13 February 1997 when a rogue wave struck the German-registered container ship Tokio Express off the coast of Land's End, Cornwall, United Kingdom, causing 62 containers to fall overboard. One container held approximately 4.8 million Lego pieces, primarily from sea-themed sets such as Lego Aquazone and Lego Pirates. The spilled pieces have washed ashore on coastlines across the UK, Ireland, the Netherlands, and as far as Australia, becoming a cultural phenomenon and an unintentional case study in ocean currents and marine plastic pollution.

πŸ”— Nyctography: A substituton cypher by Lewis Carroll

πŸ”— Cryptography πŸ”— Cryptography/Computer science

Nyctography (in Nyctography: ) is a form of substitution cipher writing created by Lewis Carroll (Charles Lutwidge Dodgson) in 1891. It is written with a nyctograph (a device invented by Carroll) and uses a system of dots and strokes all based on a dot placed in the upper left corner. Using the Nyctograph, one could quickly jot down ideas or notes without the aid of light. Carroll invented the Nyctograph and Nyctography as he was often awakened during the night with thoughts that needed to be written down at once, and didn't want to go through the lengthy process of lighting a lamp only to have to then extinguish it.

Discussed on

πŸ”— The If-by-whiskey fallacy

πŸ”— Philosophy πŸ”— Philosophy/Logic

In political discourse, if-by-whiskey is a relativist fallacy in which the speaker's position is contingent on the listener's opinion. An if-by-whiskey argument implemented through doublespeak appears to affirm both sides of an issue, and agrees with whichever side the listener supports, in effect taking a position without taking a position. The statement typically uses words with strongly positive or negative connotations (e.g., terrorist as negative and freedom fighter as positive).

Discussed on

πŸ”— Mithridatism

Mithridatism is the practice of protecting oneself against a poison by gradually self-administering non-lethal amounts. The word is derived from Mithridates VI, the King of Pontus, who so feared being poisoned that he regularly ingested small doses, aiming to develop immunity.

Discussed on

πŸ”— Fearmongering

πŸ”— Politics πŸ”— Psychology πŸ”— Marketing & Advertising

Fearmongering, or scaremongering, is the act of exploiting feelings of fear by using exaggerated rumors of impending danger, usually for personal gain.

Discussed on

πŸ”— Schwartzian Transform

πŸ”— Computer science

In computer programming, the Schwartzian transform is a technique used to improve the efficiency of sorting a list of items. This idiom is appropriate for comparison-based sorting when the ordering is actually based on the ordering of a certain property (the key) of the elements, where computing that property is an intensive operation that should be performed a minimal number of times. The Schwartzian transform is notable in that it does not use named temporary arrays.

The Schwartzian transform is a version of a Lisp idiom known as decorate-sort-undecorate, which avoids recomputing the sort keys by temporarily associating them with the input items. This approach is similar to memoization, which avoids repeating the calculation of the key corresponding to a specific input value. By comparison, this idiom assures that each input item's key is calculated exactly once, which may still result in repeating some calculations if the input data contains duplicate items.

The idiom is named after Randal L. Schwartz, who first demonstrated it in Perl shortly after the release of Perl 5 in 1994. The term "Schwartzian transform" applied solely to Perl programming for a number of years, but it has later been adopted by some users of other languages, such as Python, to refer to similar idioms in those languages. However, the algorithm was already in use in other languages (under no specific name) before it was popularized among the Perl community in the form of that particular idiom by Schwartz. The term "Schwartzian transform" indicates a specific idiom, and not the algorithm in general.

For example, to sort the word list ("aaaa","a","aa") according to word length: first build the list (["aaaa",4],["a",1],["aa",2]), then sort it according to the numeric values getting (["a",1],["aa",2],["aaaa",4]), then strip off the numbers and you get ("a","aa","aaaa"). That was the algorithm in general, so it does not count as a transform. To make it a true Schwartzian transform, it would be done in Perl like this:

Discussed on

πŸ”— Coastline Paradox

πŸ”— Mathematics πŸ”— Maps

The coastline paradox is the counterintuitive observation that the coastline of a landmass does not have a well-defined length. This results from the fractal curve-like properties of coastlines, i.e., the fact that a coastline typically has a fractal dimension (which in fact makes the notion of length inapplicable). The first recorded observation of this phenomenon was by Lewis Fry Richardson and it was expanded upon by Benoit Mandelbrot.

The measured length of the coastline depends on the method used to measure it and the degree of cartographic generalization. Since a landmass has features at all scales, from hundreds of kilometers in size to tiny fractions of a millimeter and below, there is no obvious size of the smallest feature that should be taken into consideration when measuring, and hence no single well-defined perimeter to the landmass. Various approximations exist when specific assumptions are made about minimum feature size.

The problem is fundamentally different from the measurement of other, simpler edges. It is possible, for example, to accurately measure the length of a straight, idealized metal bar by using a measurement device to determine that the length is less than a certain amount and greater than another amountβ€”that is, to measure it within a certain degree of uncertainty. The more accurate the measurement device, the closer results will be to the true length of the edge. When measuring a coastline, however, the closer measurement does not result in an increase in accuracyβ€”the measurement only increases in length; unlike with the metal bar, there is no way to obtain a maximum value for the length of the coastline.

In three-dimensional space, the coastline paradox is readily extended to the concept of fractal surfaces whereby the area of a surface varies, depending on the measurement resolution.

Discussed on

πŸ”— List of U.S. states and territories by net migration

πŸ”— United States

This is a list of U.S. states and the District of Columbia by annual net migration. The first table lists U.S. states and the District of Columbia by annual net domestic migration, while the second table lists U.S. states and the District of Columbia by annual net international migration. There is a separate table for the U.S. territories. The term net domestic migration describes the total number of people moving to a state from another state minus people moving to another state from that state. The term net international migration describes the total number of people moving to a state from another country minus people moving to another country from that state.

Discussed on