Showing posts with label basics. Show all posts
Showing posts with label basics. Show all posts

Wednesday, January 1, 2014

Data Compression

Data compression is the process of reducing size of a data file. Compression can be either lossy or lossless. In lossless the bits are reduced by identifying and eliminating statistical redundancy. Lossy compression removes unnecessary information. 

HTTP compression (wiki)
HTTP data is compressed before it is sent from the server: compliant browsers will announce what methods are supported to the server before downloading the correct format. The most common compression schemes include gzip and Deflate

GZip vs Deflate
GZip is simply deflate with checksum and header/footer. Deflate is faster. SO - Why use deflate instead of gzip for text files served by Apache?

Resources
Data compression - wikipedia
http://www.fastly.com/blog/best-practices-for-using-the-vary-header/



What is a Compiler

A compiler is a computer program which transforms source code written in a programming language to another computer language. Usually compilers transforms source code of a high level programming language to a low level programming language. 

Transpiler
Type of compiler that takes source code of a programming language and converts into another language.

Following images shows steps happening in the compilation process

image credit: nocookie.net

Interpreter

Directly executes source code without firstly compiling into a machine language program.

Name Binding

Association of  entities with identifiers. Binding is connected is scope, as scope determines which names bind to which objects. 

Early/Static Binding
Method is bound at compile time. If a suitable method does not exist, an error will occur. 

Late/Dynamic/Virtual Binding
Binding happens at run time.

Dynamic dispatch is process of selecting which implementation of a polymorphic operation (method or function) to call at run time.

Resources


Types of Programming Languages

Dynamic Languages 

Dynamic languages do their work at run time. They do checking at run time. Scripting languages are also dynamic languages.

To understand dynamic languages (wiki) you should know what is static and late binding are.  In Static binding method is bound at compile time. If a suitable method does not exist at compile time, it'll give an error.

E.g: 
  • ActionScript
  • JavaScript
  • Clojure
  • Objective-C
  • Perl
  • PHP
  • Python
  • Java (using reflection)
Prior to C# 4.0, C# was not a dynamic language, but with C# 4.0, it's main focus was to have interoperability with partially or fully dynamically typed languages and frameworks such as Dynamic Language Runtime and COM. 

Dynamic Language Runtime (DLR) runs on top of CLR provides services to different dynamic languages. (note that dynamic == DLR). See Dynamic Programming in .NET (MSDN)

What's so appealing about dynamic languages

Static Languages

Types of variables are known at compile time. They allow IDEs and compilers to detect programmer errors as early as possible.

https://www.google.com/search?q=static+languages&ie=utf-8&oe=utf-8


Assembly language

Is a low level programming language in which there is a strong relationship between the language instructions and machine code instructions. Assembly languages are specific to computer architectures whereas high level languages are portable across architectures (but require compiling)

Assembly language (wiki)

Concurrent

http://programmers.stackexchange.com/questions/121128/modern-programming-language-with-intuitive-concurrent-programming-abstractions
http://en.wikipedia.org/wiki/Concurrent_computing

Declarative

Is a programming paradigm, which describes logic of computations without describing its control flow. 

E.g: database query languages, regular expressions, functional programming, etc.

Functional

It is a part of declarative programming paradigm. 

Imperative

Describes computation in terms of statements that change a program state.  
http://en.wikipedia.org/wiki/Imperative_programming

Aspect oriented programming

Aims to increase modularity by allowing the separation of cross cutting concerns. 
 

Multi-paradigm

http://en.wikipedia.org/wiki/Comparison_of_multi-paradigm_programming_languages

Object oriented

based on objects

Procedural

Instructions about what to do step by step.
https://www.google.com/search?q=procedural+language&ie=utf-8&oe=utf-8

Scripting

Dynamic language
https://www.google.com/search?q=scripting+language&ie=utf-8&oe=utf-8

XML based

Wednesday, December 14, 2011

Memory Basics : Stack and Heap

Stack and heap are closely related with memory. Actually both are stored in computers RAM. Let's firstly look at what they are.

The Stack

Is a special region of the computer memory which holds temporary variables created by each function. This is managed and optimized by the CPU itself therefore you don't have to worry about allocating memory or anything as such. 

When you enter a function the variables defined inside the function will be pushed into the stack and when you exit the function the variables will be cleared from the stack. 

The stack is always reserved in LIFO (last in first out order). The stack is set aside for a thread. Each thread gets a stack.

 
Understanding stack in  JavaScript (blog article)

In JavaScript sometimes you'll encounter Maximum call stack exceeded in JavaScript error. This happens when you exceed the  call stack size in JavaScript. You can replicate this with a simple code like below



The Heap

Is the memory set aside for dynamic allocation. Unlike stack there is no pattern for allocation or deallocation of blocks from the heap. You must manually destroy variables on the heap. 

Heap can have fragmentation when there are lot of allocations and deallocations happening. Heap is usually responsible for memory leaks as well. 

In .NET unless you're building a compiler, knowing how stack and heap works is not needed much. (Stack vs. Heap in .NET - Stackoverflow).

Resources

Tuesday, November 30, 2010

Algorithms every software developer must know

Basics in algorithms

What is Big O notation? (link Stackoverflow)
It is relative representation of the complexity of an algorithm

Sorting Algorithms

Sorting algorithms are often classified by
  • Computational complexity 
    • of elements in terms of the list size
    • of swaps
  •  Memory usage
  • Recursion
  • Stability
  • Adaptability

Popular sorting algorithms

Simple sorts : Insertion sort, Selection sort
Efficient sort: Merge sort, Heap sort, Quick sort
Bubble sort


Resources

http://stackoverflow.com/questions/33923/what-is-tail-recursion
http://stackoverflow.com/questions/tagged/algorithm

Saturday, September 11, 2010

Principles in Software Development

When designing a software there are various principle you should follow 
to make the software better in different aspects. 
In this article we'll go through some of those principles.

Principle of least astonishment

Basically you should not astonish people when it comes to implementing something. For example if you have a method toString() which returns a string "not implemented", it is breaking of least astonishment principle. 

see wikipedia and Programmers - StackExchange 

Cargo cult programming
inclusion of a code or program which does not have any real purpose
wikipedia, Programmers SO 

GRASP

Consists of guidelines for assigning responsibility to classes and objects.  See this wikipedia article and this.

KISS (Keep it simple stupid)

States most systems works best if they are kept simple rather than complicating. Therefore simplicity should be a key goal in designing a system.

YAGNI (You aren't gonna need it)

It's a principle of Extreme Programming. It states that programmer should not add functionality unless deemed necessary. See wikipedia.


Other

Having a good software design is important to avoid bad design which will cause us very badly. According to Robert martin there a 3 things we must avoid when designing software.
  • Ridiglity : It's hard to change because changes affects too many other parts of the system
    • every change causes a cascade of subsequent changes in dependent modules. Can grow 2 day work to multiple weeks
  • Fragility : When you do a change, unexpected parts of the system breaks. Has a close connection with Ridiglity.
  • Immobility: It is hard to reuse component in another area of the application.
  • covariance and contravariance
Memoization 
In computing, memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.

source
Memoization in JavaScript


https://www.cs.utexas.edu/~scottm/cs307/handouts/deepCopying.htm

Saturday, May 1, 2010

Introduction to Testing


Testing is a mechanism we use to evaluate whether the software we are developing satisfies the specified requirements. Testing is a very broad subject. Here we'll just look in to some high level overview of what it is.


Types of testing

  • Manual testing
    • Takes the role of an end user and checks for unexpected behavior 
    • There are few levels like unit testing, integration testing, system testing and user acceptance testing
    • Uses test plan, test cases or test scenarios to test
  • Automation testing
    • Also known as Test Automation
    • Testers writes scripts and use other software to do testing
    • Rerun test scenarios quickly and repeatedly
    • Use tools like Selenium, VS Test Professional, IBM Rationale function tester

Testing methods

  • Black box 
    • Without having any knowledge of interior workings of the application (UI level)
  • White box
    • Detailed investigation of internal logic
  • Grey box
    • Testing with limited knowledg

Tuesday, December 22, 2009

Object Oriented Concepts Every Dummy Must Know

Abstraction
  • Abstraction is Only showing what is necessary and encapsulating (hiding) unnecessary parts. 
    • If you take a car you interact with it using abstractions 
      • you use gas pedal, steering wheel which hides internal details
  • It is keeping a clear separation between abstract properties of a data type and the concrete details of its implementation. 
  • It is not presenting the details but only show the parts which are necessary.  
  • Hiding implementation 
To abstract properties we can use private modifier. Abstraction is hiding implementation details using abstract classes and interfaces.


Encapsulation
  • Hiding state/data. Information hiding mechanism
  • It is the opposite of Abstraction.  
http://stackoverflow.com/questions/24626/abstraction-vs-information-hiding-vs-encapsulation
https://www.google.com/search?q=encapsulation+vs+abstraction&ie=utf-8&oe=utf-8
http://stackoverflow.com/questions/742341/difference-between-abstraction-and-encapsulation

Composition : Combining simple types to make a complex type (Car composed of Wheels, Body etc.). An object of a composite type "has an" object of a simple type.


Aggregation : (See composition vs aggregation - adobe)

Is a form of object composition.

Inheritance : When an object or class based on another object or class. 

Inheritance is "is a" relationship while, composition is "has a" relationship

Articles

  • inheritance defined statically at compile time.
  • object composition defined dynamically at run time, through objects acquiring references to other objects
  • inheritance : reuse by subclassing : white box reuse (internals of parent are visible)
  • composition : well defined interfaces: black box reuse (no internal objects are visible)



updated: 2014

Saturday, July 11, 2009

SOLID Principles

SOLID is acronym used for 5 design principles for object oriented programming. Below we'll look at what they are

Single Responsibility principle

Every class should have only one responsibility. This responsibility should be totally encapsulated by the class.


Open/Closed principle

Software entities should be open for extension, but closed for modification. This is valuable when it comes to production environments where changes to existing code may require code reviews, unit tests etc. which ensures the quality of the product. In design, inheritance is used to achieve open/closed principle. 

see wikipedia, OODesign, Objectmentor,

Liskov Substitution principle

Derived types must be completely substitutable for their base types.

see OODesign,

Interface segregation principle 

Client should not be forced to depend upon interfaces that they don't use

Dependency Inversion principle

High-level modules should not depend on low-level modules.


Wednesday, July 1, 2009

Exception handling basics

Exceptions happens when a member cannot successfully do what it's designed to do. Exceptions can be generated by CLR, 3rd party library or by user code using throw keyword.


A catch block can specify type of exception to catch. This is called exception filter. The exception type should derive from Exception. In general do not specify Exception as the exception filter.

Inside the catch block you can either return a value or throw an exception depending on the situation you're in. (When to throw an exception). Difference between throw and throw ex.

A finally block enables you to clean up actions that are performed in try block. A finally block always runs, regardless of exception is happen. Note that sometimes finally block will throw exceptions as well.


Exceptions contains a property called StackTrace. It contains names of the methods in current call stack, together with file name and line number where exception was thrown for each method. You can use Environment.StackTrace to get stack trace information when no exception is being thrown.

Sometimes you shouldn't throw exceptions. See cost of exceptions and this (SO)

Some common exceptions in .NET

NotImplementedException (msdn)
See Why does NotImplementedException exists - SO

Handling business logic in exceptions
http://stackoverflow.com/questions/5378005/when-is-it-ok-to-use-exception-handling-for-business-logic
http://programmers.stackexchange.com/questions/15570/representing-business-rules-with-exceptions

Exceptions you should not throw (SO)
Since they doesn't give any meaningful information when writing your own code you should not throw,

  • Exception
  • SystemException
  • NullReferenceException and IndexOutOfRangeException are fine





ResourcesUnhandled Exception Processing In The CLR
Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook