"...Instead of asking machines to understand people’s
language, it involves asking people to make the extra
effort...."
T. Berners-Lee, 1998, about the concept of
machine-understandable documents.
Soure: A Semantic Web is not Artificial Intelligence
Friday, December 09, 2011
Thursday, December 01, 2011
Easier to ask for forgiveness than permission - Programming
EAFP
Easier to ask for forgiveness than permission. This common Python coding style assumes the existence of valid keys or attributes and catches exceptions if the assumption proves false. This clean and fast style is characterized by the presence of many try and except statements. The technique contrasts with the LBYL style common to many other languages such as C.LBYL
Look before you leap. This coding style explicitly tests for pre-conditions before making calls or lookups. This style contrasts with the EAFP approach and is characterized by the presence of many if statements. In a multi-threaded environment, the LBYL approach can risk introducing a race condition between “the looking” and “the leaping”. For example, the code, if key in mapping: return mapping[key] can fail if another thread removes key from mapping after the test, but before the lookup. This issue can be solved with locks or by using the EAFP approach.
Strong vs weak typing in programming
Example
Weak Typing | Strong Typing | |
---|---|---|
Pseudocode | a = 2 b = "2" concatenate(a, b) # Returns "22" add(a, b) # Returns 4 |
a = 2 b = "2" concatenate(a, b) # Type Error add(a, b) # Type Error concatenate(str(a), b) # Returns "22" add(a, int(b)) # Returns 4 |
Languages | Perl, PHP, Rexx, JavaScript, BASIC | Java, C, C++, Python, C#, Vala |
Subscribe to:
Posts (Atom)