diff --git a/.vscode/settings.json b/.vscode/settings.json index 5ad8faa..76e2e16 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,8 @@ { "cSpell.words": [ -<<<<<<< Updated upstream - "adzyb", -======= ->>>>>>> Stashed changes "decrement", "iterable", "pythonic" ], - "python.pythonPath": "venv\\Scripts\\python.exe" + "python.pythonPath": "c:\\Program Files\\Python38\\python.exe" } \ No newline at end of file diff --git a/docs/functions/user-functions/README.md b/docs/functions/user-functions/README.md index 7dd91b8..b16aac8 100644 --- a/docs/functions/user-functions/README.md +++ b/docs/functions/user-functions/README.md @@ -1,7 +1,7 @@ # Functions Functions are self contained objects that are used to create code that we often want to reuse. The most arbitrary use of a function is in this code: -{{ code_from_file("conditionals/example-1.py", 1, 9, execute=True) }} +{{ code_from_file("functions/user-functions/example-1.py", 1, 9, execute=True) }} As you can see, we have created our first function. To create a function you must first use the def keyword followed by the name for the function. The naming conventions for functions are the same as they are for variables. However, it is good practice to have descriptive names for your functions so that you can recognise what they do at a glance. @@ -15,8 +15,12 @@ def name_of_function(passed_variable): The contents of the function is always indented to show that it belongs to the function definition above it. Python then knows that this is the local scope of that function and looks there first for any variables, functions or data you might be trying to use in the function. The passed_variable placeholder can be one or more variables that are passed to the function so they can be used. These are known as function arguments, and are how we can move data between one function and another. !!! hint - Understanding how data moves between functions is an important part of programming, as side effects can happen when you don't know what's happening behind the scenes. Make sure you feel solid with the next concepts as they can change depending on the programming language and is the starting point for reducing bugs in code and secure programming. + Understanding how data moves between functions is an important part of programming as side effects can happen when you don't know what's happening behind the scenes. Make sure you feel solid with the next concepts in passing by value and reference as they can change depending on the programming language and is the starting point for reducing bugs in code and understanding secure programming. ## Passing-by-value and Passing-by-reference -These concepts are two different ways we pass variables to functions in programming. When we pass a value by reference +These concepts are two different ways we pass variables to functions in programming. When we pass a value by reference we are essentially passing the actual variable to the function and when we pass by value we are copying the value of the variable and passing the copy to the function. Once the function has done what it needs to do, the pass by value variable is then discarded, this is also called a pure function. The best way to program to ensure less bugs is to only programming using pure functions, but sometimes there is need to program using pass by reference and modifying functions. For a more in-depth look at how passing by reference and value work, take a look at this C++ code: +{{ code_from_file("functions/user-functions/example-pass-by.cpp", flavor="c++") }} + +!!! example + In this example you can see that, apart from all the C++ shenanigans, that there isn't a huge difference from python. There are still function definitions and there is still a part where the main program is run. In the function definitions we can see that there is two functions declared, one called pass_by_value and the other pass_by_reference. As the code runs we can see that diff --git a/docs/functions/user-functions/example-pass-by.cpp b/docs/functions/user-functions/example-pass-by.cpp index 9ec94a2..cbd5557 100644 --- a/docs/functions/user-functions/example-pass-by.cpp +++ b/docs/functions/user-functions/example-pass-by.cpp @@ -1,7 +1,7 @@ #include using namespace std; -// C++ prototypes +// C++ prototypes, not technically required here but old habits... void pass_by_reference(int &var_1); void pass_by_value(int var_1); diff --git a/mkdocs.yml b/mkdocs.yml index 934643f..dd9c8e1 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -35,7 +35,7 @@ nav: markdown_extensions: - admonition ## see: https://squidfunk.github.io/mkdocs-material/extensions/admonition/ for usage - codehilite: - linenums: false ## For line numbers in code blocks, true/false toggle + linenums: False ## For line numbers in code blocks, true/false toggle # - footnotes # - meta