Quick Notes: Python

Main Notes

  • Philosophy: “There should be one obvious way to do one thing.”
  • Zen of Programming:
    • Beautiful is better than Ugly
    • Explicit is better than Implict
    • Simple is better than Complex
    • Complex is better than Complicated
    • Readability Counts
  • Multi-Paradigm Language

Variables

  • Variables hold value by reference, and are called “names” instead of variables.
  • Variables are dynamic, meaning the same variable can be set to different types.
  • Comparisons are done with values but can be done with references as well.
  • Variable Unpacking: multiple variables can be set in one expression.

Data Structures

def foo(a,b,c):
  baz = a + b + c
  print(baz)
bar = [1,2,3]
foo(*bar) #prints 6

The tuple bar is unpacked to the function foo as bar by itself would give a type error.
(GeeksforGeeks: Packing and Unpacking Arguments For Python)

Functions

  • All functions return a value.

Syntax

  • Python just has one way to write comments, with the # character preceding the comment, not working in strings.
  • Blocks are delimited by white space characters instead of parenthesis.
  • Quote (‘) and double quote (“) can be used interchangeably, triple quotes denotes multi-line strings.

(Wikipedia: Python (programming language))
(Microsoft | Vistual Studio Docs: Python In Visual Studio)

Quick Notes: Javascript

Main Notes

  • Used for dynamic content, to manipulate the DOM on web pages
  • Mostly known to function “client-side” but there are other implementations.
  • Run-Time Environment is on web browsers.
  • Supported by pretty much all browsers.
  • Multi-Paradigm
  • Mostly Object-Oriented

Other Notes

  • Uses html to include other scripts.
  • No natural facilities for input/output, networking, and storage but uses these services from the host environment.
  • console.log() used for output usually.
  • Hoisting: function and variable definitions are moved to the top of their scope before code execution. (1)
  • Hoisting only applies to var and function, not let and const. (2)
  • Semicolons are optional.(3)

1. Scotch: Understanding Hoisting in JavaScript by Mabishi Wakio
2. Don’t Use JavaScript Variables Without Knowing Temporal Dead Zone by Dmitri Pavlutin
3. Semicolons in JavaScript by Flavio Copes

Variables

  • Keyword ‘var’: function scope, re-assignable.
  • Keyword ‘let’: block scope, re-assignable.
  • Keyword ‘const’: block scope, not re-assignable.
  • variables 0, empty strings, undefined and null are equal to boolean false.

(Digital Ocean: Understanding Variables, Scope, and Hoisting in JavaScript )

Functions

  • When a function is called as a method on an object, the object is set as a local variable keyword “this”.
  • Function arguments are set in the local variable array “arguments”.
  • Function parameters are optional where they are set to undefined or set in the function itself.

Objects

  • Built in objects: Date, Function, Regex, etc.
  • Uses prototypes for inheritance.

(Wikipedia: Javascript)

Define: Programming Overview

Terms: Programming Paradigm, Object Oriented Programming, Functional Programming, Structured Programming

Languages, Libraries, etc: Java, C, C++, jQuery, HTML, XML, SQL, PHP, Node.js, WordPress, CMS, API, cURL, AJAX, Lisp, PERL.

Some of these terms may deserve their own page. I will need a common methodology in comparing these languages such as what’s different between them, what’s similar, and their general structures.

Programming Paradigm

A way of thinking of software production based on fundamental, defining principles. (1)

Object Oriented Programming

  • Data structures and functions have defined data types.
  • Objects are data structures with functions that operate with that specific object.
  • Objects may have relationships with each-other such as inheriting functions and variables.

(webopedia: OOP)

Functional Programming

  • “Declarative” instead of “Imperative”. (1)
  • Avoids shared state, mutable data, and side-effects. (1)
  • Focus on “what to solve” instead of “how to solve”. (2)
  • Expressions instead of statements. Expressions are evaluated to produce a value. (2)
  • Uses Pure Functions. Given the same input, always return the same output. Has no side-effects. (1)

Sources and References

(1. Medium: Master the JavaScript Interview: What is Functional Programming?)
(2. GeeksforGeeks: Functional Programming Paradigm)

Programming Language Reference

I recall this thing a professor said or this thing I read on the internet. They had a folder of “hello world” programs written in different languages. This sounded useful as you might have to write in a different language and these files might be good reference. I won’t be including these programs themselves here but I may make a post of notes that I make when making them.

In addition to these programs, I’d try to include a few of the unique or complex features/quirks of the language and note notable applications of the language.

As I learn python and review languages I haven’t used in while, here is a list of the languages I’ll make these programs for.

  • Python, Java, C, C++, C#
  • PHP, Javascript, HTML

Creating a Batch Script

Making a post in creating a fairly simple batch script. I wanted the script to create an html gallery of images files that are stored locally.

  • The ‘dir’ command.
  • The ‘for’ command had an issue with file paths that had spaces, the filter “tokens=*” made the ‘for’ command read the entire path instead of stopping at the first space.
  • I couldn’t find much documentation of directing output to ‘for’ commands but an option was to place the command in the ‘set’ portion of the ‘for’ command.
  • Looping through text (stackoverflow)
  • In a batch script, % needed to be changed to %%.
  • Comments are made using “::” and “rem” before the comment, I haven’t looked into multi line comments.
  • ‘If’ statements aren’t very different from ‘if’ statements in other languages. There is a comparison statement after the ‘if’. Parenthesis can be used to group commands and we can attach an ‘else’ statement.

The ‘if’ command.

I’ll be looking up how I make this script more accessible either by making a command in the command prompt (not certain if this is doable) or by making it open that window that lets you choose a folder or a text window to paste a folder’s path.

I’ve read that powershell has more functionality over command prompt and I’d look into it should I need something more complex.

A potential function to the gallery is the ability to “toggle” images between max-size and “compact” size, possibly via toggable classes.

The command prompt naturally isn’t able to sort numerically as it does alphabetically. There are solutions out there for this. One solution might be to rename files such that they have the same amount of characters (eg. 1 -> 01).

References and Sources

Development Tools
Visual Studio Code – a lightweight IDE, I thought I was using the IDE below.
Microsoft Visual Studio – I’ll be using this to do substantial programming for now.
ItelliJ IDEA – an alternative IDE that’s good too.
XAMPP – for development needing your own http server, there are better alternatives it looks such as Laravel Homestead and a number of others.

Online Tools
https://www.diffchecker.comFound that MVS could find differences itself.
https://regex101.com – tool to check regular expressions.
https://jsfiddle.net – great tool to test javascript.

Information/Reference Sites
https://www.w3schools.com
https://developer.mozilla.org – reference for web languages and more.
https://www.tutorialsteacher.com – appears quite similar to w3schools, not used personally as of yet
https://noobtuts.com – didn’t look through it much, might be informational.
https://www.geeksforgeeks.org
https://www.tutorialspoint.com

Language/Library Specific
https://www.python.org
https://api.jquery.com

Questions and Answers Sites
StackOverflow: Widely known and used question and answer site for programmers.
Quora: May provide personalized answers about certain products and services.
Reddit: May provide a good reference for public opinion about products and services.

Learning Resource
https://www.codecademy.com – I haven’t gotten to learning anything from here yet, but it looks promising.

A few comments on the above
StackOverflow can be unfriendly at times. There are some faults towards how it handles its content but it can still be a great resource. I strongly recommend to carefully read the rules, look up if your question has been answered previously, provide as much detail as you can in your question, and to attempt to answer/solve your question to show that you have put in your own time and work.

Visual Studio Code Extensions
GitHub: Bracket Pair Colorizer by CoenraadS
GitHub: Indented Block Highlighting by byi8220
– Makes it easier to identify the code block that you are on.
GitHub: Bookmarks by Alessandro Fragnani
– Marks points within a code.

Define: Linux, Unix, Command Prompt

Terms: Unix, Linux, Kernel, POSIX, Command Prompt, PowerShell, Web API.

A number of terms and phrases that I’ve heard of and probably used but haven’t clearly defined them for myself. I expect to make multiple posts looking up definitions for a number of terms. A wiki would help in sorting these terms should I ever decide to make one.

I want to summarize just the important points.

Unsorted
Command Line, Web API.

Unix

  • A type of operating system that includes a number of modern operating systems.
  • Small, modular utilities that do one thing and that one thing well.
  • “everything is a file”, everything such as resources and functions, are treated, organized, and accessed like files.
  • The other major type is Microsoft’s Windows NT-based OS.

(HTG)

Linux
A kernel. A Unix clone written by Linus Torvalds and people across the net. Free open-source and “aims towards POSIX compliance.” (nixcraft)

Kernel
A program that serves as the core of a operating system. One of first programs to load after the bootloader. (Wikipedia)

POSIX
IEEE standard for compatibility and portability between operating systems. Not just for UNIX systems. (Linux Hint)

Command Prompt
“Default command line interface provided by Microsoft”(maketecheasier)

Web API
I’ll look up definitions at a later date, this post will just reference them for now.