WIN213 Week 3 Lecture 1 - Variables PDF

Title WIN213 Week 3 Lecture 1 - Variables
Course Introduction to Scripting and PowerShell
Institution Seneca College
Pages 4
File Size 69.8 KB
File Type PDF
Total Downloads 6
Total Views 150

Summary

This document contains notes from WIN213 Week 3 Lecture 1. Topics include Variables and Scripting vs. Programming....


Description

WIN213 Week 3 Lecture 1

Why would you write a program? Efficiency: faster, easier, automated How flexible does it need to be? Multi-platform is one kind of flexibility Hardware-specific, OS-specific program writing isn’t ideal – programmer time is expensive Patches, updates, are lengthy Firstly you’d want to write a robust, reliable, self-healing/adaptive, scalable application Databases = create, read, update and delete (CRUD) Program asks database: “What are you selling?” adaptively changing the data as soon as the database is updated (Selling men’s shoes AND women’s shoes) Planning (designing) is 80% of writing your application Maintaining efficiency Designing a network, designing machine deployment – better administrators

Variables are one of the key components to make your application versatile SCRIPTS VS. COMPILED PROGRAMS *** GONNA BE ON THE QUIZ Interpreted languages (classic Shell) vs. Compiled languages (classic C) There is no such thing as a better programming language Knowing the best tool for the right job Compiled language – intense computational work/run-time reliability Interpreted language – (will never be fast) but got direct access to Windows API through WMF and .NET Administer tens of thousands of machines at the same time it takes to admin one of them, from a single workstation -- the priority here is my time (operational speed), if I have to tweak it, it takes minutes, not days or weeks Java is right in the middle between compiled and interpreted – portable Python is an interpreted language – flexibility (do a lot of things very easily) Windows direct API: powerful access to the core Input -> Processing -> Output

In Windows, differently from Unix, some things are files, some things are directories // Kantian “as if” // ;prop table; Planning: 1 – What is my program supposed to do? (Return dog years) 2 – What do I need to know? (user age, math, user input, output) 3 – Untaint data, sanity check

“Is this a problem I can solve using this language?” Programs… mundane, repetitive crap

Three categories of variables Automatic/Environment variables: read-only (e.g. PSVersion) Preference variables: read-write (e.g. I want to use VI as my default editor) User-defined variables

Automatic variables $? = error status $_ = default data container $ARGS = array (multiple data stored in index positions) – fixed-size array vs. dynamic memory allocat. // buffer overflow attacks //

$env:path = complex object with many variables inside it Namespaces, last names and first names (env:x, db:x, :x) + = concatenation for strings Char + ______ = adds “______” to “char” Echo $name + 10 = bob + 10 $name + 10 = bob10 $name=2 (will treat 2 as a numeral (string) instead of a number because it was not declared

“If you don’t tell me what variable type it is, I’ll treat it as a string, unless you give me something that I can use to treat it as something else” $name + 10 = 12 DECLARE YOUR VARIABLES [int] $name = ‘bob’ Strings are not numbers [int] $name = 1.23 $name = 1 [bool] $name = 1 SINGLE QUOTES ARE STRING OPERATORS [bool] $name = 10 $name + 12 = 13 $name = True 0 = false, 1 = true In Perl, all strings and non-zero values are true, including ‘0’.

camelCase = pseudohungarian naming conventions Syntax, grammar, vocabulary and conventions No cryptic var names ($firstName instead of $fName) Be consistent! Don’t use special variables

cd Env: (environment = directory) cd hcku: (hive = directory) Get-VirtualDisk

Mathematical Operations 12 % 3 = 0 13 % 3 = 1

4%9=4 9%9=0 10 % 9 = 1 19 % 9 = 1 $x (row count) % 25 = 0; pause

$num2 = 2 $num1 = $num2 $num1 = 2 $num2 = 4 $num1 = 2 It fixes value at the time of assignment

[Math]::sqrt(64) The difference between class and objects is that classes create objects and objects are inherited from classes In the super-class .NET, there is a child called [Math] whose object’s attributes are sqrt, pow, round etc Get-Random –Minimum 1 –Maximum 100 No such thing as a genuine random number Always comes from a parameter...


Similar Free PDFs