{"id":138,"date":"2021-01-14T20:00:00","date_gmt":"2021-01-14T19:00:00","guid":{"rendered":"https:\/\/tutos.switchelven.fr\/?p=138"},"modified":"2021-01-14T11:27:02","modified_gmt":"2021-01-14T10:27:02","slug":"programmation-bases","status":"publish","type":"post","link":"https:\/\/tutos.switchelven.fr\/fr\/programmation-bases\/","title":{"rendered":"Les bases de la programmations"},"content":{"rendered":"\n<p class=\"has-foreground-color has-text-color\">Hello World! Here is Switch. Today, I will introduce bases of programming through various languages. I will try my best to explain how to write clean simple code in different way and how you can pass from a language to another.<br><br>In this article, I will use: <a href=\"#c\">C<\/a>, <a href=\"#ocaml\">OCaml<\/a>, <a href=\"#go\">Golang<\/a>, <a href=\"#python\">Python<\/a> and a <a href=\"#pseudo-code\" data-type=\"internal\" data-id=\"#pseudo-code\">custom pseudo<\/a> code to go through some basic problems we can find.<\/p>\n\n\n\n<p class=\"has-large-font-size\">Basic code organisation<\/p>\n\n\n\n<p>When learning how to code, you will often start of by putting everything in a single place, providing a correct but heavy solution. For example, you would probably do something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\" line-numbers\">print(\"Hello World!\")\nprint(\"Hello Switch!\")\npint(\"*\")\npint(\"**\")\npint(\"***\")\npint(\"****\")<\/code><\/pre>\n\n\n\n<p>When asked to display:<br><em>Hello World!<br>Hello Switch!<br>*<br>**<br>***<br>****<\/em><br>And it works. <\/p>\n\n\n\n<p>Though this example is a bit exaggerated, it is a clear representation of what juniors will have hard time to balance: code separation. <\/p>\n\n\n\n<p>Programming languages offers you various way to associate values to names and define repetitive process as function.  A simple way to clarify the previous example is to define a function to say hello<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\" line-numbers\">function Hello(to):\n  message = \"Hello\" + to + \"!\"\n  print(message)<\/code><\/pre>\n\n\n\n<p>To avoid the repetition of the print line with <em>Hello ! + name<\/em>. <\/p>\n\n\n\n<p class=\"has-foreground-color has-text-color\">They also provide solution for repetitive tasks. Mosts current programming languages integrate <em>for<\/em> and <em>while<\/em> loop or accept <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Recursion_(computer_science)\" data-type=\"URL\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/Recursion_(computer_science)\" target=\"_blank\">recursive function<\/a> (a function who call itself). So, to display the <em>*<\/em> triangle, we could propose something like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\" line-numbers\">stars = \"\"\nfor i from 0 to 4 do:\n    stars = stars + \"*\"\n    print(stars)<\/code><\/pre>\n\n\n\n<p>The first thing you will find hard is to know if you should or not split a code block into a dedicated function or if a process has enough repetition to loop over it. <\/p>\n\n\n\n<p class=\"has-foreground-color has-text-color\">There are a lot of way to organise a code base, each one having its strong and weak points. In this blog, I will mainly use a basic module separation for small projects (regrouping related feature in a single module without specific rules) and <a href=\"https:\/\/whatis.techtarget.com\/definition\/clean-architecture#:~:text=Clean%20architecture%20is%20a%20software,separate%20from%20the%20delivery%20mechanism.\" data-type=\"URL\" data-id=\"https:\/\/whatis.techtarget.com\/definition\/clean-architecture#:~:text=Clean%20architecture%20is%20a%20software,separate%20from%20the%20delivery%20mechanism.\" target=\"_blank\" rel=\"noreferrer noopener\">Clean Architecture<\/a> for heavier code base (clean separation between project objectives, data management, transport to the user and functional block).<\/p>\n\n\n\n<p>Now, let&#8217;s try to solve some basic problems. <\/p>\n\n\n\n<p class=\"has-large-font-size\">Data swap (C &#8211; OCaml)<\/p>\n\n\n\n<p>First, we will produce algorithms to allow data swapping between two variables. The simplest solution for this is to use a third variable as tampon to store initial data, giving something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">a = 125\nb = \"trust\"\nc = b\nb = a\na = c<\/code><\/pre>\n\n\n\n<p> But what if I wished to make the same swap without relying on a secondary variable ? <\/p>\n\n\n\n<p>In order to simplify the reflexion, we will consider swapping integer only. If I have a variable <em>A<\/em> set to <em>5<\/em> and a variable <em>B<\/em> set to <em>2<\/em>, how can I make <em>A<\/em> become <em>2<\/em> and <em>B 5<\/em> without relying on a temporary storage. A simple solution is to use a protective operation between two values witch stores a composed value from initials and will allow to separate them at the end. Let&#8217;s say that we add <em>A<\/em> to <em>B<\/em>, <em>B<\/em> is then <em>7<\/em> and <em>A<\/em> is till <em>2<\/em>. When I remove<em> A <\/em>from <em>B<\/em> in <em>A<\/em>, I will have <em>A = B &#8211; A = 7 &#8211; 2 = 5<\/em>, witch is the initial value of <em>B<\/em>. Then I can remove <em>A<\/em> from <em>B<\/em> to retrieve <em>A<\/em>, cause: <em>A = A + B &#8211; B<\/em> and <em>B = A + B &#8211; A<\/em>, storing <em>A + B &#8211; A<\/em> in <em>A<\/em> and <em>A + B &#8211; B<\/em> in <em>B<\/em> will result in a swap. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">a = 7\nb = 2\nb = a + b\na = b - a\nb = b - a<\/code><\/pre>\n\n\n\n<p id=\"c\">Now let&#8217;s move to code.<br>First, we will implement it using C. C is one a first hight level langage ever, appearing in 1972 and is still heavily used in embedded system (car electronics for example). Lot of langages created since then are based on it. <\/p>\n\n\n\n<p>It is a static strongly typed langage, meaning you have to specify the type of any variable you create and function return value and types cannot overlaps (you cannot add an integer with a character chain). C defines<\/p>\n\n\n\n<pre title=\"C definition\" class=\"wp-block-code\"><code lang=\"c\" class=\"language-c line-numbers\">#include LIB; \/\/ include a library to use its functions\n\nTYPE NAME(T1 P1, T2 P2, ...) {} \/\/ declare a function named NAME returning type TYPE having parameters P1 of type T1 AND P2 of type T2\n\nTYPE NAME; \/\/ declare a variable NAME of type TYPE\n\nreturn SMTG; \/\/ stop function and make it returns SMTG\n\nfuncName(P1,P2,...); \/\/ Make a function call to funcName with parameters<\/code><\/pre>\n\n\n\n<p>Every C program has to provide a main function returning a type <em>int<\/em>. This function can have either a <em>void<\/em> argument (meaning nothing as to be provided) or a couple of parameters: <em>(int argc, char *argv[]<\/em>). This function represents your feature and is the only entry point to it. The <em>int<\/em> returned is used to indicate if errors occurs while computing. <em>0<\/em> means every thing was correct, any other states are errors.<\/p>\n\n\n\n<p>Let&#8217;s define the swap feature as a single main block. We will need to defined numerical or string variables (defined here means they have a specified value) and a process to swap them.<\/p>\n\n\n\n<pre title=\"single block swap\" class=\"wp-block-code\"><code lang=\"c\" class=\"language-c line-numbers\"><em><em>int <\/em>main(<em>void<\/em>) {\n  <em>int <\/em>a, b; <em>\/\/ declare two integer variables\n\n  <\/em>a = 2;\n  b = 5;\n\n  printf(\"First value is: %d and second value %d\\n\", a, b); <em>\/\/ show before swap\n  <\/em>b = a + b; <em>\/\/ get sum of A and B\n  <\/em>a = b - a; <em>\/\/ A + B - A = B -&gt; A is now B\n  <\/em>b = b - a; <em>\/\/ A + B - B = A -&gt; as A is B, and B is A+B, B is now A\n  <\/em>printf(\"First value is now: %d and second value %d\\n\", a, b); <em>\/\/ swap done\n\n  return <\/em>0; <em>\/\/ return 0 cause all went well :)\n<\/em>}<\/em><\/code><\/pre>\n\n\n\n<p>Now we have our main code to swap. Let&#8217;s isolate swap in a function:<\/p>\n\n\n\n<pre title=\"swap function\" class=\"wp-block-code\"><code lang=\"c\" class=\"language-c line-numbers\"><em>void <\/em>swap(<em>int <\/em>a, <em>int <\/em>b) {\n  b = a + b; <em>\/\/ get sum of A and B\n  <\/em>a = b - a; <em>\/\/ A + B - A = B -&gt; A is now B\n  <\/em>b = b - a; <em>\/\/ A + B - B = A -&gt; as A is B, and B is A+B, B is now A\n  <\/em>printf(\"First value is now: %d and second value %d\", a, b); <em>\/\/ swap done\n<\/em>}<\/code><\/pre>\n\n\n\n<p>We defined a swap method with two integer arguments witch will swap provided value then print swap result.<\/p>\n\n\n\n<p>Then let&#8217;s allow user to provide integer to swap. We have two options for this. Either let the user define the values on the fly, or let him provide values when running the program. The first solution relies on <em>stdio<\/em> library witch allow writing and reading standard entries, the second solution uses C args (<em>argc, argv <\/em>couple) from <em>main<\/em> function. <\/p>\n\n\n\n<p>Following code will expect user to pass two integers arguments to program. Then we just have to call our swap method to have the job done.<\/p>\n\n\n\n<pre title=\"users entry\" class=\"wp-block-code\"><code lang=\"c\" class=\"language-c line-numbers\"><em>int <\/em>main(<em>int <\/em>argc, <em>char <\/em>*argv[]) {\n  <em>int <\/em>a, b;\n\n  <em>if <\/em>(argc != 2) { <em>\/\/ check that we received 2 arguments\n    <\/em>printf(\"Swap expect 2 arguments, %d received!\", argc)\n    <em>return <\/em>1 <em>\/\/ return 1 cause we received an unexpected number of arguments witch is an error\n  <\/em>}\n\n  a = atoi(argv[0])\n  b = atoi(argv[1])<\/code><\/pre>\n\n\n\n<p>To let the user provide input its value while running the program, we can define a simple method witch will prompt him to enter a value then return it to main code.<\/p>\n\n\n\n<pre title=\"get int\" class=\"wp-block-code\"><code lang=\"c\" class=\"language-c line-numbers\">int getInt(void) {\n  int a;\n  printf(\"Enter an integer:\");\n  scanf(\"%d\", &amp;a); \/\/ scan user input and store it in a variable. The &amp; is required      here to let scan method modify a values (pointer concept)\n  return a;\n}<\/code><\/pre>\n\n\n\n<p>Now, I would like to provide this swap method from another language. What should I keep, what should I check to ensure it still works. <\/p>\n\n\n\n<p>First, I always can reuse the same algorithm in any language. How it is implemented will change depending on the syntax of the language but the concept behind it can be conserved. Then I have to know how the language allows me to do tasks like converting value or recovering user inputs. Most programming language integrates solution for basic tasks like those but not all do. Then I can adapt my code to the new target. Let&#8217;s do it with swap and move it to OCaml. <\/p>\n\n\n\n<p>OCaml is a language derived from C but its syntax is quite different. It is still a strongly typed langage but it use dynamic typing instead of static (you can force types using specific file to describe expected types but if you do not, OCaml will determine the best choice). <\/p>\n\n\n\n<p>Now, let&#8217;s adapt our C swap to OCaml. While C required a main function, OCaml does not. It will execute the file you provide to him as it is defined. So we just have to create a file witch declare swap function then call it. <\/p>\n\n\n\n<pre title=\"OCaml swap\" class=\"wp-block-code\"><code lang=\"ocaml\" class=\"language-ocaml line-numbers\">let swap <em>a<\/em> <em>b<\/em> = \n  let b = a + b in \n  let a = b - a in \n  let b = b - a in \n  (a, b);;\n\nswap 2 5;;<\/code><\/pre>\n\n\n\n<p>Here, we are doing exactly the same process than C version, but instead of printing the result, we are returning it. Using <em>let &#8230; in<\/em>, we redefined variables <em>a <\/em>and <em>b <\/em>to new value, then we define the couple <em>(a, b)<\/em> as resulting expressing for swap method. So when calling <em>swap 2 5<\/em>, we obtain the couple <em>5, 2<\/em> as a result.<\/p>\n\n\n\n<p>You can find code for other langages directly on github: <a href=\"https:\/\/github.com\/switchelven\/programming-bases\">https:\/\/github.com\/switchelven\/programming-bases<\/a> as I will not detail them as the adaptions are equivalent to C to OCaml conversion. So let&#8217;s move on to the next problem.<\/p>\n\n\n\n<p class=\"has-large-font-size\">Min and max (Go)<\/p>\n\n\n\n<p>This time, we would like to find the maximum or minimum from a list of value. With this method, the list <em>2,4,1,3,5,7,9<\/em> should provide <em>1<\/em> when computing <em>min<\/em> and <em>9 <\/em>for <em>max<\/em>. Once again, there are multiple may to do so. The simplest one is to compare each element one by one until we find min and max. Another would be to sort he list then take the first and last element. We can also think of multiple solution for comparison.<\/p>\n\n\n\n<p>Let&#8217;s start with the comparison. Of course, most languages will provide a direct comparison operators. And we will mostly use those operators as its clearer. But as an exercice, I would like to find a way to get min and max value directly from a calcul instead of unknown methods provided by the languages. Theoretically, we can use the fact that <em>A + B + A &#8211; B= 2A<\/em> and absolute values. How ? We know that <em>|A-B|<\/em> <em>= A-B <\/em>when <em>A &gt; B<\/em> and <em>|A-B| = B-A<\/em> when <em>A &lt; B<\/em>. From this, we can say that <em>A+B+|A-B| <\/em>will give <em>2A <\/em>if <em>A &gt; B<\/em> and <em>2B<\/em> if <em>B &gt; A<\/em>. Then using this result, we can also deduce than <em>A+B-|A-B| <\/em>will give <em>2A <\/em>if <em>A &lt; B<\/em> and <em>2B<\/em> if <em>B &lt; A<\/em>. Then our computation for min and max can be express like:<\/p>\n\n\n\n<pre title=\"min max pseudo code\" class=\"wp-block-code\"><code class=\" line-numbers\">function max(a, b) {\n  return (a+b+|a-b|)\/2\n}\n\nfunction min(a, b) {\n  return (a+b-|a-b|)\/2\n}<\/code><\/pre>\n\n\n\n<p>Then let&#8217;s implement it. This time, I will provide you a Go implementation you can adapt in other langages. <\/p>\n\n\n\n<pre title=\"Go min max\" class=\"wp-block-code\"><code lang=\"go\" class=\"language-go line-numbers\"><em>\n<em>func Min<\/em>(a int, b int) uint {\n   <em>return <\/em>uint(a+b-abs(a-b)) \/ 2\n}\n\n<em>func Max<\/em>(a int, b int) uint {\n   <em>return <\/em>uint(a+b+abs(a-b)) \/ 2\n}<\/em>\n\n<em>func <\/em>main() {\n   fmt.Println(\"Min of\", 135, 209, \"is\", Min(135, 209))\n   fmt.Println(\"Max of\", 178, 179, \"is\", Max(178, 179))\n}<\/code><\/pre>\n\n\n\n<p>You will notice that <em>Min<\/em> and <em>Max<\/em> function returns an uint instead of an integer. I choose this type to hint that this algorithm does not work well with negative numbers. Using an unsigned integer indicates <em>Min<\/em> and <em>Max<\/em> will never return negative numbers correctly. If you test the method on signed integer, you will see that this method works correctly for positive integer or differently signed integer. If both integers are negative, Min will return the max of the two while Max will return the minimal due to the absolute difference being computed.<\/p>\n\n\n\n<p>Now, we have to apply this method to a list of value. I talked about two different way to find the minimal and maximal value of a list. Comparing all element agains them selves is better than sorting the list when the list is randomly sorted. If the list is quite sorted, sorting it will be faster. As we cannot determine sorting of a list at computing time, we will have to choose depending on precondition. We can ensures those precondition when relying on internal inputs or specific structure. We could define an always sorted list where appending values will add it directly to its correctly sorted place. <\/p>\n\n\n\n<p>Assuming that the list as random sorting, the simplest implementation to get minimal and maximal value existing in an integer list in Go is<\/p>\n\n\n\n<pre title=\"min max list\" class=\"wp-block-code\"><code lang=\"go\" class=\"language-go line-numbers\">func MinMaxList(intList []<em>int<\/em>) (min <em>uint<\/em>, max <em>uint<\/em>) {\n    \/\/ Set default value if slice is empty\n    min = 0\n    max = 0\n\n    \/\/ Search for min and max in slice\n    for i, x := range intList {\n        \/\/ Set max and min on list fist element. \n        if i == 0 { \/\/ i is the index of element. Go starts indexing slices at 0\n            max = x\n            min = x\n            continue\n        }\n\n        \/\/ Check if current min\/max are still min or max comparing to current value\n        max = Max(int(max), x)\n        min = Min(int(min), x)\n    }\n\n    return \/\/ return computed min, max. The empty return in go will automatically returns named return parameters\n}<\/code><\/pre>\n\n\n\n<p class=\"has-large-font-size\">Pow (Python, OCaml)<\/p>\n\n\n\n<p>Now, let&#8217;s implement a <em>pow<\/em> method. Pow methods compute number power, a power is the repetition of multiplication (<em>pow(2,3)=2*2*2=8<\/em>). You already know a way to repeat a define number of time a single operation using <em>for loop<\/em>. This will give a pseudo code like:<\/p>\n\n\n\n<pre title=\"pow pseudo code\" class=\"wp-block-code\"><code class=\" line-numbers\">function pow(a, b) {\n  res = 1 \/\/ pow(number, 0) = 1\n  for _ from 0 to b do:\n    res = a * res\n  return res\n}<\/code><\/pre>\n\n\n\n<p>Another way to do so is to use a recursive function. Recursive function are function who defined simple known cases (globally called exit cases). They are known steps to the function where we exactly know the result. For pow method, we keep a single exit case with is (<em>pow(n,0)=1<\/em>). Then we have to find a method to go from any cases to those exit cases. Here, we can state that<em> (pow(a, n)=a*pow(a, n-1)<\/em>). So our recursive function will be expressed as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">function pow(a, n) {\n  if n == 0 {\n    return 1\n  }\n  return a * pow(a, n-1)\n}<\/code><\/pre>\n\n\n\n<p>Recursive function are powerful but you need to be aware of their space complexity (the required memory to run them). If we decompose the pow function for <em>pow(10,4)<\/em>, we have the following process:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">call pow(10, 4):\npow(10,4) = 10 * pow(10,3)\n  call pow(10, 3):\n  pow(10,3) = 10 * pow(10,2)\n    call pow(10,2):\n    pow(10,2) = 1O * pow(10,1)\n      call pow(10,1):\n      pow(10,1) = 10 * pow(10,0)\n        call pow(10,0):\n        pow(10,0) = 1\n        return 1\n     pow(10,1)=10 * pow(10, 0) = 10 * 1 = 10\n     return 10\n   pow(10,2) = 10*pow(10,1) = 10 * 10 = 100\n   return 100\n  pow(10,3) = 10 * pow(10,2) = 10 * 100 = 1000\n  return 1000\npow(10, 4) = 10 * pow(10,3) = 10 * 1000 = 10000\nreturn 10000<\/code><\/pre>\n\n\n\n<p>We see that each recursive call stores an operation while waiting for next step to be computed. When next state is computed, it executes is own stored operation before returning. Basic errors when dealing with recursive function are incorrect simplification step. Simplification steps are steps that execute a partial operation to approach the basic steps (they are the steps doing recursive calls). If your simplification does not help to move to single case, you will never reach them and will not be able to exit your method, leading to stack overflow errors.  Another common mistakes is to incorrectly compute result. You correctly reach your exits cases but the result is empty or invalid cause the method to simplify is not correctly implemented. When mastered, recursive method helps to cleanly defines some complex method. Now, let&#8217;s implement those two methods. I could present it in a single langage, but I will present you the Python implementation for the loop and OCaml way to implements recursive function. <\/p>\n\n\n\n<pre title=\"python for loop pow\" class=\"wp-block-code\"><code lang=\"python\" class=\"language-python line-numbers\"><em><em>def <\/em>pow(a, n):\n    res <em>= <\/em>1\n    <em>for <\/em>_ <em>in <\/em>range(0, n):\n        res <em>= <\/em>res <em>* <\/em>a\n    <em>return <\/em>res\n\n<em>if <\/em>__name__ <em>== <\/em>\"__main__\":\n    pow(3,10)<\/em><\/code><\/pre>\n\n\n\n<pre title=\"OCaml recursive pow\" class=\"wp-block-code\"><code lang=\"ocaml\" class=\"language-ocaml line-numbers\">let rec pow <em>a<\/em> n = \n  match n with\n  | 0 -&gt; 1\n  | _ -&gt; a * pow a (n-1);;\n\npow 3 10;;<\/code><\/pre>\n\n\n\n<p class=\"has-primary-color has-text-color has-small-font-size\" id=\"pseudo-code\">Pseudo code definition<\/p>\n\n\n\n<p class=\"has-small-font-size\">I will define the following keys when using pseudo code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">X = Value -&gt; stores Value into variable X allowing it to be called through X directly in the code (ex: stars = \"*\" will allow you to recover * character as stars in the next lines).\n\nprint(SOMETHING) -&gt; display SOMETHING to user.\n\n+ -&gt; is a basic addition on numbers, a concatenation on others (ex: 1 + 4 = 5, \"to\"+\"to\"= \"toto\").\n\nfunction Name(a, b, ...) -&gt; define a function as Name expecting values for a, b, ... Provided value will be known as it was named in function definition.\n\nfor X from A to B do -&gt; run proposed steps for each value from A to B known as X.<\/code><\/pre>\n\n\n\n<p class=\"has-primary-color has-text-color has-small-font-size\" id=\"ocaml\">OCaml code definition<\/p>\n\n\n\n<p class=\"has-small-font-size\">Ocaml was introduced in 1996 by french institute INRIA. It is initially designed to help with mathematical proofs and a singular syntax in the programming world.<\/p>\n\n\n\n<pre title=\"OCaml definitions\" class=\"wp-block-code\"><code lang=\"ocaml\" class=\"language-ocaml line-numbers\">open LIB;; (* include a library to use its functions *)\n\nlet NAME  P1 P2 = (* declare a function named NAME having parameters P1 and P2 *)\nlet NAME = VAL;; (* declare a variable NAME having value VAL *)\nlet rec NAME P1 P2 = (* declare a recursive function named NAME having parameters P1 and P2 *)\n\nfuncName(P1 P2 ...);; (* Make a function call to funcName with parameter *)\n\nmatch (P1, P2, ...) with (* match P1, P2, ... with values)\n| A, B, ... -&gt;           (* P1=1, P2=B, ... then execute *)\n| _, C, ... -&gt;           (* P1 is any, P2=C, ... then execute *) <\/code><\/pre>\n\n\n\n<p class=\"has-primary-color has-text-color has-small-font-size\" id=\"go\">Go code definition<\/p>\n\n\n\n<p class=\"has-small-font-size\">Go is a Google developed langage witch appear in 2009. It is a classic strongly static type langage.<\/p>\n\n\n\n<pre title=\"Go definition\" class=\"wp-block-code\"><code lang=\"go\" class=\"language-go line-numbers\">import MODULE \/\/ import module MODULE\n\nvar NAME TYPE \/\/ declare a variable named NAME of type TYPE\n\nfunc NAME(P1 T1, P2 T2) (RT1, RT2) \/\/ define a function NAME having parameters P1 of type T1 and P2 of type T2 returning a couple of type RT1, RT2<\/code><\/pre>\n\n\n\n<p class=\"has-primary-color has-text-color has-small-font-size\" id=\"python\">Python code definition<\/p>\n\n\n\n<p class=\"has-small-font-size\">Python is a complete langage aiming for simplicity and human comprehension. It was first released in 1980 and is weakly typed. It is very adaptative and is syntax is quite permissive witch make it look like a good langage to start but its quite the opposite. As the langage by itself does not provide any safeguard around common mistake like type incorrect inference and such, you encounter lots of unexpected issue while using it if you are new to programming. None the less, its still is a very good langage largely used and the default langage for data science.<\/p>\n\n\n\n<pre title=\"Python definition\" class=\"wp-block-code\"><code lang=\"python\" class=\"language-python line-numbers\">import MODULE \/\/ import module\nimport MODULE from path.to.file \/\/ import specific module from file\/module\n\ndef FUNC(P1, P2): \/\/ define function FUNC having parameters P1 and P2\n\nA = VAL \/\/ defines a variable A set to VAL<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduces bases of programming through various languages and details common points between each and how to move from one to another.<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[13,15,14,12,16],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-tutorial","tag-c","tag-go","tag-ocaml","tag-programming-bases","tag-python","entry"],"_links":{"self":[{"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/comments?post=138"}],"version-history":[{"count":65,"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":207,"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/posts\/138\/revisions\/207"}],"wp:attachment":[{"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/media?parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/categories?post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutos.switchelven.fr\/fr\/wp-json\/wp\/v2\/tags?post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}