📜 ⬆️ ⬇️

Learning to understand the art of programming

Classic


The most common code.

$size = sizeof($arr)-1; for ($i = $size; $i>=0; $i--) { for ($j = 0; $j<=($i-1); $j++) if ($arr[$j]>$arr[$j+1]) { $k = $arr[$j]; $arr[$j] = $arr[$j+1]; $arr[$j+1] = $k; } } 


Baroque


Baroque (Italian. Barocco - "quaint", "strange", "prone to excess")
Baroque is characterized by contrast, tension, the desire for greatness and pomp, both in naming and commentary, to the fusion of different coding styles. Usually already on production hidden “detonators” are found.

Most often used in: javascript, c ++, java.
')
  $SIZE = SIZEof($A_R__R)-1; for ($i = $SIZE; $i>=0; $i--) { for ($j = 0; $j<=($i-1); $j++) if ($A_R__R[$j]>$A_R__R[$j+1]) { //   $A_R__R[$j+1] = $A_R__R[$j]; + $A_R__R[$j+1]; $A_R__R[$j] = $A_R__R[$j+1] - $A_R__R[$j]; $A_R__R[$j+1] = $A_R__R[$j+1] - $A_R__R[$j]; } } 


Gothic


Gothic traits:
Gothic is characterized by specific code construction in the form of various vertical alignments, richly named variables with unusual details. Just as often, the code is so tied to a specific hardware configuration that it looks impressive and monolithic.

Most often used in: javascript, php, python, perl.

  $size = sizeof($arr)- 1 ; for ($INDEX_I = $size; $INDEX_I>=0 ; $INDEX_I--){ for ($INDEX_J = 0; $INDEX_J<=($INDEX_I-1) ; $INDEX_J++) if( $arr[$INDEX_J] > $arr[$INDEX_J+1]){ $k = $arr[$INDEX_J] ; $arr[$INDEX_J] = $arr[$INDEX_J+1] ; $arr[$INDEX_J+1] = $k ; } } 


Minimalism


Common features:
Minimalism is characterized by spatial freedom, zoning of space, variables mostly single-letter, in one register, often reused, lack of spaces, simple cycles and conditions, implementation of only the basic functionality, no explanations and comments.

Most commonly used in: Perl, Ruby, Python, Haskell, Scala, Erlang, F #.

  for($i=sizeof($M)-1;$i>=0;$i--){ for($j=0;$j<=($i-1);$j++) if($M[$j]>$M[$j+1]) { list($M[$j],$M[$j+1])=[$M[$j+1],$M[$j]]; } } 


Expressionism


The banality, ugliness and contradictions of modern programming languages ​​evoked in Expressionists feelings of irritation, disgust, anxiety and frustration, which they conveyed with the help of hardcode, spaghetti code, fast and coarse hacks. Preference is given to a particularly ugly code in order to increase the impact on the viewer, not to leave it indifferent.

Most often used in: C #, Ruby, Common Lisp, PHP, Shen / Qi II.

 <?php $error = null; $query = 'SELECT * FROM prices'; $result = mysql_query($query) or $error = '  : ' . mysql_error(); $arr = []; while ($line = mysql_fetch_row($result)) { $arr[] = $line['price']; } $size = sizeof($arr)-1; for ($i = $size; $i>=0; $i--) { for ($j = 0; $j<=($i-1); $j++) if ($arr[$j]>$arr[$j+1]) { $k = $arr[$j]; $arr[$j] = $arr[$j+1]; $arr[$j+1] = $k; } } echo "<ul>"; foreach ($arr => $v) echo "<li>".$v."</li>"; echo "</ul>"; ?> <script> var error = "<?php echo $error?>"; if (error) alert("ERROR: " + error); </script> 


Abstractionism


Abstraction traits:
Virtually all of the program code is exclusively decoration around a Divine Object. Code that is configured so flexible (and confusing) that I want to better it was a hard code.

Most often used in: Java, PHP.

sort.php
 <?php require_once 'Sorter/Bubble/NumericArray.php'; require_once 'Storage/Array.php'; $bubbleSorter = new Sorter_Bubble_NumericArray(); $storage = new Storage_Array; $storage->setElements(array(15, 204, 1, 4, 2, 6, 8, 3, 150)); $bubbleSorter->sort($storage); var_dump($storage->getElements()); 

Abstract.php
 <?php require_once 'Sorter/Interface.php'; abstract class Sorter_Bubble_Abstract implements Sorter_Interface { /** * * @var Comparator_Interface */ protected $_comparator; /** * * @var Swapper_Interface */ protected $_swapper; /** * * @var Storage_Interface */ protected $_storage; /** * */ public function _bubble() { for ($i = $this->_storage->getSize() - 1; $i >= 0; $i--) { for ($j = 0; $j <= ($i - 1); $j++) { if ($this->_comparator->isBigger($this->_storage->getElementByIndex($j + 1), $this->_storage->getElementByIndex($j))) { $this->_swapper->swap($this->_storage, $j + 1, $j); } } } } } 


NumericArray.php
 <?php require_once 'Sorter/Bubble/Abstract.php'; require_once 'Storage/Interface.php'; require_once 'Comparator/Numeric.php'; require_once 'Swapper.php'; class Sorter_Bubble_NumericArray extends Sorter_Bubble_Abstract { public function sort(\Storage_Interface &$storage) { $this->_storage = $storage; $this->_comparator = new Comparator_Numeric(); $this->_swapper = new Swapper(); $this->_bubble(); } } 


Link to all code.

Cubism


Cubism is characterized by the use of underlined geometrical conditional forms, the desire to "split" real objects into stereometric primitives.

Most often used in: Perl, Shen / Qi II, Python.

  $size= sizeof($arr)- 1; for($i =$size;$i>=0; $i--) { for($j =0;$j<=($i-1); $j++) if($arr[$j] > $arr[$j+1]) { $k= $arr[$j]; $arr[$j]= $arr[$j+1]; $arr[$j+1]= $k; } } 


Pop Art


Pop art from English popular art, abbreviated pop art - a popular, publicly available code.

Traits of pop art:
Simple and bright code, provoking and provocative comments, pop art in the code attracts extraordinary personalities. There is almost no excess in pop art - here different approaches and coding styles are mixed. Usually grows out of historical contribution.

Most often used in: C ++, Java, PHP, C #, 1C.

  $CocaCola = sizeof($Elvis)-1; //     <<----   for ($i = $CocaCola; $i>=0; $i--) { for ($j = 0; $j<=($i-1); $j++) if ($Elvis[$j]>$Elvis[$j+1]) { //       ,     $Presley = $Elvis[$j]; $Elvis[$j] = $Elvis[$j+1]; $Elvis[$j+1] = $Presley; } } 


And what style and in which programming language do you most often meet?

Resources used

Source: https://habr.com/ru/post/225827/


All Articles