General Coding Flashcards
Statically Typed Languages
The type of variable is known at compile time.
- You must declare the type of each variable explicitly and the type info is checked during compilation
Ex: Java, C++, C#, Swift, Rust, Go
Pros: Static Typed Languages
- Type checking: reduces runtime errors and improves code reliability
- Performance: Leads to optimizations during compilation
- Clarity
Dynamically Typed Languages
The type of variable is determined at runtime.
- You don’t need to declare types explicitly. The language inverse the type based on value assigned
Ex: Python, JS, Ruby
Pros: Dynamic Typed Languages
- Flexibility: variable types can at runtime
- Less boilerplate
- Ease of use
Weakly Typed Languages
More flexible approach to type conversions, often performing implicit conversions between types
Languages: JS, PHP
Ex: implicit conversion of number to string
Let number = 10
let text = “the number is “ + number
Compile Time
A programs source code is translated into machine code/executable code
- Before the program is executed
Compiler checks for
1. Syntax and type checking which must be resolved before the program can run
2. Optimization
3. Code generation (executable code or byte code from the source code which is then ready to be executed by computer)
Runtime
When a compiled program is actually executed by the computer
- When a programs code is run and the program interacts with user
Key Characteristics
1. Programs instructions are executed by the CPU
2. Dynamic behavior occurs like memory allocation, dynamic typing, user input handling. Errors not caught at compile time are found here
Source file
Contains human readable code written in a programming language
- The starting point for creating executable programs or other outputs
when to source your env
When you want to load environment variables from it into your current shell session before running your application
- Node js projects usually use dotenv package which automatically loads in variables from env file
- Go Projects usually require manually sourcing the .env file or using a package like godotenv to load environment variables.
What is Node.js
a JS runtime built on Chromes V8 JS engine
- allows devs to run JS code on the server side (outside of a web browser)
- Known for its nonblocking event driven architecture
Key features of Node.js
- Async and event driven: uses an event driven model which makes it lightweight and efficient. Useful for building real time applications that require high throughput
- Single threaded: handles multiple connections concurrently. This avoids the overhead of creating multiple threads for each connection
- NPM: comes with this
- Cross platform: can run on various operating systems like windows, macOS and linux
- Built in modules: provides rich set of built in modules for performing common tasks
NPM
Largest ecosystem of open source libraries and packages
- allows for devs to easily manage and share reusable code
Chromes V8 JS Engine
An open source JS engine developed by Google
- Is used in the chrome web browser to execute JS code
- Compiles JS directly to native machine code which makes it very fast
How Node.js works
JS execution
- node.js uses the V8 engine to execute JS code. The V8 engine then compiles JS to machine code which is then executed by the computers processor
Client side Javascript
Environment: Runs in the Web browser
Use cases:
- user interface interactions like manipulating the DOM
- Event handling
- Form validation