Skip to content

2024 Codestak Learning#

Polyglot Programming.

C#

C Fundamentals
  • What's known as a Mid-level-language
  • Memory Management

  • Functions

    • Procedures
    • Methods
    • Subroutines
  • Variables and Scope
    • Scope is a characteristic of a variable that defines from which functions that variable may be accessed.
      • Local Variables
      • Can only be accessed whithin the functions in which they are created.
      • Global Variables
      • Can be accessed by any function in the program.
  • Arrays
  • Algorithms
  • Memory
  • Data Structures
  • Command Line Arguments

  • Pointers

    • Pointers are a fundamental concept in the C programming language, allowing you to work with memory addresses and manipulate data indirectly. They are powerful tools for efficient memory management and data manipulation, but they can also introduce complexity and potential pitfalls.

Here's a basic overview of pointers in C:

  1. Memory Address and Pointers:

    • A memory address is a location in the computer's memory where data is stored.
    • A pointer is a variable that holds the memory address of another variable. It "points" to the memory location where the actual data is stored.
  2. Declaring and Initializing Pointers:

    • To declare a pointer, you use an asterisk (*) before the variable name. For example: int *ptr;.
    • Pointers should be initialized before they are used. You can initialize a pointer with the address of an existing variable: int *ptr = &variable;.
  3. Accessing Pointer Value and Referenced Value:

    • The value of a pointer is the memory address it holds. You can access it using the pointer variable itself: printf("%p", ptr);.
    • To access the value stored at the memory address pointed to by a pointer, you use the dereference operator (*) followed by the pointer variable: int x = *ptr;.
  4. Pointer Arithmetic:

    • C allows arithmetic operations on pointers, which is useful for navigating through arrays and memory blocks.
    • Incrementing a pointer moves it to the next memory location of the pointed type: ptr++;.
    • Decrementing a pointer moves it to the previous memory location: ptr--;.
  5. Dynamic Memory Allocation:

    • C allows you to dynamically allocate memory using functions like malloc, calloc, and realloc. These functions return a pointer to the allocated memory.
    • You must manage the allocated memory and free it using the free function to prevent memory leaks.
  6. Passing Pointers to Functions:

    • Pointers are often used to pass data by reference to functions, allowing functions to modify the original data.
    • The receiving function must declare its parameter as a pointer to the appropriate type.
  7. Pointer to Pointers (Double Pointers):

    • You can have pointers that point to other pointers. These are used for more complex data structures like dynamic arrays and matrices.
  8. Null Pointers:

    • A null pointer points to no memory location. It is often used to indicate that a pointer is not pointing to a valid address.
    • Assigning a pointer to NULL is a good practice after freeing the memory it points to.
  9. Pointer and Arrays:

    • Arrays and pointers are closely related in C. In many cases, the name of an array behaves like a pointer to the first element of the array.
    • For example, int arr[5]; int *ptr = arr; sets ptr to point to the first element of arr.

Remember that improper use of pointers can lead to memory-related bugs like segmentation faults, memory leaks, and undefined behavior. Careful and proper handling of pointers is crucial for writing reliable and efficient C programs.

  • Debugging

Python#

Threading vs Mulitprocessing in Python

Speed Test of Multiprocessing Function Operations (N) in Python Using an 8-Core 16-Thread CPU (Test Concluded in Summary)

  • Python is Multithreaded
  • It is concurrent but not parallel.
  • CPython implementation will consider switching threads every 15ms or when an I/O operation is encountered.

  • Multi-threading does not strictly mean single core

  • The OS may switch the Python process between physical and virtual CPU cores!

  • Multiprocessing is the standard Python way to increase processing power if needed (it's part of the Python library).

  • Most numerical libraries (NumPy, SciPy, TensorFlow) are simultaneously multi-threaded behind the scenes, so you won't necessarily get any speed increase when using multiprocessing.

Not covered in the test, but things to watch out for:

  • Since threading allows processing data to be accessed, data may need to be protected with Lock(). Locks ensure that if a thread is interrupted halfway through changing or accessing some data, another thread cannot modify it during that interruption. For example, if some data was updated by several write operations, reading an intermediate value could return nonsense. Locks can be used to protect these operations.

  • Pipe() may become corrupted if accessed simultaneously.

  • It is NOT thread safe.

  • Queue() can be accessed by multiple users.

  • It is thread and process safe. However, Queue can be more costly to set up than a Pipe, so use the one more appropriate for your application.

  • CPU-limited tasks would benefit from multiprocessing.

  • I/O-bound tasks would benefit from threading.

How to use all your CPU cores in Python?

Due to the Global Interpreter Lock (GIL) in Python, threads don't really get much use of your CPU cores. Instead, use multiprocessing! Process pools are beginner-friendly but also quite performant in many situations.

  • Extraction
  • Transformation
  • Load (Store new Form)

JavaScript#

JavaScript

GO#

A Tour of GO

Built for Concurrency and Multiprocessing. - Latest Version Update - go1.2.1: As a result of runtime-internal garbage collection tuning, applications may experience up to a 40% reduction in application tail latency and a slight decrease in memory usage.

Named return values - 7/17()

Go's return values may be named. If so, they are treated as variables defined at the top of the function.

These names should be used to document the meaning of the return values.

A return statement without arguments returns the named return values. This is known as a "naked" return.

Naked return statements should be used only in short functions, as with the example shown here. They can harm readability in longer functions.

   package main

   import "fmt"

   func split(sum int) (x, y int) {
      x = sum * 4 / 9
      y = sum - x
      return
   }

   func main() {
      fmt.Println(split(17))
   }

## A more detailed breakdown of the function:

func split(sum int) (x, y int) {
   x = sum * 4 / 9
   y = sum - x
   return
}
  1. Function Declaration:

    func split(sum int) (x, y int) {
    
    - func: Keyword indicating the declaration of a function. - split: Name of the function. - (sum int): Input parameter of the function, an integer named sum. - (x, y int): Return values of the function, both integers named x and y.

  2. Calculation of x:

    x = sum * 4 / 9
    
    - x: Variable used to store the calculated value. - sum * 4 / 9: The input sum is multiplied by 4 and then divided by 9. The result of this calculation is assigned to the variable x.

  3. Calculation of y:

    y = sum - x
    
    - y: Variable used to store the calculated value. - sum - x: The value of x (calculated previously) is subtracted from the input sum, and the result is assigned to the variable y.

  4. Return Statement:

    return
    
    - The return statement doesn't explicitly provide return values. However, due to the function's signature (x, y int) specifying the return values as x and y, the values stored in these variables are automatically returned.

In essence, this function takes an integer sum as input, calculates two values (x and y) based on the input, and returns them. The value of x is obtained by performing a mathematical operation on the input, while the value of y is derived from the difference between the input and x. The function's structure uses named return values, which allows the function to automatically return the values assigned to x and y.

BASH#

BASH

SQL#

SQL

C++#

C++ Fundamentals

Java#

C# Fundamentals

Documentation By: Raymond C. TURNER

Revision: March 24th, 2024