mirror of
https://github.com/theoludwig/theoludwig.git
synced 2024-12-08 00:44:30 +01:00
fix(blog): typos in posts
This commit is contained in:
parent
c4650c34d9
commit
7febe6d1f9
@ -19,13 +19,13 @@ A clean code is a code that is **easy** to **read** and easy to **understand**.
|
|||||||
|
|
||||||
But I promise it is not a code that is easy to write, in fact it is really **hard to write Clean Code**.
|
But I promise it is not a code that is easy to write, in fact it is really **hard to write Clean Code**.
|
||||||
|
|
||||||
We could ask ourselves, what is **easy** to **read** and easy to **understand** ?
|
We could ask ourselves, what is **easy** to **read** and easy to **understand**?
|
||||||
|
|
||||||
It depends of many factors, and is somewhat relative to each one of us. The **perfect** Clean code **doesn't exist**, but we can try to be **as perfect as possible**.
|
It depends of many factors, and is somewhat relative to each one of us. The **perfect** Clean code **doesn't exist**, but we can try to be **as perfect as possible**.
|
||||||
|
|
||||||
## Why is it so important?
|
## Why is it so important?
|
||||||
|
|
||||||
Code like that works great, but it is not enough, even if the code will be read by the computer and understood by the machine, we should not forget that the code is **written by human** and will be also **read by human** not only a machine.
|
Code that works is great, but not enough, even if the code will be read and understood by the computer, we should not forget that the code is **written by human** and will be also **read by human** not only a machine.
|
||||||
|
|
||||||
For example the [Linux kernel](https://www.kernel.org/), is one of the biggest open source project with many contributors worldwide. Last data shows that it is about **20 millions** lines of code.
|
For example the [Linux kernel](https://www.kernel.org/), is one of the biggest open source project with many contributors worldwide. Last data shows that it is about **20 millions** lines of code.
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ We don't want to "reinvent the wheel" and rewrite everything from scratch for ea
|
|||||||
|
|
||||||
However, it is important to draw a line between what dependencies are worth the cost and which are not.
|
However, it is important to draw a line between what dependencies are worth the cost and which are not.
|
||||||
|
|
||||||
Most likely adding a [JavaScript npm package `is-odd`](https://www.npmjs.com/package/is-odd) to check if a number is odd or even for example, is not worth it. Writing it ourselves is easier and allows a better maintenance in the long term.
|
Most likely adding a [JavaScript npm package `is-odd`](https://www.npmjs.com/package/is-odd) to check if a number is odd or even for example, is not worth it. Writing it ourselves allows a better maintenance in the long term.
|
||||||
|
|
||||||
Learning **how to solve problems** and how to write efficient code is very important and also a very broad and complicated topic, so this blog post will only be an **introduction to the subject**, and will not go in depth.
|
Learning **how to solve problems** and how to write efficient code is very important and also a very broad and complicated topic, so this blog post will only be an **introduction to the subject**, and will not go in depth.
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ Here is a list of classes of functions that are commonly encountered when analyz
|
|||||||
|
|
||||||
### Estimating efficiency
|
### Estimating efficiency
|
||||||
|
|
||||||
By checking the time complexity of an algorithm, it is possible to check before implementing the algorithm,that it is efficient enough for the problem.
|
By checking the time complexity of an algorithm, it is possible to check before implementing the algorithm, that it is efficient enough for the problem.
|
||||||
|
|
||||||
Example: assume that the time limit for a problem is 1 second and the input size is $n = 10^5$. If the time complexity is $O(n^2)$, the algorithm will perform about $(10^5)^2 = 10^{10}$ operations.
|
Example: assume that the time limit for a problem is 1 second and the input size is $n = 10^5$. If the time complexity is $O(n^2)$, the algorithm will perform about $(10^5)^2 = 10^{10}$ operations.
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ Contiguous subarray is any sub series of elements in a given array that are cont
|
|||||||
|
|
||||||
**Explanation:** The subarray with the largest sum is `[2, 4, -3, 5, 2]` which has a sum of `10`.
|
**Explanation:** The subarray with the largest sum is `[2, 4, -3, 5, 2]` which has a sum of `10`.
|
||||||
|
|
||||||
### Worst solution: Brute force
|
### Worst solution: Brute force ($O(n^3)$)
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def maximum_subarray_sum_cubic(array: list[int]) -> int:
|
def maximum_subarray_sum_cubic(array: list[int]) -> int:
|
||||||
@ -309,7 +309,7 @@ def maximum_subarray_sum_cubic(array: list[int]) -> int:
|
|||||||
return best_sum
|
return best_sum
|
||||||
```
|
```
|
||||||
|
|
||||||
### Better solution: Linear time
|
### Better solution: Linear time ($O(n)$)
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def maximum_subarray_sum_linear(array: list[int]) -> int:
|
def maximum_subarray_sum_linear(array: list[int]) -> int:
|
||||||
|
Loading…
Reference in New Issue
Block a user