<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aashetty</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aashetty"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Aashetty"/>
	<updated>2026-06-03T12:17:46Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92398</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92398"/>
		<updated>2014-12-04T02:01:09Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository [https://github.com/ankit3005/servo]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
Once the new image library was imported , passed in several test images to record the decoding timing for different images.&lt;br /&gt;
The timing was compared with the decoding time for images by passing in the same images to the servo build containing the C image library.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92397</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92397"/>
		<updated>2014-12-04T01:57:11Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Implementation of the Final Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Implementation of the Final Requirements ==&lt;br /&gt;
&lt;br /&gt;
1. Add Image Decoding time to the Profiler&lt;br /&gt;
To profile the time required by the load_from_memory to decode an image, we make a call to the profiler which outputs the time taken to decode on the console. To enable the profiler to do so, the following files were changed:&lt;br /&gt;
*image_cache_task.rs&lt;br /&gt;
*lib.rs&lt;br /&gt;
*time.rs&lt;br /&gt;
To invoke the profiler, we added a category under which to group the timings and passed a TimeProfilerChan (ie. a channel for communicating with the profiler task) to the ImageCacheTask::new method. On successfully building and running servo, we get the following image timings by profiler on the console:&lt;br /&gt;
&amp;lt;pre&amp;gt; ./mach run -p 1 https://optipng.sourceforge.net/pngtech/img/lena.html &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:Profiler.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Imported the freetype-rs library to replace rust-freetype in Servo.&lt;br /&gt;
We replaced the currently used rust-freetype library with the freetype-rs library. To enable proper functioning of servo after importing the new library, following files were modified in the repository [https://github.com/PistonDevelopers/freetype-rs PistonDevelopers/freetype-rs]:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*src/ffi.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/lib.rs&lt;br /&gt;
*src/library.rs&lt;br /&gt;
*src/tt_os2.rs&lt;br /&gt;
These changes were committed and have been pulled by PistonDevelopers. Check the changes on [https://github.com/PistonDevelopers/freetype-rs/pull/70 pull request] for more info.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Imported the rust-image library to replace the rust-stb-image and stb-image libraries and rewrite the load_from_memory function which uses these libraries.&lt;br /&gt;
In order to import the new library we modified the following files files in the repository []:&lt;br /&gt;
*Cargo.toml &lt;br /&gt;
*components/net/lib.rs&lt;br /&gt;
*components/net/image_cache_task.rs&lt;br /&gt;
*components/net/image/base.rs&lt;br /&gt;
*components/net/image/holder.rs&lt;br /&gt;
*components/gfx/render_context.rs&lt;br /&gt;
*components/gfx/lib.rs&lt;br /&gt;
*components/gfx/Cargo.toml&lt;br /&gt;
*components/gfx/display_list/mod.rs&lt;br /&gt;
*components/layout/display_list_builder.rs&lt;br /&gt;
*components/layout/lib.rs&lt;br /&gt;
&lt;br /&gt;
4. Reported the timing differences for loading PNGs and non-PNGs on the same benchmarks.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92366</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92366"/>
		<updated>2014-12-03T05:09:37Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
        //Retrieve the ImageFormat enum to be passed into the updated function&lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        //The updated function returns a Result&amp;lt;DynamicImage&amp;gt;&lt;br /&gt;
        //below code resolves it to be returned by the wrapper function&lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92365</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=92365"/>
		<updated>2014-12-03T04:58:52Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Design Principles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa initial step], implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design Principles ==&lt;br /&gt;
&lt;br /&gt;
We are adhering to the following design principles for our implementation:&lt;br /&gt;
&lt;br /&gt;
'''Open-Closed Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Open/closed_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although our task is to evaluate replacing C libraries with Rust libraries, we won't actually be modifying any existing functionality.&lt;br /&gt;
&lt;br /&gt;
'''Interface Segregation Principle'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Interface_segregation_principle&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The existing code is currently using the ''rust-freetype'' library for rendering fonts on the browser. We will be replacing this with the ''freetype-rs'' library, which divides the functionality offered by the former into smaller libraries which can be individually implemented instead of calling the entire library.&lt;br /&gt;
&lt;br /&gt;
== Design Pattern==&lt;br /&gt;
&lt;br /&gt;
We have implemented the Adapter Pattern in our Project:&lt;br /&gt;
&lt;br /&gt;
When we updated the image library, the function load_from_memory() in base.rs had to be updated since the return from the updated function accepts a different set of parameters.&lt;br /&gt;
We implemented the Adapter pattern as a wrapper function over the new load_from_memory() function which performs the below functions:&lt;br /&gt;
1. Based on the file extension generate the ImageFormat Enum.&lt;br /&gt;
2. The return of the new function is a Result&amp;lt;DynamicImage&amp;gt;. This needs to be converted into a DynamicImage struct.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pub fn load_from_memory(buffer: &amp;amp;[u8],ext: &amp;amp;str) -&amp;gt; Option&amp;lt;DynamicImage&amp;gt; {&lt;br /&gt;
    if buffer.len() == 0 {&lt;br /&gt;
        return None;&lt;br /&gt;
    }&lt;br /&gt;
   else {&lt;br /&gt;
	//let new_image_type: servo_image::ImageFormat = servo_image::ImageFormat::PNG;&lt;br /&gt;
   &lt;br /&gt;
        let image_type: Option&amp;lt; servo_image::ImageFormat &amp;gt; = get_format(ext);&lt;br /&gt;
	if image_type == None&lt;br /&gt;
	{&lt;br /&gt;
	panic!(&amp;quot;Image format not supported!&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
	else{&lt;br /&gt;
        let new_image_type: servo_image::ImageFormat = image_type.unwrap();&lt;br /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
	let result = servo_image::load_from_memory(buffer,new_image_type);&lt;br /&gt;
	if result.is_ok() {&lt;br /&gt;
  	    let v = result.unwrap();&lt;br /&gt;
  	    return Some(v);&lt;br /&gt;
	}&lt;br /&gt;
	else  {	&lt;br /&gt;
	    return None;&lt;br /&gt;
	}		&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2014/oss_M1455_asa Initial Step Details]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91816</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91816"/>
		<updated>2014-11-11T23:40:41Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Component Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our initial step, implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;ref&amp;gt;http://doc.rust-lang.org/guide.html#crates-and-modules&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design patterns ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Flowchart describing Project Implementation==&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
===Class Diagram===&lt;br /&gt;
[[File:Class_diagram_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91814</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91814"/>
		<updated>2014-11-11T23:39:26Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Component Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our initial step, implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;ref&amp;gt;http://rustbyexample.com/trait.html&amp;lt;/ref&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design patterns ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91812</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91812"/>
		<updated>2014-11-11T23:37:13Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Data and component design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our initial step, implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/image rust-image] library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the &amp;lt;code&amp;gt;load_from_memory&amp;lt;/code&amp;gt; function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design &amp;lt;ref&amp;gt;http://www.rust-ci.org/PistonDevelopers/piston/doc/image/index.html&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals with is present in the image crate.&lt;br /&gt;
&lt;br /&gt;
The structs and enums used to represent images are as below :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design patterns ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
[[File:Flowchart_final_M1455.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that tasks that could be performed with the older C libraries can be executed.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
# Render different webpages with different fonts. Ensure the text renders correctly&lt;br /&gt;
# Render images of different formats (png, jpeg, bmp, gif) of different resolutions. Ensure that the images are rendered correctly.&lt;br /&gt;
# Record time taken to render and compare against time taken by the older libraries, for both image and text.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91791</id>
		<title>CSC/ECE 517 Fall 2014/final M1455 yaaa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_M1455_yaaa&amp;diff=91791"/>
		<updated>2014-11-11T23:08:25Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* UML diagrams */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This wiki page contains design details for the project on [https://github.com/servo/servo/wiki/Replace-C-libraries-student-project Evaluate replacing C libraries with modern Rust equivalents] for the Mozilla research project [http://github.com/servo/servo/wiki/Design Servo].&lt;br /&gt;
&lt;br /&gt;
== Background Information ==&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
[http://www.rust-lang.org/ Rust] is a new programming language for developing reliable and efficient systems. It is designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
===Servo===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Servo_%28layout_engine%29 Servo] is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. &lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Rust’s lightweight task mechanism promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation. Servo is not designed to create a full browser but is rather focused on creating a reliable and fast browser engine.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo currently depends on a lot of C libraries for image decoding. We wish to evaluate switching some of these to new Rust libraries. This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
====Setup of Development Environment====&lt;br /&gt;
Servo is currently developed on 64bit OS X and 64bit Linux. &lt;br /&gt;
&lt;br /&gt;
The steps needed to build on a Debian based 64 bit Linux machine are included below. The instructions for other platforms are available [https://github.com/servo/servo#prerequisites here].&lt;br /&gt;
&lt;br /&gt;
* Install the prerequisite dependencies&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install curl freeglut3-dev \&lt;br /&gt;
    libfreetype6-dev libgl1-mesa-dri libglib2.0-dev xorg-dev \&lt;br /&gt;
    msttcorefonts gperf g++ cmake python-virtualenv \&lt;br /&gt;
    libssl-dev libglfw-dev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Clone and build servo repository&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&lt;br /&gt;
cd servo&lt;br /&gt;
./mach build&lt;br /&gt;
./mach run tests/html/about-mozilla.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architecture of system &amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Design#task-supervision-diagram&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Task Supervision Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskSupervision.png]]&lt;br /&gt;
&lt;br /&gt;
=== Task Communication Diagram ===&lt;br /&gt;
&lt;br /&gt;
[[File:TaskCommunication.png]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams gives us an overview of the Servo's architecture.&lt;br /&gt;
*Each box represents a Rust task.&lt;br /&gt;
*Primary tasks are the ones which are represented by blue boxes.&lt;br /&gt;
*Gray boxes are for auxiliary tasks.&lt;br /&gt;
*White boxes are for worker tasks. Each such box represents several tasks, the precise number of which are decided by the workload.&lt;br /&gt;
*Supervisor relationships are shown by dashed lines.&lt;br /&gt;
*Communication channels are shown by solid lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The scope of our project is limited to changing the libraries used in the image decoding task shown above.&lt;br /&gt;
&lt;br /&gt;
== Requirement analysis ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents for these libraries did not exist when the project started. Our project is to evaluate switching some of these to new Rust libraries that have since been created. It involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&amp;lt;ref&amp;gt;https://github.com/servo/servo/wiki/Replace-C-libraries-student-project&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Initial step&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our initial step, implemented for the OSS project involved:&lt;br /&gt;
# Building Servo.&lt;br /&gt;
# Adding [http://doc.servo.org/util/time/fn.time.html timing code] to the image decoding implementation in the net crate.&lt;br /&gt;
# Rebuilding Servo.&lt;br /&gt;
# Reporting numbers for different kinds of images (i.e. PNG, JPEG, GIF).&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;b&amp;gt;Final Requirements&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our final project requirements are to:&lt;br /&gt;
* Build Servo and add code that reports (via the println! macro) the time required to decode images into displayable pixels.&lt;br /&gt;
* Add image decoding timing to the profiler.&lt;br /&gt;
* Import the [https://github.com/PistonDevelopers/freetype-rs freetype-rs] library to replace [https://github.com/servo/rust-freetype rust-freetype] in Servo, rewriting necessary code.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3369&amp;lt;/ref&amp;gt; For this, we are to use [http://doc.crates.io/ Cargo], the dependency manager for Servo.&lt;br /&gt;
* Import the rust-image library to replace the [https://github.com/servo/rust-stb-image rust-stb-image] and [https://github.com/nothings/stb stb-image] libraries and rewrite the ''load_from_memory'' function which uses these libraries.&amp;lt;ref&amp;gt;https://github.com/servo/servo/issues/3368&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Report the timing differences for loading PNGs and non-PNGs on the same benchmarks. For this step, we are to consider profiling the result and optimizing the hotspots in rust-image.&lt;br /&gt;
&lt;br /&gt;
== Data and component design ==&lt;br /&gt;
&lt;br /&gt;
===Data Design===&lt;br /&gt;
The system entities that the project deals is present in the image crate.&lt;br /&gt;
The structs and Enums used are as below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Structures&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class = &amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ImageBuf&lt;br /&gt;
|An Image whose pixels are contained within a vector&lt;br /&gt;
|-&lt;br /&gt;
|Luma&lt;br /&gt;
|A type to hold a grayscale pixel&lt;br /&gt;
|-&lt;br /&gt;
|LumaA&lt;br /&gt;
|A type to hold a grayscale pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|MutPixels&lt;br /&gt;
|Mutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Pixels&lt;br /&gt;
|Immutable pixel iterator&lt;br /&gt;
|-&lt;br /&gt;
|Rgb&lt;br /&gt;
|A type to hold an RGB pixel&lt;br /&gt;
|-&lt;br /&gt;
|Rgba&lt;br /&gt;
|A type to hold an RGB pixel with an alpha channel&lt;br /&gt;
|-&lt;br /&gt;
|SubImage&lt;br /&gt;
|A View into another image&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Enums&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|ColorType&lt;br /&gt;
|An enumeration over supported color types and their bit depths&lt;br /&gt;
|-&lt;br /&gt;
|DynamicImage&lt;br /&gt;
|A Dynamic Image&lt;br /&gt;
|-&lt;br /&gt;
|FilterType&lt;br /&gt;
|Available Sampling Filters&lt;br /&gt;
|-&lt;br /&gt;
|ImageError&lt;br /&gt;
|An enumeration of Image Errors&lt;br /&gt;
|-&lt;br /&gt;
|ImageFormat&lt;br /&gt;
|An enumeration of supported image formats. Not all formats support both encoding and decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Component Design===&lt;br /&gt;
&lt;br /&gt;
Rust image : It is an image processing library. This crate provides basic imaging processing functions and methods for converting to and from image formats.&lt;br /&gt;
All image processing functions provided operate on types that implement the GenericImage trait and return an ImageBuf. The details of other modules and  traits included are :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Modules&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|gif&lt;br /&gt;
|Decoding of GIF Images&lt;br /&gt;
|-&lt;br /&gt;
|imageops&lt;br /&gt;
|Image Processing Functions&lt;br /&gt;
|-&lt;br /&gt;
|jpeg&lt;br /&gt;
|Decoding and Encoding of JPEG Images&lt;br /&gt;
|-&lt;br /&gt;
|png&lt;br /&gt;
|Decoding and Encoding of PNG Images&lt;br /&gt;
|-&lt;br /&gt;
|ppm&lt;br /&gt;
|Encoding of portable pixmap Images&lt;br /&gt;
|-&lt;br /&gt;
|webp&lt;br /&gt;
|Decoding of Webp Images&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|GenericImage&lt;br /&gt;
|A trait for manipulating images.&lt;br /&gt;
|-&lt;br /&gt;
|ImageDecoder&lt;br /&gt;
|The trait that all decoders implement&lt;br /&gt;
|-&lt;br /&gt;
|MutableRefImage&lt;br /&gt;
|A trait for images that allow providing mutable references to pixels.&lt;br /&gt;
|-&lt;br /&gt;
|Pixel&lt;br /&gt;
|A trait that all pixels implement.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Functions&amp;lt;/b&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|load&lt;br /&gt;
|Create a new image from a Reader&lt;br /&gt;
|-&lt;br /&gt;
|load_from_memory&lt;br /&gt;
|Create a new image from a byte slice&lt;br /&gt;
|-&lt;br /&gt;
|open&lt;br /&gt;
|Open the image located at the path specified. The image's format is determined from the path's file extension&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Design patterns ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML diagrams ==&lt;br /&gt;
&lt;br /&gt;
[[File:Flowchart_final_M1455.png]]&lt;br /&gt;
&lt;br /&gt;
== Proposed Test Cases ==&lt;br /&gt;
&lt;br /&gt;
The project does not plan to add new functionality. &lt;br /&gt;
The test-cases we propose to run are will ensure that the image decoding tasks that could be performed with the older C libraries can be executed after replacement as well.&lt;br /&gt;
&lt;br /&gt;
The following test cases are proposed.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90276</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90276"/>
		<updated>2014-10-29T02:29:45Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
Rust is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
Servo is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/&lt;br /&gt;
&lt;br /&gt;
== Further Reading==&lt;br /&gt;
https://people.mozilla.org/~roc/Samsung/MozillaRustAndServo.pdf&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90273</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90273"/>
		<updated>2014-10-29T02:28:43Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Run Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
Rust is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
Servo is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
https://www.mozilla.org/en-US/research/projects/&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90271</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90271"/>
		<updated>2014-10-29T02:28:12Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Rust==&lt;br /&gt;
Rust is a new programming language for developing reliable and efficient systems. It's designed to support concurrency and parallelism in building platforms that take full advantage of modern hardware. Its static type system is safe and expressive and it provides strong guarantees about isolation, concurrency execution and memory safety.&lt;br /&gt;
&lt;br /&gt;
Rust combines powerful and flexible modern programming constructs with a clear performance model to make program efficiency predictable and manageable. One important way it achieves this is by allowing fine-grained control over memory allocation through contiguous records and stack allocation. This control is balanced with the absolute requirement of safety: Rust’s type system and runtime guarantee the absence of data races, buffer overflow, stack overflow or access to uninitialized or deallocated memory.&lt;br /&gt;
&lt;br /&gt;
== Introduction to Servo==&lt;br /&gt;
Servo is an experimental project to build a Web browser engine for a new generation of hardware: mobile devices, multi-core processors and high-performance GPUs. With Servo, we are rethinking the browser at every level of the technology stack — from input parsing to page layout to graphics rendering — to optimize for power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
Servo builds on top of Rust to provide a secure and reliable foundation. Memory safety at the core of the platform ensures a high degree of assurance in the browser’s trusted computing base. Rust’s lightweight task mechanism also promises to allow fine-grained isolation between browser components, such as tabs and extensions, without the need for expensive runtime protection schemes, like operating system process isolation.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Shraddha1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90260</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90260"/>
		<updated>2014-10-29T02:20:30Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:bs14.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();.&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once we made the above changes, we now need to rebuild the servo code base. For this we again follow the same steps as described in the build servo section.&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90257</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90257"/>
		<updated>2014-10-29T02:18:35Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Run Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:buildservo1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Further the tabulated results are reported below:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90255</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90255"/>
		<updated>2014-10-29T02:17:55Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Run Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Screen1M1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:buildservoM1455.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
You can see the decoding time values reported for the different images on the command line.&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90250</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90250"/>
		<updated>2014-10-29T02:15:21Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90249</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90249"/>
		<updated>2014-10-29T02:14:50Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_2.png|left]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:M1455_3.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_4.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once the initial step is completed, our next task was to add timing code around the code block which performed decoding of images.&lt;br /&gt;
The decoding of images is performed in the https://github.com/servo/servo/blob/master/components/net/image_cache_task.rs rust file.&lt;br /&gt;
&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_5.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90240</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90240"/>
		<updated>2014-10-29T02:05:39Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:M1455_1.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|600px|left]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90238</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90238"/>
		<updated>2014-10-29T02:04:52Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository from git using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|600px|left]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Building servo basically compiling the code along withthe dependent libraries.&lt;br /&gt;
3. Once our servo is built, we have to run a test in order to ensure the build was successful. This is done using the below command &amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&lt;br /&gt;
&lt;br /&gt;
The above output shows that the html page was successfully launched by the servo browser. Thus proving that the build was successful.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90236</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90236"/>
		<updated>2014-10-29T01:51:11Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|600px|left]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90226</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90226"/>
		<updated>2014-10-29T01:27:51Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|600px|left]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90225</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90225"/>
		<updated>2014-10-29T01:27:30Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png|200px|thumb|left|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|600px|left]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90224</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90224"/>
		<updated>2014-10-29T01:27:00Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png|200px|thumb|left|]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|200px|thumb|left]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90223</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90223"/>
		<updated>2014-10-29T01:26:21Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|200px|thumb|left]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90222</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90222"/>
		<updated>2014-10-29T01:25:31Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|200px|thumb|left]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90220</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90220"/>
		<updated>2014-10-29T01:18:39Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png|center|300x200px]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90219</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90219"/>
		<updated>2014-10-29T01:17:02Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Build_servo.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Build_servo.png&amp;diff=90218</id>
		<title>File:Build servo.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Build_servo.png&amp;diff=90218"/>
		<updated>2014-10-29T01:16:28Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: uploaded a new version of &amp;amp;quot;File:Build servo.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90214</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90214"/>
		<updated>2014-10-29T01:06:36Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
It required us to make changes to the Servo code base.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:build_servo.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90211</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90211"/>
		<updated>2014-10-29T01:05:24Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps followed in order to implement the taskes assigned under the the above OSS Mozilla Project.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:build_servo.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90207</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=90207"/>
		<updated>2014-10-29T01:03:12Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS ==&lt;br /&gt;
In this wiki we represent the steps involved in our OSS Mozilla Project using Rust Programming Language.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:build_servo.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;let start_time=precise_time_ns();&lt;br /&gt;
 let image = load_from_memory(data.as_slice());&lt;br /&gt;
 let end_time=precise_time_ns();&lt;br /&gt;
 let required_time=(end_time-start_time) as f64/1000000f64;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Rebuild Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Run Tests ==&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
We tested images with different file formats and resolution using ./mach run image_url.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:code_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
These are the results we got:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89717</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89717"/>
		<updated>2014-10-26T23:56:32Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS '''&lt;br /&gt;
In this wiki we represent the steps involved in our OSS Mozilla Project using Rust Programming Language.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:build_servo.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
                    let start_time=precise_time_ns();&lt;br /&gt;
                    let image = load_from_memory(data.as_slice());&lt;br /&gt;
		    let end_time=precise_time_ns();&lt;br /&gt;
		    let required_time=(end_time-start_time) as f64/1000000f64;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89716</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89716"/>
		<updated>2014-10-26T23:56:13Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS '''&lt;br /&gt;
In this wiki we represent the steps involved in our OSS Mozilla Project using Rust Programming Language.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png|thumb]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:build_servo.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png|thumb]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
                    let start_time=precise_time_ns();&lt;br /&gt;
                    let image = load_from_memory(data.as_slice());&lt;br /&gt;
		    let end_time=precise_time_ns();&lt;br /&gt;
		    let required_time=(end_time-start_time) as f64/1000000f64;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89715</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89715"/>
		<updated>2014-10-26T23:55:45Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS '''&lt;br /&gt;
In this wiki we represent the steps involved in our OSS Mozilla Project using Rust Programming Language.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:build_servo.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png|thumb]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&amp;lt;br&amp;gt;&lt;br /&gt;
4. precise_time_ns() gives us the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&amp;lt;br&amp;gt;&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&amp;lt;br&amp;gt;&lt;br /&gt;
                    let start_time=precise_time_ns();&lt;br /&gt;
                    let image = load_from_memory(data.as_slice());&lt;br /&gt;
		    let end_time=precise_time_ns();&lt;br /&gt;
		    let required_time=(end_time-start_time) as f64/1000000f64;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89713</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89713"/>
		<updated>2014-10-26T23:53:02Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS '''&lt;br /&gt;
In this wiki we represent the steps involved in our OSS Mozilla Project using Rust Programming Language.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:build_servo.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&lt;br /&gt;
4. precise_time_ns() gives us the current time.&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&lt;br /&gt;
                    let start_time=precise_time_ns();&lt;br /&gt;
                    let image = load_from_memory(data.as_slice());&lt;br /&gt;
		    let end_time=precise_time_ns();&lt;br /&gt;
		    let required_time=(end_time-start_time) as f64/1000000f64;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89711</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89711"/>
		<updated>2014-10-26T23:51:54Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Steps of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' EVALUATE REPLACING C IMAGE &amp;amp; FONT LIBRARIES WITH RUST EQUIVALENTS '''&lt;br /&gt;
In this wiki we represent the steps involved in our OSS Mozilla Project using Rust Programming Language.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Servo is an experimental web browser layout engine being developed by Mozilla Research for new generation hardware.&lt;br /&gt;
The project has a symbiotic relationship with the Rust programming language, in which it is being developed. Rust is a new programming language for developing reliable and efficient systems.&lt;br /&gt;
&lt;br /&gt;
Servo currently depends on a lot of C libraries, because Rust equivalents did not exist when the project started. &lt;br /&gt;
We want to evaluate switching some of these to new Rust libraries that have been created. &lt;br /&gt;
This project involves rewriting the code that uses these libraries as well as taking measurements before and after to determine the costs involved.&lt;br /&gt;
&lt;br /&gt;
== Aim ==&lt;br /&gt;
The aim of our project is display the time required by the decode function to decode images of different formats, e.g, jpeg, bmp, png, gif.&lt;br /&gt;
&lt;br /&gt;
== Steps of Implementation ==&lt;br /&gt;
We implemented the following steps on our linux machine:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Build Servo'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. We first need to clone the servo repository using the following command:&amp;lt;br&amp;gt;&lt;br /&gt;
git clone https://www.github.com/servo/servo&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git clone.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
Now we have a local copy of the servo codebase.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. We build the servo using&amp;lt;br&amp;gt; &lt;br /&gt;
   ./mach build&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:build_servo.png|center|300x300px|]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Once our servo is built, we can run it using a test url&amp;lt;br&amp;gt;&lt;br /&gt;
   ./mach run url &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:test_command.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:test_op.png]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''• Add timing code'''&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
1. In image_cache_task.rs , we have a fn decode which calls the load_from_memory fn in base.rs. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Image decoding is implemented in this load_from_memory function.&amp;lt;br&amp;gt;&lt;br /&gt;
3. So we added the timing code arround this function call in imacge_cache_task.rs&lt;br /&gt;
4. precise_time_ns() gives us the current time.&lt;br /&gt;
5. So we added it before the call to get the start time of decoding and after the call to get the end time.&lt;br /&gt;
6. Difference of the two gave us the decoding time, which can be printed on command line.&lt;br /&gt;
                    let start_time=precise_time_ns();&lt;br /&gt;
                    let image = load_from_memory(data.as_slice());&lt;br /&gt;
		    let end_time=precise_time_ns();&lt;br /&gt;
		    let required_time=(end_time-start_time) as f64/1000000f64;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Code_op.png&amp;diff=89697</id>
		<title>File:Code op.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Code_op.png&amp;diff=89697"/>
		<updated>2014-10-26T23:36:24Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Test_op.png&amp;diff=89695</id>
		<title>File:Test op.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Test_op.png&amp;diff=89695"/>
		<updated>2014-10-26T23:31:08Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Test_command.png&amp;diff=89694</id>
		<title>File:Test command.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Test_command.png&amp;diff=89694"/>
		<updated>2014-10-26T23:30:42Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Build_servo.png&amp;diff=89693</id>
		<title>File:Build servo.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Build_servo.png&amp;diff=89693"/>
		<updated>2014-10-26T23:28:11Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Git_clone.png&amp;diff=89692</id>
		<title>File:Git clone.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Git_clone.png&amp;diff=89692"/>
		<updated>2014-10-26T23:25:36Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89678</id>
		<title>CSC/ECE 517 Fall 2014/oss M1455 asa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_M1455_asa&amp;diff=89678"/>
		<updated>2014-10-26T23:00:31Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: Created page with &amp;quot;'''''' Evaluate replacing C image &amp;amp; font libraries with Rust equivalents '''''''''Bold text'''&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''' Evaluate replacing C image &amp;amp; font libraries with Rust equivalents '''''''''Bold text'''&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=89675</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=89675"/>
		<updated>2014-10-26T22:50:13Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88441</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 9 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88441"/>
		<updated>2014-09-25T21:21:55Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Further reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Functional Programming?  =&lt;br /&gt;
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. The programming is done with the use of expressions, that is, it is a [http://en.wikipedia.org/wiki/Declarative_programming declarative programming] paradigm. One key feature in a functional language is the concept of [http://en.wikipedia.org/wiki/First-class_function first-class functions]. The idea is that you can pass functions as parameters to other functions and return them as values. Also, the output value of a function depends only on the arguments that are input to the function, unlike in [http://en.wikipedia.org/wiki/Imperative_programming imperative programming] languages. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behaviour of a program, which is one of the key motivations for the development of functional programming.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_programming&amp;lt;/ref&amp;gt;&lt;br /&gt;
Some examples of functional programming languages:&lt;br /&gt;
&lt;br /&gt;
*Common Lisp&lt;br /&gt;
*Scheme&lt;br /&gt;
*Erlang&lt;br /&gt;
*Haskell&lt;br /&gt;
&lt;br /&gt;
= What is Object Oriented Programming? =&lt;br /&gt;
Object-oriented programming (OOP) is based upon the concept of real world &amp;quot;objects&amp;quot;. These objects have data fields called attributes that describe the object and some procedures associated with them called methods. Object-oriented programming takes the view that what we really care about the objects we want to manipulate rather than the logic required to manipulate them.&lt;br /&gt;
&lt;br /&gt;
Some examples of object oriented programming languages are:&lt;br /&gt;
&lt;br /&gt;
*Simula&lt;br /&gt;
*Smalltalk&lt;br /&gt;
*C++&lt;br /&gt;
*Java&lt;br /&gt;
*C#&lt;br /&gt;
&lt;br /&gt;
= Features of Functional Programming&amp;lt;ref&amp;gt;http://en.wikibooks.org/wiki/Computer_Programming/Functional_programming&amp;lt;/ref&amp;gt; =&lt;br /&gt;
===&amp;lt;b&amp;gt;Higher-order functions:&amp;lt;/b&amp;gt;===&lt;br /&gt;
Higher-order functions (HOFs) are functions that take other functions as their arguments. A basic example of a HOF is map which takes a function and a list as its arguments, applies the function to all elements of the list, and returns the list of its results. Higher-order functions are very useful for refactoring code and reduce the amount of repetition.&lt;br /&gt;
Let’s see an example of a higher order function that receives a message, transforms it in various ways, and forwards it to another server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MessageHandler {&lt;br /&gt;
    	void handleMessage(Message msg, Function getClientCode) {&lt;br /&gt;
        	// ...&lt;br /&gt;
        	Message msg1 = msg.setClientCode(getClientCode());&lt;br /&gt;
        	// ...&lt;br /&gt;
        &lt;br /&gt;
        	sendMessage(msg1);&lt;br /&gt;
    	}&lt;br /&gt;
    &lt;br /&gt;
    	// ...&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeOne() {&lt;br /&gt;
    	return &amp;quot;ABCD_123&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeTwo() {&lt;br /&gt;
    	return &amp;quot;123_ABCD&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	MessageHandler handler = new MessageHandler();&lt;br /&gt;
	handler.handleMessage(someMsg, getClientCodeOne);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we see that we have created no new types and no class hierarchy. We simply pass appropriate functions as a parameter. We don't restrict ourselves to class hierarchies: we can pass new functions at runtime and change them at any time with a much higher degree of granularity with less code.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Purity&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.haskell.org/haskellwiki/Functional_programming&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Some functional languages allow expressions to yield actions in addition to return values. These actions are called side effects to emphasize that the return value is the most important outcome of a function (as opposed to the case in imperative programming). Languages that prohibit side effects are called pure. Even though some functional languages are impure they often contain a pure subset that is also useful as a programming language. It is usually beneficial to write a significant part of a functional program in a purely functional fashion and keep the code involving state and I/O to the minimum as impure code is more prone to errors.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutable data&amp;lt;/b&amp;gt;===&lt;br /&gt;
Purely functional programs typically operate on immutable data. Instead of altering existing values, altered copies are created and the original is preserved. Since the unchanged parts of the structure cannot be modified, they can often be shared between the old and new copies, which saves memory. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Referential transparency&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pure computations yield the same value each time they are invoked. This property is called referential transparency and makes possible to conduct equational reasoning on the code. For instance if &lt;br /&gt;
y = f x&lt;br /&gt;
and &lt;br /&gt;
g = h y y&lt;br /&gt;
then we should be able to replace the definition of &lt;br /&gt;
g&lt;br /&gt;
with &lt;br /&gt;
g = h (f x) (f x)&lt;br /&gt;
and get the same result; only the efficiency might change.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Lazy evaluation&amp;lt;/b&amp;gt;===&lt;br /&gt;
Since pure computations are referentially transparent they can be performed at any time and still yield the same result. This makes it possible to defer the computation of values until they are needed, that is, to compute them lazily. [http://en.wikipedia.org/wiki/Lazy_evaluation Lazy evaluation] avoids unnecessary computations and allows, for example, infinite data structures to be defined and used. &lt;br /&gt;
Let’s take a look at the following piece of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String s1 = somewhatLongOperation1();&lt;br /&gt;
String s2 = somewhatLongOperation2();&lt;br /&gt;
String s3 = concatenate(s1, s2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an imperative language the order of evaluation would be clear. Because each function may affect or depend on an external state it would be necessary to execute them in order: first somewhatLongOperation1, then somewhatLongOperation2, followed by concatenate. Not so in functional languages. somewhatLongOperation1 and somewhatLongOperation2 can be executed concurrently because we're guaranteed no function affects or depends on global state. But what if we don't want to run the two concurrently, do we need to run them in order? The answer is no. We only need to run these operations when another function depends on s1 and s2. We don't even have to run them before concatenate is called - we can delay their evaluation until they're required within concatenate. If we replace concatenate with a function that has a conditional and uses only one of its two parameters we may never evaluate one of the parameters at all!&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
[http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html Recursion] is heavily used in functional programming as it is the canonical and often the only way to iterate. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?PatternMatching&amp;lt;/ref&amp;gt;===&lt;br /&gt;
In the context of pure functional languages, [http://en.wikipedia.org/wiki/Pattern_matching Pattern Matching] is a dispatch mechanism: choosing which variant of a function is the correct one to call. Example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        factorial(0) ::= 1&lt;br /&gt;
	factorial(n) ::= n * factorial(n-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The function has been given two definitions. Which is used for dispatch when a call is made will depend, in this case, on whether the actual parameter pattern matches 0 or not. The matching is not limited to constants; in general, functions have a [http://en.wikipedia.org/wiki/Type_signature TypeSignature] used for matching. [http://en.wikipedia.org/wiki/Currying Currying] is integrated into this mechanism. &lt;br /&gt;
1.Pattern matching is the compiler's ability to compare both the form and the content of two expressions. It is used in two ways:&lt;br /&gt;
All or part of a data structure may be assigned to one or several variables in a single expression. &lt;br /&gt;
2.A function may have several definitions (clauses), according to the form and/or content of its arguments. This second use is usually combined with the first to initialize the variables that will be used in the clause. &lt;br /&gt;
In both these uses, a pattern match has the additional benefit of making an assertion about the form and/or content of a variable.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Closures&amp;lt;/b&amp;gt;===&lt;br /&gt;
Passing functions around in impure languages is a little bit different than doing it in the confines of lambda calculus and requires support for an interesting feature often referred to as [https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Closure_(computer_science).html lexical closure]. Let's take a look at some sample code. Remember, in this case variables aren't final and functions can refer to variables outside of their scope:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Function makePowerFn(int power) {&lt;br /&gt;
   int powerFn(int base) {&lt;br /&gt;
       return pow(base, power);&lt;br /&gt;
   }&lt;br /&gt;
   return powerFn;&lt;br /&gt;
}&lt;br /&gt;
Function square = makePowerFn(2);&lt;br /&gt;
square(3); // returns 9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function makePowerFn returns a function that takes a single argument and raises it to a certain power. What happens when we try to evaluate square(3)? The variable power isn't anywhere in scope of powerFn because makePowerFn has returned and its stack is long gone. How can square work, then? The language must, somehow, store the value of power somewhere for square to work. What if we create another function, cube, that raises something to the third power? The runtime must now store two copies of power, one for each function we generated using makePowerFn. The phenomenon of storing these values is called a closure.&lt;br /&gt;
&lt;br /&gt;
= Comparison between Functional Programming and OOP &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w25_aras&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Let us compare both the programming paradigms with respect to several disctinction attributes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Point of Comparison&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functional Languages&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Object-Oriented Languages&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Primary focus&amp;lt;/b&amp;gt;&lt;br /&gt;
| Functional programming emphasizes on functions that produce results which depend only on their inputs and not on the program state - i.e. pure mathematial functions. || Focus on identifying and''' representing the problem in terms of an 'object'''' which has its own data, sub-routines and state. Different objects in the problem interact by sending messages to each other and thus result in change in its internal state. The final state and values of the objects refer to the solution. It is '''data-centric'''.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Problem Solving Approach&amp;lt;/b&amp;gt;&lt;br /&gt;
| Primarily''' Top-down''' design || '''Identification and design of necessary objects'''. Close to being 'better models of the way the world works'.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Program Flow&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Often sequential''' with program having single point of entry and exit. || '''Complex''' program flow. Can sometimes depend on the internal state of the objects.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Modularity&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Limited modularity'''. Program is divided into modules or per say procedures independent of each other but are constrained due to uniqueness to that particular problem. || '''Extremely modular''' due to the presence of objects which contain their own data and sub-routines.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Data Protection/Hiding&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''No concept of data-hiding'''. Variables local to one method cannot be accessed by other method. But, Global variables can be accessed anywhere within the program. || One of the main fundamentals of O-O languages.''' Access specifiers''' like 'public', 'private' and 'protected' dictate the rules of data-hiding. Data which is private is confined to one object and cannot be directly changed by any other method except its own. This places the responsibility of managing data with the object itself This is called as ownership. Thus, data can be accessed ( read/write/modified )''' only''' through the object's own interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Ease of Understanding&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Smaller programs''' are '''easy to understand''' but as the program increases in size; understanding the code becomes more and more difficult. || '''Easy to understand''' due to its real world-like design and flow.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Reuse of Code&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Very Limited or no''' code re-usability. ||'''Highly re-usable code''' as the code developed can be easily modified or extended to suit a problem's need.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Support for declaring new data types/classes&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Difficult '''due to limited in-built functionality. || '''Easily possible''' due to the concept of classes. Generic classes can be built as per the required specifications.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Efficiency&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Efficient''' for solving '''small''' problems. || '''Efficient''' for solving '''large problems''' which have a complex structure and require complex data-types, abstraction and data-security.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintenance&amp;lt;/b&amp;gt;&lt;br /&gt;
| Maintenance is''' easy for smaller programs''' but can consume''' a-lot of effort for larger program''' size as it requires the programmer to know and understand the dependencies of every module in the program. This makes it difficult to debug and test the program. ||'''Extremely simple''' as O-O languages aim for high modularity. Secondly, programmer is not concerned with the details of how the data is stored and represented. Thirdly, they also tend to keep low coupling which makes it easy to debug and test different modules in the program.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less Extensible''' as modules developed need to be re-organised and re-structured heavily in order to meet different needs. || '''High extensibility''' is one of the most important advantages of OOP. Code can be easily modified and 'plugged-in' to a different program. Methods can be exteneded due to many properties such as polymorphism, inheritance and support for multiple inheritance through interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Flexibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less flexible.''' Sometimes, certain problems do not fit into the 'top-down design' approach. || '''High flexibility.''' The modelling of problems into world-like objects makes it easy to solve any practical problem.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Examples&amp;lt;/b&amp;gt;&lt;br /&gt;
| [http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell], [http://en.wikipedia.org/wiki/Scala_%28programming_language%29 Scala], [http://en.wikipedia.org/wiki/Erlang_%28programming_language%29 Erlang] || [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], [http://en.wikipedia.org/wiki/Python_(programming_language) Python].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Scala : An overview  &amp;lt;ref&amp;gt;http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html&amp;lt;/ref&amp;gt;=&lt;br /&gt;
Scala is an object-functional programming and scripting language generallly used in software applications. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.) and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than most general purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.&lt;br /&gt;
&lt;br /&gt;
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries can be used directly in Scala code, and vice versa. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
object HelloWorld &lt;br /&gt;
{&lt;br /&gt;
   def main(args: Array[String]) &lt;br /&gt;
  {&lt;br /&gt;
    println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program consists of one method called main which takes the command line arguments, an array of strings, as parameter; the body of this method consists of a single call to the predefined method println with the greeting as argument. The main method does not return a value (it is a procedure method). Therefore, it is not necessary to declare a return type. Such a declaration introduces what is commonly known as a singleton object, that is a class with a single instance. The declaration above thus declares both a class called HelloWorld and an instance of that class, also called HelloWorld. This instance is created on demand, the first time it is used. Notice that the main method is not declared as static (like in Java) here. This is because static members (methods or fields) do not exist in Scala. Rather than defining static members, the Scala programmer declares these members in singleton objects.&lt;br /&gt;
&lt;br /&gt;
= Features of Scala &amp;lt;ref&amp;gt;http://www.scala-lang.org/old/node/104&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is object-oriented&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is functional&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.&lt;br /&gt;
Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of right-ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is statically typed&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. &lt;br /&gt;
In particular, the type system supports:&lt;br /&gt;
generic classes, variance annotations, upper and lower type bounds, inner classes and abstract types as object members, compound types, explicitly typed self references, views, and polymorphic methods.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is extensible&amp;lt;/b&amp;gt;===&lt;br /&gt;
In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:&lt;br /&gt;
any method may be used as an infix or postfix operator, and&lt;br /&gt;
closures are constructed automatically depending on the expected type (target typing). A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala interoperates with Java and .NET&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is designed to interoperate well with the popular Java 2 Runtime Environment ([http://docs.oracle.com/javase/7/docs/ JRE]) . In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available.&lt;br /&gt;
&lt;br /&gt;
= Similarities between Scala and Java =&lt;br /&gt;
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy,JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.&lt;br /&gt;
&lt;br /&gt;
2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.&lt;br /&gt;
&lt;br /&gt;
3) Major Java programming IDE like [http://www.eclipse.org/documentation/ Eclipse],[https://netbeans.org/kb/ Netbeans] and [http://www.jetbrains.com/idea/ InetelliJ] supports Scala.&lt;br /&gt;
&lt;br /&gt;
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.&lt;br /&gt;
&lt;br /&gt;
= Scala vs JAVA &amp;lt;ref&amp;gt;http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Syntactic flexibility &amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala has a very powerful and flexible syntax as it relates to methods, both declaration and invocation. In Java you can create methods with different visibilities, modifiers and return types. Scala does allow for different visibilities on not just methods, but any members. &lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person {&lt;br /&gt;
  private var name = &amp;quot;Daniel Spiewak&amp;quot;&lt;br /&gt;
  val ssn = 1234567890    // public constant field&lt;br /&gt;
 &lt;br /&gt;
  def firstName() = splitName()(0)   // public method&lt;br /&gt;
 &lt;br /&gt;
  private def splitName() = name.split(&amp;quot; &amp;quot;)    // private method&lt;br /&gt;
 &lt;br /&gt;
  protected def guessAge() = {&lt;br /&gt;
    import Math._&lt;br /&gt;
    round(random * 20)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala provides the option to import into a specific scope. The import statement within guessAge()is much like a Java static import statement which only provides access to the Math members within theguessAge() method. So we couldn’t just make a call to round() from within the splitName() method.&lt;br /&gt;
Scala access modifiers are also quite a bit more powerful than Java’s. For example,protected by default limits access to only subclasses, unlike Java which also allows access to other classes in the same package.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Unified type system&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). Only reference types are part of the inheritance scheme, deriving from java.lang.Object. In Scala, however, all types inherit from a top-level class Any, whose immediate children are AnyVal(value types, such as Int and Boolean) andAnyRef (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala; boxing and unboxing is completely transparent to the user. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;For-expressions&amp;lt;/b&amp;gt;===&lt;br /&gt;
Instead of the Java &amp;quot;foreach&amp;quot; loops for looping through an iterator, Scala has a much more powerful concept of for-expressions. These are similar to list comprehensions in languages such as Haskell, or a combination of list comprehensions and generator expressions in Python. For-expressions using the yield keyword allow a new collection to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of map, flatMap and filter calls. Where yield is not used, the code approximates to an imperative-style loop, by translating to foreach. A simple example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val s = for (x &amp;lt;- 1 to 25 if x*x &amp;gt; 50) yield 2*x&lt;br /&gt;
The result of running it is the following vector:&lt;br /&gt;
Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Everything is an expression&amp;lt;/b&amp;gt;===&lt;br /&gt;
Unlike C or Java, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning void in Java, and statements like while that logically do not return a value, are in Scala considered to return the type Unit, which is a singleton type, with only one object of that type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Java:&lt;br /&gt;
int hexDigit = x &amp;gt;= 10 ? x + 'A' - 10 : x + '0';&lt;br /&gt;
&lt;br /&gt;
//Scala: &lt;br /&gt;
val hexDigit = if (x &amp;gt;= 10) x + 'A' - 10 else x + '0'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Type inference&amp;lt;/b&amp;gt;===&lt;br /&gt;
Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = &amp;quot;foo&amp;quot; (for an immutable, constant variable or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Anonymous functions&amp;lt;/b&amp;gt;===&lt;br /&gt;
In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x =&amp;gt; x &amp;lt; 2, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. &lt;br /&gt;
&lt;br /&gt;
An even shorter form of anonymous function uses placeholder variables: For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list map { x =&amp;gt; sqrt(x) }&lt;br /&gt;
&lt;br /&gt;
can be written more concisely as&lt;br /&gt;
&lt;br /&gt;
list map { sqrt(_) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutability&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with val while mutable variables use var. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Tail recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround. Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released July 14, 2010).&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pattern matching in Scala is really a lot like Java’s switch/case construct.  So in Java, one might write something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public boolean checkPrime(int number) {&lt;br /&gt;
    // checks if a number between 1 and 10 is prime&lt;br /&gt;
    switch (number) {&lt;br /&gt;
        case 1: return true;&lt;br /&gt;
        case 2: return true;&lt;br /&gt;
        case 3: return true;&lt;br /&gt;
        case 5: return true;&lt;br /&gt;
        case 7: return true;&lt;br /&gt;
 &lt;br /&gt;
        default: return false;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the major limitations of switch/case in Java  is that it can only be used on primitives.  You can’t use switch/case to test a String, for example (a need which arises more often than one would think).  In fact, the most complex type testable within switch/case is the Enum, and even this is just being reduced to its ordinal values under the surface.&lt;br /&gt;
The designers of Scala chose not to include this “feature” in their new language. Instead, they implemented a “new” concept called pattern matching. At a basic level, it allows algorithms which are very similar to the checkPrime(int) example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def checkPrime(number:Int):Boolean = {&lt;br /&gt;
  number match {&lt;br /&gt;
    case 1 =&amp;gt; return true&lt;br /&gt;
    case 2 =&amp;gt; return true&lt;br /&gt;
    case 3 =&amp;gt; return true&lt;br /&gt;
    case 5 =&amp;gt; return true&lt;br /&gt;
    case 7 =&amp;gt; return true&lt;br /&gt;
 &lt;br /&gt;
    case _ =&amp;gt; return false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The biggest difference which likely jumps out at you is the lack of a default statement. Instead, we see the return of Scala’s ubiquitous wildcard character, the underscore. Literally read, this example means: match the value within number; in the case that it is 1, return true; in the case that it is 2, return true; …; for any previously unmatched value, return false.&lt;br /&gt;
Scala case statements can’t “overflow” into each-other (causing multiple matches) like Java’s can, so even if we weren’t returning values, the algorithm would still be safe.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java’s designers recognized the need for multiple typing (e.g. CollegeStudent is both a Student and a Worker), but they wanted to avoid the issues associated with inheriting conflicting method definitions along multiple paths.  Their solution was to design the interface mechanism, a feature which allows multiple typing without the complications of multiple inheritance.  &lt;br /&gt;
Scala recognizes that interfaces have their issues.  So rather than blinding creating a reimplementation of the same problems found in either Java or C++, Scala takes a new approach.  Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
trait Book &lt;br /&gt;
{&lt;br /&gt;
  def title:String&lt;br /&gt;
  def title_=(n:String):Unit&lt;br /&gt;
 &lt;br /&gt;
  def computePrice = title.length * 10&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala’s traits are quite nice in that they can not only define abstract members, but also full method definitions. At the same time, they allow inheriting classes to inherit from more than one trait. They pass on their type information and implementations to their children, as well as enforcing the abstract members. At first glance, this seems like it would be just as bad as straight-up multiple inheritance, but it turns out the problems have been mitigated in some very clever ways.&lt;br /&gt;
Traits are actually mixins, not true parent classes. Any non-abstract trait members are actually included in the inheriting class, as in physically part of the class. Well, not physically, but you get the picture. It’s as if the compiler performs a cut-and-paste with the non-abstract members and inserts them into the inheriting class. This means that there’s no ambiguity in the inheritance path, meaning no diamond problem. We can rewrite our CollegeStudent example in Scala without redundancy or fear of paradox:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Person {&lt;br /&gt;
  def schedule:Schedule&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Student extends Person {&lt;br /&gt;
  private var classSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = classSchedule&lt;br /&gt;
 &lt;br /&gt;
  def learn() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Worker extends Person {&lt;br /&gt;
  private var workSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = workSchedule&lt;br /&gt;
 &lt;br /&gt;
  def work() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class CollegeStudent(school:School, company:Company) extends Student with Worker {&lt;br /&gt;
  // ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if we make a call to the schedule method on an instance of CollegeStudent, the compiler knows that we’re referring to the implementation of schedule in the Worker trait.  This is because Worker was mixed in after the Student trait.  &lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Further reading =&lt;br /&gt;
# [http://vimeo.com/20293743 Video to learn about Scala]&lt;br /&gt;
# [http://docs.scala-lang.org/tutorials/ Scala Documentation]&lt;br /&gt;
# [http://shipilev.net/blog/2014/java-scala-divided-we-fail/#_analyzing_bottlenecks Java vs. Scala]&lt;br /&gt;
# [http://www.cs.uku.fi/~mnykanen/FOH/lectures1.pdf  Salient Features of Functional Programming]&lt;br /&gt;
# [https://www.cs.rpi.edu/research/pdf/10-04.pdf Comparison of Object-oriented and Functional Programming]&lt;br /&gt;
# [http://en.wikibooks.org/wiki/Object_Oriented_Programming features of Object oriented programming]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88433</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 9 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88433"/>
		<updated>2014-09-25T21:15:10Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Scala interoperates with Java and .NET */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Functional Programming?  =&lt;br /&gt;
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. The programming is done with the use of expressions, that is, it is a [http://en.wikipedia.org/wiki/Declarative_programming declarative programming] paradigm. One key feature in a functional language is the concept of [http://en.wikipedia.org/wiki/First-class_function first-class functions]. The idea is that you can pass functions as parameters to other functions and return them as values. Also, the output value of a function depends only on the arguments that are input to the function, unlike in [http://en.wikipedia.org/wiki/Imperative_programming imperative programming] languages. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behaviour of a program, which is one of the key motivations for the development of functional programming.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_programming&amp;lt;/ref&amp;gt;&lt;br /&gt;
Some examples of functional programming languages:&lt;br /&gt;
&lt;br /&gt;
*Common Lisp&lt;br /&gt;
*Scheme&lt;br /&gt;
*Erlang&lt;br /&gt;
*Haskell&lt;br /&gt;
&lt;br /&gt;
= What is Object Oriented Programming? =&lt;br /&gt;
Object-oriented programming (OOP) is based upon the concept of real world &amp;quot;objects&amp;quot;. These objects have data fields called attributes that describe the object and some procedures associated with them called methods. Object-oriented programming takes the view that what we really care about the objects we want to manipulate rather than the logic required to manipulate them.&lt;br /&gt;
&lt;br /&gt;
Some examples of object oriented programming languages are:&lt;br /&gt;
&lt;br /&gt;
*Simula&lt;br /&gt;
*Smalltalk&lt;br /&gt;
*C++&lt;br /&gt;
*Java&lt;br /&gt;
*C#&lt;br /&gt;
&lt;br /&gt;
= Features of Functional Programming&amp;lt;ref&amp;gt;http://en.wikibooks.org/wiki/Computer_Programming/Functional_programming&amp;lt;/ref&amp;gt; =&lt;br /&gt;
===&amp;lt;b&amp;gt;Higher-order functions:&amp;lt;/b&amp;gt;===&lt;br /&gt;
Higher-order functions (HOFs) are functions that take other functions as their arguments. A basic example of a HOF is map which takes a function and a list as its arguments, applies the function to all elements of the list, and returns the list of its results. Higher-order functions are very useful for refactoring code and reduce the amount of repetition.&lt;br /&gt;
Let’s see an example of a higher order function that receives a message, transforms it in various ways, and forwards it to another server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MessageHandler {&lt;br /&gt;
    	void handleMessage(Message msg, Function getClientCode) {&lt;br /&gt;
        	// ...&lt;br /&gt;
        	Message msg1 = msg.setClientCode(getClientCode());&lt;br /&gt;
        	// ...&lt;br /&gt;
        &lt;br /&gt;
        	sendMessage(msg1);&lt;br /&gt;
    	}&lt;br /&gt;
    &lt;br /&gt;
    	// ...&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeOne() {&lt;br /&gt;
    	return &amp;quot;ABCD_123&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeTwo() {&lt;br /&gt;
    	return &amp;quot;123_ABCD&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	MessageHandler handler = new MessageHandler();&lt;br /&gt;
	handler.handleMessage(someMsg, getClientCodeOne);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we see that we have created no new types and no class hierarchy. We simply pass appropriate functions as a parameter. We don't restrict ourselves to class hierarchies: we can pass new functions at runtime and change them at any time with a much higher degree of granularity with less code.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Purity&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.haskell.org/haskellwiki/Functional_programming&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Some functional languages allow expressions to yield actions in addition to return values. These actions are called side effects to emphasize that the return value is the most important outcome of a function (as opposed to the case in imperative programming). Languages that prohibit side effects are called pure. Even though some functional languages are impure they often contain a pure subset that is also useful as a programming language. It is usually beneficial to write a significant part of a functional program in a purely functional fashion and keep the code involving state and I/O to the minimum as impure code is more prone to errors.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutable data&amp;lt;/b&amp;gt;===&lt;br /&gt;
Purely functional programs typically operate on immutable data. Instead of altering existing values, altered copies are created and the original is preserved. Since the unchanged parts of the structure cannot be modified, they can often be shared between the old and new copies, which saves memory. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Referential transparency&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pure computations yield the same value each time they are invoked. This property is called referential transparency and makes possible to conduct equational reasoning on the code. For instance if &lt;br /&gt;
y = f x&lt;br /&gt;
and &lt;br /&gt;
g = h y y&lt;br /&gt;
then we should be able to replace the definition of &lt;br /&gt;
g&lt;br /&gt;
with &lt;br /&gt;
g = h (f x) (f x)&lt;br /&gt;
and get the same result; only the efficiency might change.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Lazy evaluation&amp;lt;/b&amp;gt;===&lt;br /&gt;
Since pure computations are referentially transparent they can be performed at any time and still yield the same result. This makes it possible to defer the computation of values until they are needed, that is, to compute them lazily. [http://en.wikipedia.org/wiki/Lazy_evaluation Lazy evaluation] avoids unnecessary computations and allows, for example, infinite data structures to be defined and used. &lt;br /&gt;
Let’s take a look at the following piece of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String s1 = somewhatLongOperation1();&lt;br /&gt;
String s2 = somewhatLongOperation2();&lt;br /&gt;
String s3 = concatenate(s1, s2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an imperative language the order of evaluation would be clear. Because each function may affect or depend on an external state it would be necessary to execute them in order: first somewhatLongOperation1, then somewhatLongOperation2, followed by concatenate. Not so in functional languages. somewhatLongOperation1 and somewhatLongOperation2 can be executed concurrently because we're guaranteed no function affects or depends on global state. But what if we don't want to run the two concurrently, do we need to run them in order? The answer is no. We only need to run these operations when another function depends on s1 and s2. We don't even have to run them before concatenate is called - we can delay their evaluation until they're required within concatenate. If we replace concatenate with a function that has a conditional and uses only one of its two parameters we may never evaluate one of the parameters at all!&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
[http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html Recursion] is heavily used in functional programming as it is the canonical and often the only way to iterate. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?PatternMatching&amp;lt;/ref&amp;gt;===&lt;br /&gt;
In the context of pure functional languages, [http://en.wikipedia.org/wiki/Pattern_matching Pattern Matching] is a dispatch mechanism: choosing which variant of a function is the correct one to call. Example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        factorial(0) ::= 1&lt;br /&gt;
	factorial(n) ::= n * factorial(n-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The function has been given two definitions. Which is used for dispatch when a call is made will depend, in this case, on whether the actual parameter pattern matches 0 or not. The matching is not limited to constants; in general, functions have a [http://en.wikipedia.org/wiki/Type_signature TypeSignature] used for matching. [http://en.wikipedia.org/wiki/Currying Currying] is integrated into this mechanism. &lt;br /&gt;
1.Pattern matching is the compiler's ability to compare both the form and the content of two expressions. It is used in two ways:&lt;br /&gt;
All or part of a data structure may be assigned to one or several variables in a single expression. &lt;br /&gt;
2.A function may have several definitions (clauses), according to the form and/or content of its arguments. This second use is usually combined with the first to initialize the variables that will be used in the clause. &lt;br /&gt;
In both these uses, a pattern match has the additional benefit of making an assertion about the form and/or content of a variable.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Closures&amp;lt;/b&amp;gt;===&lt;br /&gt;
Passing functions around in impure languages is a little bit different than doing it in the confines of lambda calculus and requires support for an interesting feature often referred to as [https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Closure_(computer_science).html lexical closure]. Let's take a look at some sample code. Remember, in this case variables aren't final and functions can refer to variables outside of their scope:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Function makePowerFn(int power) {&lt;br /&gt;
   int powerFn(int base) {&lt;br /&gt;
       return pow(base, power);&lt;br /&gt;
   }&lt;br /&gt;
   return powerFn;&lt;br /&gt;
}&lt;br /&gt;
Function square = makePowerFn(2);&lt;br /&gt;
square(3); // returns 9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function makePowerFn returns a function that takes a single argument and raises it to a certain power. What happens when we try to evaluate square(3)? The variable power isn't anywhere in scope of powerFn because makePowerFn has returned and its stack is long gone. How can square work, then? The language must, somehow, store the value of power somewhere for square to work. What if we create another function, cube, that raises something to the third power? The runtime must now store two copies of power, one for each function we generated using makePowerFn. The phenomenon of storing these values is called a closure.&lt;br /&gt;
&lt;br /&gt;
= Comparison between Functional Programming and OOP &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w25_aras&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Let us compare both the programming paradigms with respect to several disctinction attributes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Point of Comparison&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functional Languages&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Object-Oriented Languages&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Primary focus&amp;lt;/b&amp;gt;&lt;br /&gt;
| Functional programming emphasizes on functions that produce results which depend only on their inputs and not on the program state - i.e. pure mathematial functions. || Focus on identifying and''' representing the problem in terms of an 'object'''' which has its own data, sub-routines and state. Different objects in the problem interact by sending messages to each other and thus result in change in its internal state. The final state and values of the objects refer to the solution. It is '''data-centric'''.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Problem Solving Approach&amp;lt;/b&amp;gt;&lt;br /&gt;
| Primarily''' Top-down''' design || '''Identification and design of necessary objects'''. Close to being 'better models of the way the world works'.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Program Flow&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Often sequential''' with program having single point of entry and exit. || '''Complex''' program flow. Can sometimes depend on the internal state of the objects.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Modularity&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Limited modularity'''. Program is divided into modules or per say procedures independent of each other but are constrained due to uniqueness to that particular problem. || '''Extremely modular''' due to the presence of objects which contain their own data and sub-routines.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Data Protection/Hiding&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''No concept of data-hiding'''. Variables local to one method cannot be accessed by other method. But, Global variables can be accessed anywhere within the program. || One of the main fundamentals of O-O languages.''' Access specifiers''' like 'public', 'private' and 'protected' dictate the rules of data-hiding. Data which is private is confined to one object and cannot be directly changed by any other method except its own. This places the responsibility of managing data with the object itself This is called as ownership. Thus, data can be accessed ( read/write/modified )''' only''' through the object's own interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Ease of Understanding&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Smaller programs''' are '''easy to understand''' but as the program increases in size; understanding the code becomes more and more difficult. || '''Easy to understand''' due to its real world-like design and flow.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Reuse of Code&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Very Limited or no''' code re-usability. ||'''Highly re-usable code''' as the code developed can be easily modified or extended to suit a problem's need.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Support for declaring new data types/classes&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Difficult '''due to limited in-built functionality. || '''Easily possible''' due to the concept of classes. Generic classes can be built as per the required specifications.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Efficiency&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Efficient''' for solving '''small''' problems. || '''Efficient''' for solving '''large problems''' which have a complex structure and require complex data-types, abstraction and data-security.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintenance&amp;lt;/b&amp;gt;&lt;br /&gt;
| Maintenance is''' easy for smaller programs''' but can consume''' a-lot of effort for larger program''' size as it requires the programmer to know and understand the dependencies of every module in the program. This makes it difficult to debug and test the program. ||'''Extremely simple''' as O-O languages aim for high modularity. Secondly, programmer is not concerned with the details of how the data is stored and represented. Thirdly, they also tend to keep low coupling which makes it easy to debug and test different modules in the program.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less Extensible''' as modules developed need to be re-organised and re-structured heavily in order to meet different needs. || '''High extensibility''' is one of the most important advantages of OOP. Code can be easily modified and 'plugged-in' to a different program. Methods can be exteneded due to many properties such as polymorphism, inheritance and support for multiple inheritance through interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Flexibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less flexible.''' Sometimes, certain problems do not fit into the 'top-down design' approach. || '''High flexibility.''' The modelling of problems into world-like objects makes it easy to solve any practical problem.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Examples&amp;lt;/b&amp;gt;&lt;br /&gt;
| [http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell], [http://en.wikipedia.org/wiki/Scala_%28programming_language%29 Scala], [http://en.wikipedia.org/wiki/Erlang_%28programming_language%29 Erlang] || [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], [http://en.wikipedia.org/wiki/Python_(programming_language) Python].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Scala : An overview  &amp;lt;ref&amp;gt;http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html&amp;lt;/ref&amp;gt;=&lt;br /&gt;
Scala is an object-functional programming and scripting language generallly used in software applications. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.) and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than most general purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.&lt;br /&gt;
&lt;br /&gt;
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries can be used directly in Scala code, and vice versa. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
object HelloWorld &lt;br /&gt;
{&lt;br /&gt;
   def main(args: Array[String]) &lt;br /&gt;
  {&lt;br /&gt;
    println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program consists of one method called main which takes the command line arguments, an array of strings, as parameter; the body of this method consists of a single call to the predefined method println with the greeting as argument. The main method does not return a value (it is a procedure method). Therefore, it is not necessary to declare a return type. Such a declaration introduces what is commonly known as a singleton object, that is a class with a single instance. The declaration above thus declares both a class called HelloWorld and an instance of that class, also called HelloWorld. This instance is created on demand, the first time it is used. Notice that the main method is not declared as static (like in Java) here. This is because static members (methods or fields) do not exist in Scala. Rather than defining static members, the Scala programmer declares these members in singleton objects.&lt;br /&gt;
&lt;br /&gt;
= Features of Scala &amp;lt;ref&amp;gt;http://www.scala-lang.org/old/node/104&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is object-oriented&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is functional&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.&lt;br /&gt;
Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of right-ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is statically typed&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. &lt;br /&gt;
In particular, the type system supports:&lt;br /&gt;
generic classes, variance annotations, upper and lower type bounds, inner classes and abstract types as object members, compound types, explicitly typed self references, views, and polymorphic methods.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is extensible&amp;lt;/b&amp;gt;===&lt;br /&gt;
In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:&lt;br /&gt;
any method may be used as an infix or postfix operator, and&lt;br /&gt;
closures are constructed automatically depending on the expected type (target typing). A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala interoperates with Java and .NET&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is designed to interoperate well with the popular Java 2 Runtime Environment ([http://docs.oracle.com/javase/7/docs/ JRE]) . In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available.&lt;br /&gt;
&lt;br /&gt;
= Similarities between Scala and Java =&lt;br /&gt;
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy,JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.&lt;br /&gt;
&lt;br /&gt;
2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.&lt;br /&gt;
&lt;br /&gt;
3) Major Java programming IDE like [http://www.eclipse.org/documentation/ Eclipse],[https://netbeans.org/kb/ Netbeans] and [http://www.jetbrains.com/idea/ InetelliJ] supports Scala.&lt;br /&gt;
&lt;br /&gt;
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.&lt;br /&gt;
&lt;br /&gt;
= Scala vs JAVA &amp;lt;ref&amp;gt;http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Syntactic flexibility &amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala has a very powerful and flexible syntax as it relates to methods, both declaration and invocation. In Java you can create methods with different visibilities, modifiers and return types. Scala does allow for different visibilities on not just methods, but any members. &lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person {&lt;br /&gt;
  private var name = &amp;quot;Daniel Spiewak&amp;quot;&lt;br /&gt;
  val ssn = 1234567890    // public constant field&lt;br /&gt;
 &lt;br /&gt;
  def firstName() = splitName()(0)   // public method&lt;br /&gt;
 &lt;br /&gt;
  private def splitName() = name.split(&amp;quot; &amp;quot;)    // private method&lt;br /&gt;
 &lt;br /&gt;
  protected def guessAge() = {&lt;br /&gt;
    import Math._&lt;br /&gt;
    round(random * 20)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala provides the option to import into a specific scope. The import statement within guessAge()is much like a Java static import statement which only provides access to the Math members within theguessAge() method. So we couldn’t just make a call to round() from within the splitName() method.&lt;br /&gt;
Scala access modifiers are also quite a bit more powerful than Java’s. For example,protected by default limits access to only subclasses, unlike Java which also allows access to other classes in the same package.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Unified type system&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). Only reference types are part of the inheritance scheme, deriving from java.lang.Object. In Scala, however, all types inherit from a top-level class Any, whose immediate children are AnyVal(value types, such as Int and Boolean) andAnyRef (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala; boxing and unboxing is completely transparent to the user. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;For-expressions&amp;lt;/b&amp;gt;===&lt;br /&gt;
Instead of the Java &amp;quot;foreach&amp;quot; loops for looping through an iterator, Scala has a much more powerful concept of for-expressions. These are similar to list comprehensions in languages such as Haskell, or a combination of list comprehensions and generator expressions in Python. For-expressions using the yield keyword allow a new collection to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of map, flatMap and filter calls. Where yield is not used, the code approximates to an imperative-style loop, by translating to foreach. A simple example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val s = for (x &amp;lt;- 1 to 25 if x*x &amp;gt; 50) yield 2*x&lt;br /&gt;
The result of running it is the following vector:&lt;br /&gt;
Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Everything is an expression&amp;lt;/b&amp;gt;===&lt;br /&gt;
Unlike C or Java, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning void in Java, and statements like while that logically do not return a value, are in Scala considered to return the type Unit, which is a singleton type, with only one object of that type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Java:&lt;br /&gt;
int hexDigit = x &amp;gt;= 10 ? x + 'A' - 10 : x + '0';&lt;br /&gt;
&lt;br /&gt;
//Scala: &lt;br /&gt;
val hexDigit = if (x &amp;gt;= 10) x + 'A' - 10 else x + '0'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Type inference&amp;lt;/b&amp;gt;===&lt;br /&gt;
Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = &amp;quot;foo&amp;quot; (for an immutable, constant variable or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Anonymous functions&amp;lt;/b&amp;gt;===&lt;br /&gt;
In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x =&amp;gt; x &amp;lt; 2, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. &lt;br /&gt;
&lt;br /&gt;
An even shorter form of anonymous function uses placeholder variables: For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list map { x =&amp;gt; sqrt(x) }&lt;br /&gt;
&lt;br /&gt;
can be written more concisely as&lt;br /&gt;
&lt;br /&gt;
list map { sqrt(_) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutability&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with val while mutable variables use var. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Tail recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround. Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released July 14, 2010).&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pattern matching in Scala is really a lot like Java’s switch/case construct.  So in Java, one might write something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public boolean checkPrime(int number) {&lt;br /&gt;
    // checks if a number between 1 and 10 is prime&lt;br /&gt;
    switch (number) {&lt;br /&gt;
        case 1: return true;&lt;br /&gt;
        case 2: return true;&lt;br /&gt;
        case 3: return true;&lt;br /&gt;
        case 5: return true;&lt;br /&gt;
        case 7: return true;&lt;br /&gt;
 &lt;br /&gt;
        default: return false;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the major limitations of switch/case in Java  is that it can only be used on primitives.  You can’t use switch/case to test a String, for example (a need which arises more often than one would think).  In fact, the most complex type testable within switch/case is the Enum, and even this is just being reduced to its ordinal values under the surface.&lt;br /&gt;
The designers of Scala chose not to include this “feature” in their new language. Instead, they implemented a “new” concept called pattern matching. At a basic level, it allows algorithms which are very similar to the checkPrime(int) example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def checkPrime(number:Int):Boolean = {&lt;br /&gt;
  number match {&lt;br /&gt;
    case 1 =&amp;gt; return true&lt;br /&gt;
    case 2 =&amp;gt; return true&lt;br /&gt;
    case 3 =&amp;gt; return true&lt;br /&gt;
    case 5 =&amp;gt; return true&lt;br /&gt;
    case 7 =&amp;gt; return true&lt;br /&gt;
 &lt;br /&gt;
    case _ =&amp;gt; return false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The biggest difference which likely jumps out at you is the lack of a default statement. Instead, we see the return of Scala’s ubiquitous wildcard character, the underscore. Literally read, this example means: match the value within number; in the case that it is 1, return true; in the case that it is 2, return true; …; for any previously unmatched value, return false.&lt;br /&gt;
Scala case statements can’t “overflow” into each-other (causing multiple matches) like Java’s can, so even if we weren’t returning values, the algorithm would still be safe.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java’s designers recognized the need for multiple typing (e.g. CollegeStudent is both a Student and a Worker), but they wanted to avoid the issues associated with inheriting conflicting method definitions along multiple paths.  Their solution was to design the interface mechanism, a feature which allows multiple typing without the complications of multiple inheritance.  &lt;br /&gt;
Scala recognizes that interfaces have their issues.  So rather than blinding creating a reimplementation of the same problems found in either Java or C++, Scala takes a new approach.  Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
trait Book &lt;br /&gt;
{&lt;br /&gt;
  def title:String&lt;br /&gt;
  def title_=(n:String):Unit&lt;br /&gt;
 &lt;br /&gt;
  def computePrice = title.length * 10&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala’s traits are quite nice in that they can not only define abstract members, but also full method definitions. At the same time, they allow inheriting classes to inherit from more than one trait. They pass on their type information and implementations to their children, as well as enforcing the abstract members. At first glance, this seems like it would be just as bad as straight-up multiple inheritance, but it turns out the problems have been mitigated in some very clever ways.&lt;br /&gt;
Traits are actually mixins, not true parent classes. Any non-abstract trait members are actually included in the inheriting class, as in physically part of the class. Well, not physically, but you get the picture. It’s as if the compiler performs a cut-and-paste with the non-abstract members and inserts them into the inheriting class. This means that there’s no ambiguity in the inheritance path, meaning no diamond problem. We can rewrite our CollegeStudent example in Scala without redundancy or fear of paradox:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Person {&lt;br /&gt;
  def schedule:Schedule&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Student extends Person {&lt;br /&gt;
  private var classSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = classSchedule&lt;br /&gt;
 &lt;br /&gt;
  def learn() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Worker extends Person {&lt;br /&gt;
  private var workSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = workSchedule&lt;br /&gt;
 &lt;br /&gt;
  def work() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class CollegeStudent(school:School, company:Company) extends Student with Worker {&lt;br /&gt;
  // ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if we make a call to the schedule method on an instance of CollegeStudent, the compiler knows that we’re referring to the implementation of schedule in the Worker trait.  This is because Worker was mixed in after the Student trait.  &lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Further reading =&lt;br /&gt;
# [http://vimeo.com/20293743 Video to learn about Scala]&lt;br /&gt;
# [http://docs.scala-lang.org/tutorials/ Scala Documentation]&lt;br /&gt;
# [http://shipilev.net/blog/2014/java-scala-divided-we-fail/#_analyzing_bottlenecks Java vs. Scala]&lt;br /&gt;
# [http://www.cs.uku.fi/~mnykanen/FOH/lectures1.pdf  Salient Features of Functional Programming]&lt;br /&gt;
# [https://www.cs.rpi.edu/research/pdf/10-04.pdf Comparison of Object-oriented and Functional Programming]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88432</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 9 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88432"/>
		<updated>2014-09-25T21:14:24Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Scala interoperates with Java and .NET */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Functional Programming?  =&lt;br /&gt;
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. The programming is done with the use of expressions, that is, it is a [http://en.wikipedia.org/wiki/Declarative_programming declarative programming] paradigm. One key feature in a functional language is the concept of [http://en.wikipedia.org/wiki/First-class_function first-class functions]. The idea is that you can pass functions as parameters to other functions and return them as values. Also, the output value of a function depends only on the arguments that are input to the function, unlike in [http://en.wikipedia.org/wiki/Imperative_programming imperative programming] languages. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behaviour of a program, which is one of the key motivations for the development of functional programming.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_programming&amp;lt;/ref&amp;gt;&lt;br /&gt;
Some examples of functional programming languages:&lt;br /&gt;
&lt;br /&gt;
*Common Lisp&lt;br /&gt;
*Scheme&lt;br /&gt;
*Erlang&lt;br /&gt;
*Haskell&lt;br /&gt;
&lt;br /&gt;
= What is Object Oriented Programming? =&lt;br /&gt;
Object-oriented programming (OOP) is based upon the concept of real world &amp;quot;objects&amp;quot;. These objects have data fields called attributes that describe the object and some procedures associated with them called methods. Object-oriented programming takes the view that what we really care about the objects we want to manipulate rather than the logic required to manipulate them.&lt;br /&gt;
&lt;br /&gt;
Some examples of object oriented programming languages are:&lt;br /&gt;
&lt;br /&gt;
*Simula&lt;br /&gt;
*Smalltalk&lt;br /&gt;
*C++&lt;br /&gt;
*Java&lt;br /&gt;
*C#&lt;br /&gt;
&lt;br /&gt;
= Features of Functional Programming&amp;lt;ref&amp;gt;http://en.wikibooks.org/wiki/Computer_Programming/Functional_programming&amp;lt;/ref&amp;gt; =&lt;br /&gt;
===&amp;lt;b&amp;gt;Higher-order functions:&amp;lt;/b&amp;gt;===&lt;br /&gt;
Higher-order functions (HOFs) are functions that take other functions as their arguments. A basic example of a HOF is map which takes a function and a list as its arguments, applies the function to all elements of the list, and returns the list of its results. Higher-order functions are very useful for refactoring code and reduce the amount of repetition.&lt;br /&gt;
Let’s see an example of a higher order function that receives a message, transforms it in various ways, and forwards it to another server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MessageHandler {&lt;br /&gt;
    	void handleMessage(Message msg, Function getClientCode) {&lt;br /&gt;
        	// ...&lt;br /&gt;
        	Message msg1 = msg.setClientCode(getClientCode());&lt;br /&gt;
        	// ...&lt;br /&gt;
        &lt;br /&gt;
        	sendMessage(msg1);&lt;br /&gt;
    	}&lt;br /&gt;
    &lt;br /&gt;
    	// ...&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeOne() {&lt;br /&gt;
    	return &amp;quot;ABCD_123&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeTwo() {&lt;br /&gt;
    	return &amp;quot;123_ABCD&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	MessageHandler handler = new MessageHandler();&lt;br /&gt;
	handler.handleMessage(someMsg, getClientCodeOne);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we see that we have created no new types and no class hierarchy. We simply pass appropriate functions as a parameter. We don't restrict ourselves to class hierarchies: we can pass new functions at runtime and change them at any time with a much higher degree of granularity with less code.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Purity&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.haskell.org/haskellwiki/Functional_programming&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Some functional languages allow expressions to yield actions in addition to return values. These actions are called side effects to emphasize that the return value is the most important outcome of a function (as opposed to the case in imperative programming). Languages that prohibit side effects are called pure. Even though some functional languages are impure they often contain a pure subset that is also useful as a programming language. It is usually beneficial to write a significant part of a functional program in a purely functional fashion and keep the code involving state and I/O to the minimum as impure code is more prone to errors.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutable data&amp;lt;/b&amp;gt;===&lt;br /&gt;
Purely functional programs typically operate on immutable data. Instead of altering existing values, altered copies are created and the original is preserved. Since the unchanged parts of the structure cannot be modified, they can often be shared between the old and new copies, which saves memory. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Referential transparency&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pure computations yield the same value each time they are invoked. This property is called referential transparency and makes possible to conduct equational reasoning on the code. For instance if &lt;br /&gt;
y = f x&lt;br /&gt;
and &lt;br /&gt;
g = h y y&lt;br /&gt;
then we should be able to replace the definition of &lt;br /&gt;
g&lt;br /&gt;
with &lt;br /&gt;
g = h (f x) (f x)&lt;br /&gt;
and get the same result; only the efficiency might change.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Lazy evaluation&amp;lt;/b&amp;gt;===&lt;br /&gt;
Since pure computations are referentially transparent they can be performed at any time and still yield the same result. This makes it possible to defer the computation of values until they are needed, that is, to compute them lazily. [http://en.wikipedia.org/wiki/Lazy_evaluation Lazy evaluation] avoids unnecessary computations and allows, for example, infinite data structures to be defined and used. &lt;br /&gt;
Let’s take a look at the following piece of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String s1 = somewhatLongOperation1();&lt;br /&gt;
String s2 = somewhatLongOperation2();&lt;br /&gt;
String s3 = concatenate(s1, s2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an imperative language the order of evaluation would be clear. Because each function may affect or depend on an external state it would be necessary to execute them in order: first somewhatLongOperation1, then somewhatLongOperation2, followed by concatenate. Not so in functional languages. somewhatLongOperation1 and somewhatLongOperation2 can be executed concurrently because we're guaranteed no function affects or depends on global state. But what if we don't want to run the two concurrently, do we need to run them in order? The answer is no. We only need to run these operations when another function depends on s1 and s2. We don't even have to run them before concatenate is called - we can delay their evaluation until they're required within concatenate. If we replace concatenate with a function that has a conditional and uses only one of its two parameters we may never evaluate one of the parameters at all!&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
[http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html Recursion] is heavily used in functional programming as it is the canonical and often the only way to iterate. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?PatternMatching&amp;lt;/ref&amp;gt;===&lt;br /&gt;
In the context of pure functional languages, [http://en.wikipedia.org/wiki/Pattern_matching Pattern Matching] is a dispatch mechanism: choosing which variant of a function is the correct one to call. Example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        factorial(0) ::= 1&lt;br /&gt;
	factorial(n) ::= n * factorial(n-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The function has been given two definitions. Which is used for dispatch when a call is made will depend, in this case, on whether the actual parameter pattern matches 0 or not. The matching is not limited to constants; in general, functions have a [http://en.wikipedia.org/wiki/Type_signature TypeSignature] used for matching. [http://en.wikipedia.org/wiki/Currying Currying] is integrated into this mechanism. &lt;br /&gt;
1.Pattern matching is the compiler's ability to compare both the form and the content of two expressions. It is used in two ways:&lt;br /&gt;
All or part of a data structure may be assigned to one or several variables in a single expression. &lt;br /&gt;
2.A function may have several definitions (clauses), according to the form and/or content of its arguments. This second use is usually combined with the first to initialize the variables that will be used in the clause. &lt;br /&gt;
In both these uses, a pattern match has the additional benefit of making an assertion about the form and/or content of a variable.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Closures&amp;lt;/b&amp;gt;===&lt;br /&gt;
Passing functions around in impure languages is a little bit different than doing it in the confines of lambda calculus and requires support for an interesting feature often referred to as [https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Closure_(computer_science).html lexical closure]. Let's take a look at some sample code. Remember, in this case variables aren't final and functions can refer to variables outside of their scope:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Function makePowerFn(int power) {&lt;br /&gt;
   int powerFn(int base) {&lt;br /&gt;
       return pow(base, power);&lt;br /&gt;
   }&lt;br /&gt;
   return powerFn;&lt;br /&gt;
}&lt;br /&gt;
Function square = makePowerFn(2);&lt;br /&gt;
square(3); // returns 9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function makePowerFn returns a function that takes a single argument and raises it to a certain power. What happens when we try to evaluate square(3)? The variable power isn't anywhere in scope of powerFn because makePowerFn has returned and its stack is long gone. How can square work, then? The language must, somehow, store the value of power somewhere for square to work. What if we create another function, cube, that raises something to the third power? The runtime must now store two copies of power, one for each function we generated using makePowerFn. The phenomenon of storing these values is called a closure.&lt;br /&gt;
&lt;br /&gt;
= Comparison between Functional Programming and OOP &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w25_aras&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Let us compare both the programming paradigms with respect to several disctinction attributes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Point of Comparison&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functional Languages&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Object-Oriented Languages&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Primary focus&amp;lt;/b&amp;gt;&lt;br /&gt;
| Functional programming emphasizes on functions that produce results which depend only on their inputs and not on the program state - i.e. pure mathematial functions. || Focus on identifying and''' representing the problem in terms of an 'object'''' which has its own data, sub-routines and state. Different objects in the problem interact by sending messages to each other and thus result in change in its internal state. The final state and values of the objects refer to the solution. It is '''data-centric'''.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Problem Solving Approach&amp;lt;/b&amp;gt;&lt;br /&gt;
| Primarily''' Top-down''' design || '''Identification and design of necessary objects'''. Close to being 'better models of the way the world works'.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Program Flow&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Often sequential''' with program having single point of entry and exit. || '''Complex''' program flow. Can sometimes depend on the internal state of the objects.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Modularity&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Limited modularity'''. Program is divided into modules or per say procedures independent of each other but are constrained due to uniqueness to that particular problem. || '''Extremely modular''' due to the presence of objects which contain their own data and sub-routines.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Data Protection/Hiding&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''No concept of data-hiding'''. Variables local to one method cannot be accessed by other method. But, Global variables can be accessed anywhere within the program. || One of the main fundamentals of O-O languages.''' Access specifiers''' like 'public', 'private' and 'protected' dictate the rules of data-hiding. Data which is private is confined to one object and cannot be directly changed by any other method except its own. This places the responsibility of managing data with the object itself This is called as ownership. Thus, data can be accessed ( read/write/modified )''' only''' through the object's own interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Ease of Understanding&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Smaller programs''' are '''easy to understand''' but as the program increases in size; understanding the code becomes more and more difficult. || '''Easy to understand''' due to its real world-like design and flow.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Reuse of Code&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Very Limited or no''' code re-usability. ||'''Highly re-usable code''' as the code developed can be easily modified or extended to suit a problem's need.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Support for declaring new data types/classes&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Difficult '''due to limited in-built functionality. || '''Easily possible''' due to the concept of classes. Generic classes can be built as per the required specifications.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Efficiency&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Efficient''' for solving '''small''' problems. || '''Efficient''' for solving '''large problems''' which have a complex structure and require complex data-types, abstraction and data-security.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintenance&amp;lt;/b&amp;gt;&lt;br /&gt;
| Maintenance is''' easy for smaller programs''' but can consume''' a-lot of effort for larger program''' size as it requires the programmer to know and understand the dependencies of every module in the program. This makes it difficult to debug and test the program. ||'''Extremely simple''' as O-O languages aim for high modularity. Secondly, programmer is not concerned with the details of how the data is stored and represented. Thirdly, they also tend to keep low coupling which makes it easy to debug and test different modules in the program.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less Extensible''' as modules developed need to be re-organised and re-structured heavily in order to meet different needs. || '''High extensibility''' is one of the most important advantages of OOP. Code can be easily modified and 'plugged-in' to a different program. Methods can be exteneded due to many properties such as polymorphism, inheritance and support for multiple inheritance through interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Flexibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less flexible.''' Sometimes, certain problems do not fit into the 'top-down design' approach. || '''High flexibility.''' The modelling of problems into world-like objects makes it easy to solve any practical problem.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Examples&amp;lt;/b&amp;gt;&lt;br /&gt;
| [http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell], [http://en.wikipedia.org/wiki/Scala_%28programming_language%29 Scala], [http://en.wikipedia.org/wiki/Erlang_%28programming_language%29 Erlang] || [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], [http://en.wikipedia.org/wiki/Python_(programming_language) Python].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Scala : An overview  &amp;lt;ref&amp;gt;http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html&amp;lt;/ref&amp;gt;=&lt;br /&gt;
Scala is an object-functional programming and scripting language generallly used in software applications. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.) and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than most general purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.&lt;br /&gt;
&lt;br /&gt;
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries can be used directly in Scala code, and vice versa. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
object HelloWorld &lt;br /&gt;
{&lt;br /&gt;
   def main(args: Array[String]) &lt;br /&gt;
  {&lt;br /&gt;
    println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program consists of one method called main which takes the command line arguments, an array of strings, as parameter; the body of this method consists of a single call to the predefined method println with the greeting as argument. The main method does not return a value (it is a procedure method). Therefore, it is not necessary to declare a return type. Such a declaration introduces what is commonly known as a singleton object, that is a class with a single instance. The declaration above thus declares both a class called HelloWorld and an instance of that class, also called HelloWorld. This instance is created on demand, the first time it is used. Notice that the main method is not declared as static (like in Java) here. This is because static members (methods or fields) do not exist in Scala. Rather than defining static members, the Scala programmer declares these members in singleton objects.&lt;br /&gt;
&lt;br /&gt;
= Features of Scala &amp;lt;ref&amp;gt;http://www.scala-lang.org/old/node/104&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is object-oriented&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is functional&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.&lt;br /&gt;
Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of right-ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is statically typed&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. &lt;br /&gt;
In particular, the type system supports:&lt;br /&gt;
generic classes, variance annotations, upper and lower type bounds, inner classes and abstract types as object members, compound types, explicitly typed self references, views, and polymorphic methods.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is extensible&amp;lt;/b&amp;gt;===&lt;br /&gt;
In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:&lt;br /&gt;
any method may be used as an infix or postfix operator, and&lt;br /&gt;
closures are constructed automatically depending on the expected type (target typing). A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala interoperates with Java and .NET&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is designed to interoperate well with the popular Java 2 Runtime Environment ([http://docs.oracle.com/javase/7/docs/JRE]) . In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available.&lt;br /&gt;
&lt;br /&gt;
= Similarities between Scala and Java =&lt;br /&gt;
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy,JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.&lt;br /&gt;
&lt;br /&gt;
2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.&lt;br /&gt;
&lt;br /&gt;
3) Major Java programming IDE like [http://www.eclipse.org/documentation/ Eclipse],[https://netbeans.org/kb/ Netbeans] and [http://www.jetbrains.com/idea/ InetelliJ] supports Scala.&lt;br /&gt;
&lt;br /&gt;
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.&lt;br /&gt;
&lt;br /&gt;
= Scala vs JAVA &amp;lt;ref&amp;gt;http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Syntactic flexibility &amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala has a very powerful and flexible syntax as it relates to methods, both declaration and invocation. In Java you can create methods with different visibilities, modifiers and return types. Scala does allow for different visibilities on not just methods, but any members. &lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person {&lt;br /&gt;
  private var name = &amp;quot;Daniel Spiewak&amp;quot;&lt;br /&gt;
  val ssn = 1234567890    // public constant field&lt;br /&gt;
 &lt;br /&gt;
  def firstName() = splitName()(0)   // public method&lt;br /&gt;
 &lt;br /&gt;
  private def splitName() = name.split(&amp;quot; &amp;quot;)    // private method&lt;br /&gt;
 &lt;br /&gt;
  protected def guessAge() = {&lt;br /&gt;
    import Math._&lt;br /&gt;
    round(random * 20)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala provides the option to import into a specific scope. The import statement within guessAge()is much like a Java static import statement which only provides access to the Math members within theguessAge() method. So we couldn’t just make a call to round() from within the splitName() method.&lt;br /&gt;
Scala access modifiers are also quite a bit more powerful than Java’s. For example,protected by default limits access to only subclasses, unlike Java which also allows access to other classes in the same package.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Unified type system&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). Only reference types are part of the inheritance scheme, deriving from java.lang.Object. In Scala, however, all types inherit from a top-level class Any, whose immediate children are AnyVal(value types, such as Int and Boolean) andAnyRef (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala; boxing and unboxing is completely transparent to the user. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;For-expressions&amp;lt;/b&amp;gt;===&lt;br /&gt;
Instead of the Java &amp;quot;foreach&amp;quot; loops for looping through an iterator, Scala has a much more powerful concept of for-expressions. These are similar to list comprehensions in languages such as Haskell, or a combination of list comprehensions and generator expressions in Python. For-expressions using the yield keyword allow a new collection to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of map, flatMap and filter calls. Where yield is not used, the code approximates to an imperative-style loop, by translating to foreach. A simple example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val s = for (x &amp;lt;- 1 to 25 if x*x &amp;gt; 50) yield 2*x&lt;br /&gt;
The result of running it is the following vector:&lt;br /&gt;
Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Everything is an expression&amp;lt;/b&amp;gt;===&lt;br /&gt;
Unlike C or Java, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning void in Java, and statements like while that logically do not return a value, are in Scala considered to return the type Unit, which is a singleton type, with only one object of that type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Java:&lt;br /&gt;
int hexDigit = x &amp;gt;= 10 ? x + 'A' - 10 : x + '0';&lt;br /&gt;
&lt;br /&gt;
//Scala: &lt;br /&gt;
val hexDigit = if (x &amp;gt;= 10) x + 'A' - 10 else x + '0'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Type inference&amp;lt;/b&amp;gt;===&lt;br /&gt;
Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = &amp;quot;foo&amp;quot; (for an immutable, constant variable or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Anonymous functions&amp;lt;/b&amp;gt;===&lt;br /&gt;
In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x =&amp;gt; x &amp;lt; 2, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. &lt;br /&gt;
&lt;br /&gt;
An even shorter form of anonymous function uses placeholder variables: For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list map { x =&amp;gt; sqrt(x) }&lt;br /&gt;
&lt;br /&gt;
can be written more concisely as&lt;br /&gt;
&lt;br /&gt;
list map { sqrt(_) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutability&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with val while mutable variables use var. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Tail recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround. Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released July 14, 2010).&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pattern matching in Scala is really a lot like Java’s switch/case construct.  So in Java, one might write something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public boolean checkPrime(int number) {&lt;br /&gt;
    // checks if a number between 1 and 10 is prime&lt;br /&gt;
    switch (number) {&lt;br /&gt;
        case 1: return true;&lt;br /&gt;
        case 2: return true;&lt;br /&gt;
        case 3: return true;&lt;br /&gt;
        case 5: return true;&lt;br /&gt;
        case 7: return true;&lt;br /&gt;
 &lt;br /&gt;
        default: return false;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the major limitations of switch/case in Java  is that it can only be used on primitives.  You can’t use switch/case to test a String, for example (a need which arises more often than one would think).  In fact, the most complex type testable within switch/case is the Enum, and even this is just being reduced to its ordinal values under the surface.&lt;br /&gt;
The designers of Scala chose not to include this “feature” in their new language. Instead, they implemented a “new” concept called pattern matching. At a basic level, it allows algorithms which are very similar to the checkPrime(int) example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def checkPrime(number:Int):Boolean = {&lt;br /&gt;
  number match {&lt;br /&gt;
    case 1 =&amp;gt; return true&lt;br /&gt;
    case 2 =&amp;gt; return true&lt;br /&gt;
    case 3 =&amp;gt; return true&lt;br /&gt;
    case 5 =&amp;gt; return true&lt;br /&gt;
    case 7 =&amp;gt; return true&lt;br /&gt;
 &lt;br /&gt;
    case _ =&amp;gt; return false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The biggest difference which likely jumps out at you is the lack of a default statement. Instead, we see the return of Scala’s ubiquitous wildcard character, the underscore. Literally read, this example means: match the value within number; in the case that it is 1, return true; in the case that it is 2, return true; …; for any previously unmatched value, return false.&lt;br /&gt;
Scala case statements can’t “overflow” into each-other (causing multiple matches) like Java’s can, so even if we weren’t returning values, the algorithm would still be safe.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java’s designers recognized the need for multiple typing (e.g. CollegeStudent is both a Student and a Worker), but they wanted to avoid the issues associated with inheriting conflicting method definitions along multiple paths.  Their solution was to design the interface mechanism, a feature which allows multiple typing without the complications of multiple inheritance.  &lt;br /&gt;
Scala recognizes that interfaces have their issues.  So rather than blinding creating a reimplementation of the same problems found in either Java or C++, Scala takes a new approach.  Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
trait Book &lt;br /&gt;
{&lt;br /&gt;
  def title:String&lt;br /&gt;
  def title_=(n:String):Unit&lt;br /&gt;
 &lt;br /&gt;
  def computePrice = title.length * 10&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala’s traits are quite nice in that they can not only define abstract members, but also full method definitions. At the same time, they allow inheriting classes to inherit from more than one trait. They pass on their type information and implementations to their children, as well as enforcing the abstract members. At first glance, this seems like it would be just as bad as straight-up multiple inheritance, but it turns out the problems have been mitigated in some very clever ways.&lt;br /&gt;
Traits are actually mixins, not true parent classes. Any non-abstract trait members are actually included in the inheriting class, as in physically part of the class. Well, not physically, but you get the picture. It’s as if the compiler performs a cut-and-paste with the non-abstract members and inserts them into the inheriting class. This means that there’s no ambiguity in the inheritance path, meaning no diamond problem. We can rewrite our CollegeStudent example in Scala without redundancy or fear of paradox:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Person {&lt;br /&gt;
  def schedule:Schedule&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Student extends Person {&lt;br /&gt;
  private var classSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = classSchedule&lt;br /&gt;
 &lt;br /&gt;
  def learn() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Worker extends Person {&lt;br /&gt;
  private var workSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = workSchedule&lt;br /&gt;
 &lt;br /&gt;
  def work() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class CollegeStudent(school:School, company:Company) extends Student with Worker {&lt;br /&gt;
  // ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if we make a call to the schedule method on an instance of CollegeStudent, the compiler knows that we’re referring to the implementation of schedule in the Worker trait.  This is because Worker was mixed in after the Student trait.  &lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Further reading =&lt;br /&gt;
# [http://vimeo.com/20293743 Video to learn about Scala]&lt;br /&gt;
# [http://docs.scala-lang.org/tutorials/ Scala Documentation]&lt;br /&gt;
# [http://shipilev.net/blog/2014/java-scala-divided-we-fail/#_analyzing_bottlenecks Java vs. Scala]&lt;br /&gt;
# [http://www.cs.uku.fi/~mnykanen/FOH/lectures1.pdf  Salient Features of Functional Programming]&lt;br /&gt;
# [https://www.cs.rpi.edu/research/pdf/10-04.pdf Comparison of Object-oriented and Functional Programming]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88430</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 9 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88430"/>
		<updated>2014-09-25T21:13:34Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Similarities between Scala and Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Functional Programming?  =&lt;br /&gt;
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. The programming is done with the use of expressions, that is, it is a [http://en.wikipedia.org/wiki/Declarative_programming declarative programming] paradigm. One key feature in a functional language is the concept of [http://en.wikipedia.org/wiki/First-class_function first-class functions]. The idea is that you can pass functions as parameters to other functions and return them as values. Also, the output value of a function depends only on the arguments that are input to the function, unlike in [http://en.wikipedia.org/wiki/Imperative_programming imperative programming] languages. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behaviour of a program, which is one of the key motivations for the development of functional programming.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_programming&amp;lt;/ref&amp;gt;&lt;br /&gt;
Some examples of functional programming languages:&lt;br /&gt;
&lt;br /&gt;
*Common Lisp&lt;br /&gt;
*Scheme&lt;br /&gt;
*Erlang&lt;br /&gt;
*Haskell&lt;br /&gt;
&lt;br /&gt;
= What is Object Oriented Programming? =&lt;br /&gt;
Object-oriented programming (OOP) is based upon the concept of real world &amp;quot;objects&amp;quot;. These objects have data fields called attributes that describe the object and some procedures associated with them called methods. Object-oriented programming takes the view that what we really care about the objects we want to manipulate rather than the logic required to manipulate them.&lt;br /&gt;
&lt;br /&gt;
Some examples of object oriented programming languages are:&lt;br /&gt;
&lt;br /&gt;
*Simula&lt;br /&gt;
*Smalltalk&lt;br /&gt;
*C++&lt;br /&gt;
*Java&lt;br /&gt;
*C#&lt;br /&gt;
&lt;br /&gt;
= Features of Functional Programming&amp;lt;ref&amp;gt;http://en.wikibooks.org/wiki/Computer_Programming/Functional_programming&amp;lt;/ref&amp;gt; =&lt;br /&gt;
===&amp;lt;b&amp;gt;Higher-order functions:&amp;lt;/b&amp;gt;===&lt;br /&gt;
Higher-order functions (HOFs) are functions that take other functions as their arguments. A basic example of a HOF is map which takes a function and a list as its arguments, applies the function to all elements of the list, and returns the list of its results. Higher-order functions are very useful for refactoring code and reduce the amount of repetition.&lt;br /&gt;
Let’s see an example of a higher order function that receives a message, transforms it in various ways, and forwards it to another server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MessageHandler {&lt;br /&gt;
    	void handleMessage(Message msg, Function getClientCode) {&lt;br /&gt;
        	// ...&lt;br /&gt;
        	Message msg1 = msg.setClientCode(getClientCode());&lt;br /&gt;
        	// ...&lt;br /&gt;
        &lt;br /&gt;
        	sendMessage(msg1);&lt;br /&gt;
    	}&lt;br /&gt;
    &lt;br /&gt;
    	// ...&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeOne() {&lt;br /&gt;
    	return &amp;quot;ABCD_123&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeTwo() {&lt;br /&gt;
    	return &amp;quot;123_ABCD&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	MessageHandler handler = new MessageHandler();&lt;br /&gt;
	handler.handleMessage(someMsg, getClientCodeOne);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we see that we have created no new types and no class hierarchy. We simply pass appropriate functions as a parameter. We don't restrict ourselves to class hierarchies: we can pass new functions at runtime and change them at any time with a much higher degree of granularity with less code.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Purity&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.haskell.org/haskellwiki/Functional_programming&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Some functional languages allow expressions to yield actions in addition to return values. These actions are called side effects to emphasize that the return value is the most important outcome of a function (as opposed to the case in imperative programming). Languages that prohibit side effects are called pure. Even though some functional languages are impure they often contain a pure subset that is also useful as a programming language. It is usually beneficial to write a significant part of a functional program in a purely functional fashion and keep the code involving state and I/O to the minimum as impure code is more prone to errors.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutable data&amp;lt;/b&amp;gt;===&lt;br /&gt;
Purely functional programs typically operate on immutable data. Instead of altering existing values, altered copies are created and the original is preserved. Since the unchanged parts of the structure cannot be modified, they can often be shared between the old and new copies, which saves memory. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Referential transparency&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pure computations yield the same value each time they are invoked. This property is called referential transparency and makes possible to conduct equational reasoning on the code. For instance if &lt;br /&gt;
y = f x&lt;br /&gt;
and &lt;br /&gt;
g = h y y&lt;br /&gt;
then we should be able to replace the definition of &lt;br /&gt;
g&lt;br /&gt;
with &lt;br /&gt;
g = h (f x) (f x)&lt;br /&gt;
and get the same result; only the efficiency might change.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Lazy evaluation&amp;lt;/b&amp;gt;===&lt;br /&gt;
Since pure computations are referentially transparent they can be performed at any time and still yield the same result. This makes it possible to defer the computation of values until they are needed, that is, to compute them lazily. [http://en.wikipedia.org/wiki/Lazy_evaluation Lazy evaluation] avoids unnecessary computations and allows, for example, infinite data structures to be defined and used. &lt;br /&gt;
Let’s take a look at the following piece of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String s1 = somewhatLongOperation1();&lt;br /&gt;
String s2 = somewhatLongOperation2();&lt;br /&gt;
String s3 = concatenate(s1, s2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an imperative language the order of evaluation would be clear. Because each function may affect or depend on an external state it would be necessary to execute them in order: first somewhatLongOperation1, then somewhatLongOperation2, followed by concatenate. Not so in functional languages. somewhatLongOperation1 and somewhatLongOperation2 can be executed concurrently because we're guaranteed no function affects or depends on global state. But what if we don't want to run the two concurrently, do we need to run them in order? The answer is no. We only need to run these operations when another function depends on s1 and s2. We don't even have to run them before concatenate is called - we can delay their evaluation until they're required within concatenate. If we replace concatenate with a function that has a conditional and uses only one of its two parameters we may never evaluate one of the parameters at all!&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
[http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html Recursion] is heavily used in functional programming as it is the canonical and often the only way to iterate. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?PatternMatching&amp;lt;/ref&amp;gt;===&lt;br /&gt;
In the context of pure functional languages, [http://en.wikipedia.org/wiki/Pattern_matching Pattern Matching] is a dispatch mechanism: choosing which variant of a function is the correct one to call. Example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        factorial(0) ::= 1&lt;br /&gt;
	factorial(n) ::= n * factorial(n-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The function has been given two definitions. Which is used for dispatch when a call is made will depend, in this case, on whether the actual parameter pattern matches 0 or not. The matching is not limited to constants; in general, functions have a [http://en.wikipedia.org/wiki/Type_signature TypeSignature] used for matching. [http://en.wikipedia.org/wiki/Currying Currying] is integrated into this mechanism. &lt;br /&gt;
1.Pattern matching is the compiler's ability to compare both the form and the content of two expressions. It is used in two ways:&lt;br /&gt;
All or part of a data structure may be assigned to one or several variables in a single expression. &lt;br /&gt;
2.A function may have several definitions (clauses), according to the form and/or content of its arguments. This second use is usually combined with the first to initialize the variables that will be used in the clause. &lt;br /&gt;
In both these uses, a pattern match has the additional benefit of making an assertion about the form and/or content of a variable.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Closures&amp;lt;/b&amp;gt;===&lt;br /&gt;
Passing functions around in impure languages is a little bit different than doing it in the confines of lambda calculus and requires support for an interesting feature often referred to as [https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Closure_(computer_science).html lexical closure]. Let's take a look at some sample code. Remember, in this case variables aren't final and functions can refer to variables outside of their scope:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Function makePowerFn(int power) {&lt;br /&gt;
   int powerFn(int base) {&lt;br /&gt;
       return pow(base, power);&lt;br /&gt;
   }&lt;br /&gt;
   return powerFn;&lt;br /&gt;
}&lt;br /&gt;
Function square = makePowerFn(2);&lt;br /&gt;
square(3); // returns 9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function makePowerFn returns a function that takes a single argument and raises it to a certain power. What happens when we try to evaluate square(3)? The variable power isn't anywhere in scope of powerFn because makePowerFn has returned and its stack is long gone. How can square work, then? The language must, somehow, store the value of power somewhere for square to work. What if we create another function, cube, that raises something to the third power? The runtime must now store two copies of power, one for each function we generated using makePowerFn. The phenomenon of storing these values is called a closure.&lt;br /&gt;
&lt;br /&gt;
= Comparison between Functional Programming and OOP &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w25_aras&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Let us compare both the programming paradigms with respect to several disctinction attributes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Point of Comparison&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functional Languages&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Object-Oriented Languages&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Primary focus&amp;lt;/b&amp;gt;&lt;br /&gt;
| Functional programming emphasizes on functions that produce results which depend only on their inputs and not on the program state - i.e. pure mathematial functions. || Focus on identifying and''' representing the problem in terms of an 'object'''' which has its own data, sub-routines and state. Different objects in the problem interact by sending messages to each other and thus result in change in its internal state. The final state and values of the objects refer to the solution. It is '''data-centric'''.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Problem Solving Approach&amp;lt;/b&amp;gt;&lt;br /&gt;
| Primarily''' Top-down''' design || '''Identification and design of necessary objects'''. Close to being 'better models of the way the world works'.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Program Flow&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Often sequential''' with program having single point of entry and exit. || '''Complex''' program flow. Can sometimes depend on the internal state of the objects.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Modularity&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Limited modularity'''. Program is divided into modules or per say procedures independent of each other but are constrained due to uniqueness to that particular problem. || '''Extremely modular''' due to the presence of objects which contain their own data and sub-routines.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Data Protection/Hiding&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''No concept of data-hiding'''. Variables local to one method cannot be accessed by other method. But, Global variables can be accessed anywhere within the program. || One of the main fundamentals of O-O languages.''' Access specifiers''' like 'public', 'private' and 'protected' dictate the rules of data-hiding. Data which is private is confined to one object and cannot be directly changed by any other method except its own. This places the responsibility of managing data with the object itself This is called as ownership. Thus, data can be accessed ( read/write/modified )''' only''' through the object's own interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Ease of Understanding&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Smaller programs''' are '''easy to understand''' but as the program increases in size; understanding the code becomes more and more difficult. || '''Easy to understand''' due to its real world-like design and flow.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Reuse of Code&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Very Limited or no''' code re-usability. ||'''Highly re-usable code''' as the code developed can be easily modified or extended to suit a problem's need.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Support for declaring new data types/classes&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Difficult '''due to limited in-built functionality. || '''Easily possible''' due to the concept of classes. Generic classes can be built as per the required specifications.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Efficiency&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Efficient''' for solving '''small''' problems. || '''Efficient''' for solving '''large problems''' which have a complex structure and require complex data-types, abstraction and data-security.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintenance&amp;lt;/b&amp;gt;&lt;br /&gt;
| Maintenance is''' easy for smaller programs''' but can consume''' a-lot of effort for larger program''' size as it requires the programmer to know and understand the dependencies of every module in the program. This makes it difficult to debug and test the program. ||'''Extremely simple''' as O-O languages aim for high modularity. Secondly, programmer is not concerned with the details of how the data is stored and represented. Thirdly, they also tend to keep low coupling which makes it easy to debug and test different modules in the program.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less Extensible''' as modules developed need to be re-organised and re-structured heavily in order to meet different needs. || '''High extensibility''' is one of the most important advantages of OOP. Code can be easily modified and 'plugged-in' to a different program. Methods can be exteneded due to many properties such as polymorphism, inheritance and support for multiple inheritance through interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Flexibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less flexible.''' Sometimes, certain problems do not fit into the 'top-down design' approach. || '''High flexibility.''' The modelling of problems into world-like objects makes it easy to solve any practical problem.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Examples&amp;lt;/b&amp;gt;&lt;br /&gt;
| [http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell], [http://en.wikipedia.org/wiki/Scala_%28programming_language%29 Scala], [http://en.wikipedia.org/wiki/Erlang_%28programming_language%29 Erlang] || [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], [http://en.wikipedia.org/wiki/Python_(programming_language) Python].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Scala : An overview  &amp;lt;ref&amp;gt;http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html&amp;lt;/ref&amp;gt;=&lt;br /&gt;
Scala is an object-functional programming and scripting language generallly used in software applications. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.) and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than most general purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.&lt;br /&gt;
&lt;br /&gt;
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries can be used directly in Scala code, and vice versa. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
object HelloWorld &lt;br /&gt;
{&lt;br /&gt;
   def main(args: Array[String]) &lt;br /&gt;
  {&lt;br /&gt;
    println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program consists of one method called main which takes the command line arguments, an array of strings, as parameter; the body of this method consists of a single call to the predefined method println with the greeting as argument. The main method does not return a value (it is a procedure method). Therefore, it is not necessary to declare a return type. Such a declaration introduces what is commonly known as a singleton object, that is a class with a single instance. The declaration above thus declares both a class called HelloWorld and an instance of that class, also called HelloWorld. This instance is created on demand, the first time it is used. Notice that the main method is not declared as static (like in Java) here. This is because static members (methods or fields) do not exist in Scala. Rather than defining static members, the Scala programmer declares these members in singleton objects.&lt;br /&gt;
&lt;br /&gt;
= Features of Scala &amp;lt;ref&amp;gt;http://www.scala-lang.org/old/node/104&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is object-oriented&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is functional&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.&lt;br /&gt;
Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of right-ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is statically typed&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. &lt;br /&gt;
In particular, the type system supports:&lt;br /&gt;
generic classes, variance annotations, upper and lower type bounds, inner classes and abstract types as object members, compound types, explicitly typed self references, views, and polymorphic methods.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is extensible&amp;lt;/b&amp;gt;===&lt;br /&gt;
In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:&lt;br /&gt;
any method may be used as an infix or postfix operator, and&lt;br /&gt;
closures are constructed automatically depending on the expected type (target typing). A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala interoperates with Java and .NET&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available.&lt;br /&gt;
&lt;br /&gt;
= Similarities between Scala and Java =&lt;br /&gt;
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy,JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.&lt;br /&gt;
&lt;br /&gt;
2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.&lt;br /&gt;
&lt;br /&gt;
3) Major Java programming IDE like [http://www.eclipse.org/documentation/ Eclipse],[https://netbeans.org/kb/ Netbeans] and [http://www.jetbrains.com/idea/ InetelliJ] supports Scala.&lt;br /&gt;
&lt;br /&gt;
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.&lt;br /&gt;
&lt;br /&gt;
= Scala vs JAVA &amp;lt;ref&amp;gt;http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Syntactic flexibility &amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala has a very powerful and flexible syntax as it relates to methods, both declaration and invocation. In Java you can create methods with different visibilities, modifiers and return types. Scala does allow for different visibilities on not just methods, but any members. &lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person {&lt;br /&gt;
  private var name = &amp;quot;Daniel Spiewak&amp;quot;&lt;br /&gt;
  val ssn = 1234567890    // public constant field&lt;br /&gt;
 &lt;br /&gt;
  def firstName() = splitName()(0)   // public method&lt;br /&gt;
 &lt;br /&gt;
  private def splitName() = name.split(&amp;quot; &amp;quot;)    // private method&lt;br /&gt;
 &lt;br /&gt;
  protected def guessAge() = {&lt;br /&gt;
    import Math._&lt;br /&gt;
    round(random * 20)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala provides the option to import into a specific scope. The import statement within guessAge()is much like a Java static import statement which only provides access to the Math members within theguessAge() method. So we couldn’t just make a call to round() from within the splitName() method.&lt;br /&gt;
Scala access modifiers are also quite a bit more powerful than Java’s. For example,protected by default limits access to only subclasses, unlike Java which also allows access to other classes in the same package.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Unified type system&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). Only reference types are part of the inheritance scheme, deriving from java.lang.Object. In Scala, however, all types inherit from a top-level class Any, whose immediate children are AnyVal(value types, such as Int and Boolean) andAnyRef (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala; boxing and unboxing is completely transparent to the user. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;For-expressions&amp;lt;/b&amp;gt;===&lt;br /&gt;
Instead of the Java &amp;quot;foreach&amp;quot; loops for looping through an iterator, Scala has a much more powerful concept of for-expressions. These are similar to list comprehensions in languages such as Haskell, or a combination of list comprehensions and generator expressions in Python. For-expressions using the yield keyword allow a new collection to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of map, flatMap and filter calls. Where yield is not used, the code approximates to an imperative-style loop, by translating to foreach. A simple example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val s = for (x &amp;lt;- 1 to 25 if x*x &amp;gt; 50) yield 2*x&lt;br /&gt;
The result of running it is the following vector:&lt;br /&gt;
Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Everything is an expression&amp;lt;/b&amp;gt;===&lt;br /&gt;
Unlike C or Java, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning void in Java, and statements like while that logically do not return a value, are in Scala considered to return the type Unit, which is a singleton type, with only one object of that type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Java:&lt;br /&gt;
int hexDigit = x &amp;gt;= 10 ? x + 'A' - 10 : x + '0';&lt;br /&gt;
&lt;br /&gt;
//Scala: &lt;br /&gt;
val hexDigit = if (x &amp;gt;= 10) x + 'A' - 10 else x + '0'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Type inference&amp;lt;/b&amp;gt;===&lt;br /&gt;
Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = &amp;quot;foo&amp;quot; (for an immutable, constant variable or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Anonymous functions&amp;lt;/b&amp;gt;===&lt;br /&gt;
In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x =&amp;gt; x &amp;lt; 2, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. &lt;br /&gt;
&lt;br /&gt;
An even shorter form of anonymous function uses placeholder variables: For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list map { x =&amp;gt; sqrt(x) }&lt;br /&gt;
&lt;br /&gt;
can be written more concisely as&lt;br /&gt;
&lt;br /&gt;
list map { sqrt(_) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutability&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with val while mutable variables use var. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Tail recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround. Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released July 14, 2010).&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pattern matching in Scala is really a lot like Java’s switch/case construct.  So in Java, one might write something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public boolean checkPrime(int number) {&lt;br /&gt;
    // checks if a number between 1 and 10 is prime&lt;br /&gt;
    switch (number) {&lt;br /&gt;
        case 1: return true;&lt;br /&gt;
        case 2: return true;&lt;br /&gt;
        case 3: return true;&lt;br /&gt;
        case 5: return true;&lt;br /&gt;
        case 7: return true;&lt;br /&gt;
 &lt;br /&gt;
        default: return false;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the major limitations of switch/case in Java  is that it can only be used on primitives.  You can’t use switch/case to test a String, for example (a need which arises more often than one would think).  In fact, the most complex type testable within switch/case is the Enum, and even this is just being reduced to its ordinal values under the surface.&lt;br /&gt;
The designers of Scala chose not to include this “feature” in their new language. Instead, they implemented a “new” concept called pattern matching. At a basic level, it allows algorithms which are very similar to the checkPrime(int) example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def checkPrime(number:Int):Boolean = {&lt;br /&gt;
  number match {&lt;br /&gt;
    case 1 =&amp;gt; return true&lt;br /&gt;
    case 2 =&amp;gt; return true&lt;br /&gt;
    case 3 =&amp;gt; return true&lt;br /&gt;
    case 5 =&amp;gt; return true&lt;br /&gt;
    case 7 =&amp;gt; return true&lt;br /&gt;
 &lt;br /&gt;
    case _ =&amp;gt; return false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The biggest difference which likely jumps out at you is the lack of a default statement. Instead, we see the return of Scala’s ubiquitous wildcard character, the underscore. Literally read, this example means: match the value within number; in the case that it is 1, return true; in the case that it is 2, return true; …; for any previously unmatched value, return false.&lt;br /&gt;
Scala case statements can’t “overflow” into each-other (causing multiple matches) like Java’s can, so even if we weren’t returning values, the algorithm would still be safe.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java’s designers recognized the need for multiple typing (e.g. CollegeStudent is both a Student and a Worker), but they wanted to avoid the issues associated with inheriting conflicting method definitions along multiple paths.  Their solution was to design the interface mechanism, a feature which allows multiple typing without the complications of multiple inheritance.  &lt;br /&gt;
Scala recognizes that interfaces have their issues.  So rather than blinding creating a reimplementation of the same problems found in either Java or C++, Scala takes a new approach.  Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
trait Book &lt;br /&gt;
{&lt;br /&gt;
  def title:String&lt;br /&gt;
  def title_=(n:String):Unit&lt;br /&gt;
 &lt;br /&gt;
  def computePrice = title.length * 10&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala’s traits are quite nice in that they can not only define abstract members, but also full method definitions. At the same time, they allow inheriting classes to inherit from more than one trait. They pass on their type information and implementations to their children, as well as enforcing the abstract members. At first glance, this seems like it would be just as bad as straight-up multiple inheritance, but it turns out the problems have been mitigated in some very clever ways.&lt;br /&gt;
Traits are actually mixins, not true parent classes. Any non-abstract trait members are actually included in the inheriting class, as in physically part of the class. Well, not physically, but you get the picture. It’s as if the compiler performs a cut-and-paste with the non-abstract members and inserts them into the inheriting class. This means that there’s no ambiguity in the inheritance path, meaning no diamond problem. We can rewrite our CollegeStudent example in Scala without redundancy or fear of paradox:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Person {&lt;br /&gt;
  def schedule:Schedule&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Student extends Person {&lt;br /&gt;
  private var classSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = classSchedule&lt;br /&gt;
 &lt;br /&gt;
  def learn() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Worker extends Person {&lt;br /&gt;
  private var workSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = workSchedule&lt;br /&gt;
 &lt;br /&gt;
  def work() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class CollegeStudent(school:School, company:Company) extends Student with Worker {&lt;br /&gt;
  // ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if we make a call to the schedule method on an instance of CollegeStudent, the compiler knows that we’re referring to the implementation of schedule in the Worker trait.  This is because Worker was mixed in after the Student trait.  &lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Further reading =&lt;br /&gt;
# [http://vimeo.com/20293743 Video to learn about Scala]&lt;br /&gt;
# [http://docs.scala-lang.org/tutorials/ Scala Documentation]&lt;br /&gt;
# [http://shipilev.net/blog/2014/java-scala-divided-we-fail/#_analyzing_bottlenecks Java vs. Scala]&lt;br /&gt;
# [http://www.cs.uku.fi/~mnykanen/FOH/lectures1.pdf  Salient Features of Functional Programming]&lt;br /&gt;
# [https://www.cs.rpi.edu/research/pdf/10-04.pdf Comparison of Object-oriented and Functional Programming]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88429</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 9 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88429"/>
		<updated>2014-09-25T21:12:24Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Similarities between Scala and Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Functional Programming?  =&lt;br /&gt;
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. The programming is done with the use of expressions, that is, it is a [http://en.wikipedia.org/wiki/Declarative_programming declarative programming] paradigm. One key feature in a functional language is the concept of [http://en.wikipedia.org/wiki/First-class_function first-class functions]. The idea is that you can pass functions as parameters to other functions and return them as values. Also, the output value of a function depends only on the arguments that are input to the function, unlike in [http://en.wikipedia.org/wiki/Imperative_programming imperative programming] languages. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behaviour of a program, which is one of the key motivations for the development of functional programming.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_programming&amp;lt;/ref&amp;gt;&lt;br /&gt;
Some examples of functional programming languages:&lt;br /&gt;
&lt;br /&gt;
*Common Lisp&lt;br /&gt;
*Scheme&lt;br /&gt;
*Erlang&lt;br /&gt;
*Haskell&lt;br /&gt;
&lt;br /&gt;
= What is Object Oriented Programming? =&lt;br /&gt;
Object-oriented programming (OOP) is based upon the concept of real world &amp;quot;objects&amp;quot;. These objects have data fields called attributes that describe the object and some procedures associated with them called methods. Object-oriented programming takes the view that what we really care about the objects we want to manipulate rather than the logic required to manipulate them.&lt;br /&gt;
&lt;br /&gt;
Some examples of object oriented programming languages are:&lt;br /&gt;
&lt;br /&gt;
*Simula&lt;br /&gt;
*Smalltalk&lt;br /&gt;
*C++&lt;br /&gt;
*Java&lt;br /&gt;
*C#&lt;br /&gt;
&lt;br /&gt;
= Features of Functional Programming&amp;lt;ref&amp;gt;http://en.wikibooks.org/wiki/Computer_Programming/Functional_programming&amp;lt;/ref&amp;gt; =&lt;br /&gt;
===&amp;lt;b&amp;gt;Higher-order functions:&amp;lt;/b&amp;gt;===&lt;br /&gt;
Higher-order functions (HOFs) are functions that take other functions as their arguments. A basic example of a HOF is map which takes a function and a list as its arguments, applies the function to all elements of the list, and returns the list of its results. Higher-order functions are very useful for refactoring code and reduce the amount of repetition.&lt;br /&gt;
Let’s see an example of a higher order function that receives a message, transforms it in various ways, and forwards it to another server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MessageHandler {&lt;br /&gt;
    	void handleMessage(Message msg, Function getClientCode) {&lt;br /&gt;
        	// ...&lt;br /&gt;
        	Message msg1 = msg.setClientCode(getClientCode());&lt;br /&gt;
        	// ...&lt;br /&gt;
        &lt;br /&gt;
        	sendMessage(msg1);&lt;br /&gt;
    	}&lt;br /&gt;
    &lt;br /&gt;
    	// ...&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeOne() {&lt;br /&gt;
    	return &amp;quot;ABCD_123&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeTwo() {&lt;br /&gt;
    	return &amp;quot;123_ABCD&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	MessageHandler handler = new MessageHandler();&lt;br /&gt;
	handler.handleMessage(someMsg, getClientCodeOne);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we see that we have created no new types and no class hierarchy. We simply pass appropriate functions as a parameter. We don't restrict ourselves to class hierarchies: we can pass new functions at runtime and change them at any time with a much higher degree of granularity with less code.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Purity&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.haskell.org/haskellwiki/Functional_programming&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Some functional languages allow expressions to yield actions in addition to return values. These actions are called side effects to emphasize that the return value is the most important outcome of a function (as opposed to the case in imperative programming). Languages that prohibit side effects are called pure. Even though some functional languages are impure they often contain a pure subset that is also useful as a programming language. It is usually beneficial to write a significant part of a functional program in a purely functional fashion and keep the code involving state and I/O to the minimum as impure code is more prone to errors.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutable data&amp;lt;/b&amp;gt;===&lt;br /&gt;
Purely functional programs typically operate on immutable data. Instead of altering existing values, altered copies are created and the original is preserved. Since the unchanged parts of the structure cannot be modified, they can often be shared between the old and new copies, which saves memory. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Referential transparency&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pure computations yield the same value each time they are invoked. This property is called referential transparency and makes possible to conduct equational reasoning on the code. For instance if &lt;br /&gt;
y = f x&lt;br /&gt;
and &lt;br /&gt;
g = h y y&lt;br /&gt;
then we should be able to replace the definition of &lt;br /&gt;
g&lt;br /&gt;
with &lt;br /&gt;
g = h (f x) (f x)&lt;br /&gt;
and get the same result; only the efficiency might change.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Lazy evaluation&amp;lt;/b&amp;gt;===&lt;br /&gt;
Since pure computations are referentially transparent they can be performed at any time and still yield the same result. This makes it possible to defer the computation of values until they are needed, that is, to compute them lazily. [http://en.wikipedia.org/wiki/Lazy_evaluation Lazy evaluation] avoids unnecessary computations and allows, for example, infinite data structures to be defined and used. &lt;br /&gt;
Let’s take a look at the following piece of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String s1 = somewhatLongOperation1();&lt;br /&gt;
String s2 = somewhatLongOperation2();&lt;br /&gt;
String s3 = concatenate(s1, s2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an imperative language the order of evaluation would be clear. Because each function may affect or depend on an external state it would be necessary to execute them in order: first somewhatLongOperation1, then somewhatLongOperation2, followed by concatenate. Not so in functional languages. somewhatLongOperation1 and somewhatLongOperation2 can be executed concurrently because we're guaranteed no function affects or depends on global state. But what if we don't want to run the two concurrently, do we need to run them in order? The answer is no. We only need to run these operations when another function depends on s1 and s2. We don't even have to run them before concatenate is called - we can delay their evaluation until they're required within concatenate. If we replace concatenate with a function that has a conditional and uses only one of its two parameters we may never evaluate one of the parameters at all!&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
[http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html Recursion] is heavily used in functional programming as it is the canonical and often the only way to iterate. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?PatternMatching&amp;lt;/ref&amp;gt;===&lt;br /&gt;
In the context of pure functional languages, [http://en.wikipedia.org/wiki/Pattern_matching Pattern Matching] is a dispatch mechanism: choosing which variant of a function is the correct one to call. Example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        factorial(0) ::= 1&lt;br /&gt;
	factorial(n) ::= n * factorial(n-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The function has been given two definitions. Which is used for dispatch when a call is made will depend, in this case, on whether the actual parameter pattern matches 0 or not. The matching is not limited to constants; in general, functions have a [http://en.wikipedia.org/wiki/Type_signature TypeSignature] used for matching. [http://en.wikipedia.org/wiki/Currying Currying] is integrated into this mechanism. &lt;br /&gt;
1.Pattern matching is the compiler's ability to compare both the form and the content of two expressions. It is used in two ways:&lt;br /&gt;
All or part of a data structure may be assigned to one or several variables in a single expression. &lt;br /&gt;
2.A function may have several definitions (clauses), according to the form and/or content of its arguments. This second use is usually combined with the first to initialize the variables that will be used in the clause. &lt;br /&gt;
In both these uses, a pattern match has the additional benefit of making an assertion about the form and/or content of a variable.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Closures&amp;lt;/b&amp;gt;===&lt;br /&gt;
Passing functions around in impure languages is a little bit different than doing it in the confines of lambda calculus and requires support for an interesting feature often referred to as [https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Closure_(computer_science).html lexical closure]. Let's take a look at some sample code. Remember, in this case variables aren't final and functions can refer to variables outside of their scope:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Function makePowerFn(int power) {&lt;br /&gt;
   int powerFn(int base) {&lt;br /&gt;
       return pow(base, power);&lt;br /&gt;
   }&lt;br /&gt;
   return powerFn;&lt;br /&gt;
}&lt;br /&gt;
Function square = makePowerFn(2);&lt;br /&gt;
square(3); // returns 9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function makePowerFn returns a function that takes a single argument and raises it to a certain power. What happens when we try to evaluate square(3)? The variable power isn't anywhere in scope of powerFn because makePowerFn has returned and its stack is long gone. How can square work, then? The language must, somehow, store the value of power somewhere for square to work. What if we create another function, cube, that raises something to the third power? The runtime must now store two copies of power, one for each function we generated using makePowerFn. The phenomenon of storing these values is called a closure.&lt;br /&gt;
&lt;br /&gt;
= Comparison between Functional Programming and OOP &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w25_aras&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Let us compare both the programming paradigms with respect to several disctinction attributes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Point of Comparison&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functional Languages&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Object-Oriented Languages&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Primary focus&amp;lt;/b&amp;gt;&lt;br /&gt;
| Functional programming emphasizes on functions that produce results which depend only on their inputs and not on the program state - i.e. pure mathematial functions. || Focus on identifying and''' representing the problem in terms of an 'object'''' which has its own data, sub-routines and state. Different objects in the problem interact by sending messages to each other and thus result in change in its internal state. The final state and values of the objects refer to the solution. It is '''data-centric'''.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Problem Solving Approach&amp;lt;/b&amp;gt;&lt;br /&gt;
| Primarily''' Top-down''' design || '''Identification and design of necessary objects'''. Close to being 'better models of the way the world works'.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Program Flow&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Often sequential''' with program having single point of entry and exit. || '''Complex''' program flow. Can sometimes depend on the internal state of the objects.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Modularity&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Limited modularity'''. Program is divided into modules or per say procedures independent of each other but are constrained due to uniqueness to that particular problem. || '''Extremely modular''' due to the presence of objects which contain their own data and sub-routines.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Data Protection/Hiding&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''No concept of data-hiding'''. Variables local to one method cannot be accessed by other method. But, Global variables can be accessed anywhere within the program. || One of the main fundamentals of O-O languages.''' Access specifiers''' like 'public', 'private' and 'protected' dictate the rules of data-hiding. Data which is private is confined to one object and cannot be directly changed by any other method except its own. This places the responsibility of managing data with the object itself This is called as ownership. Thus, data can be accessed ( read/write/modified )''' only''' through the object's own interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Ease of Understanding&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Smaller programs''' are '''easy to understand''' but as the program increases in size; understanding the code becomes more and more difficult. || '''Easy to understand''' due to its real world-like design and flow.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Reuse of Code&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Very Limited or no''' code re-usability. ||'''Highly re-usable code''' as the code developed can be easily modified or extended to suit a problem's need.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Support for declaring new data types/classes&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Difficult '''due to limited in-built functionality. || '''Easily possible''' due to the concept of classes. Generic classes can be built as per the required specifications.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Efficiency&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Efficient''' for solving '''small''' problems. || '''Efficient''' for solving '''large problems''' which have a complex structure and require complex data-types, abstraction and data-security.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintenance&amp;lt;/b&amp;gt;&lt;br /&gt;
| Maintenance is''' easy for smaller programs''' but can consume''' a-lot of effort for larger program''' size as it requires the programmer to know and understand the dependencies of every module in the program. This makes it difficult to debug and test the program. ||'''Extremely simple''' as O-O languages aim for high modularity. Secondly, programmer is not concerned with the details of how the data is stored and represented. Thirdly, they also tend to keep low coupling which makes it easy to debug and test different modules in the program.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less Extensible''' as modules developed need to be re-organised and re-structured heavily in order to meet different needs. || '''High extensibility''' is one of the most important advantages of OOP. Code can be easily modified and 'plugged-in' to a different program. Methods can be exteneded due to many properties such as polymorphism, inheritance and support for multiple inheritance through interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Flexibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less flexible.''' Sometimes, certain problems do not fit into the 'top-down design' approach. || '''High flexibility.''' The modelling of problems into world-like objects makes it easy to solve any practical problem.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Examples&amp;lt;/b&amp;gt;&lt;br /&gt;
| [http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell], [http://en.wikipedia.org/wiki/Scala_%28programming_language%29 Scala], [http://en.wikipedia.org/wiki/Erlang_%28programming_language%29 Erlang] || [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], [http://en.wikipedia.org/wiki/Python_(programming_language) Python].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Scala : An overview  &amp;lt;ref&amp;gt;http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html&amp;lt;/ref&amp;gt;=&lt;br /&gt;
Scala is an object-functional programming and scripting language generallly used in software applications. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.) and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than most general purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.&lt;br /&gt;
&lt;br /&gt;
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries can be used directly in Scala code, and vice versa. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
object HelloWorld &lt;br /&gt;
{&lt;br /&gt;
   def main(args: Array[String]) &lt;br /&gt;
  {&lt;br /&gt;
    println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program consists of one method called main which takes the command line arguments, an array of strings, as parameter; the body of this method consists of a single call to the predefined method println with the greeting as argument. The main method does not return a value (it is a procedure method). Therefore, it is not necessary to declare a return type. Such a declaration introduces what is commonly known as a singleton object, that is a class with a single instance. The declaration above thus declares both a class called HelloWorld and an instance of that class, also called HelloWorld. This instance is created on demand, the first time it is used. Notice that the main method is not declared as static (like in Java) here. This is because static members (methods or fields) do not exist in Scala. Rather than defining static members, the Scala programmer declares these members in singleton objects.&lt;br /&gt;
&lt;br /&gt;
= Features of Scala &amp;lt;ref&amp;gt;http://www.scala-lang.org/old/node/104&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is object-oriented&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is functional&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.&lt;br /&gt;
Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of right-ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is statically typed&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. &lt;br /&gt;
In particular, the type system supports:&lt;br /&gt;
generic classes, variance annotations, upper and lower type bounds, inner classes and abstract types as object members, compound types, explicitly typed self references, views, and polymorphic methods.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is extensible&amp;lt;/b&amp;gt;===&lt;br /&gt;
In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:&lt;br /&gt;
any method may be used as an infix or postfix operator, and&lt;br /&gt;
closures are constructed automatically depending on the expected type (target typing). A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala interoperates with Java and .NET&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available.&lt;br /&gt;
&lt;br /&gt;
= Similarities between Scala and Java =&lt;br /&gt;
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy,JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.&lt;br /&gt;
&lt;br /&gt;
2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.&lt;br /&gt;
&lt;br /&gt;
3) Major Java programming IDE like Eclipse, Netbeans and [http://www.jetbrains.com/idea/ InetelliJ] supports Scala.&lt;br /&gt;
&lt;br /&gt;
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.&lt;br /&gt;
&lt;br /&gt;
= Scala vs JAVA &amp;lt;ref&amp;gt;http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Syntactic flexibility &amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala has a very powerful and flexible syntax as it relates to methods, both declaration and invocation. In Java you can create methods with different visibilities, modifiers and return types. Scala does allow for different visibilities on not just methods, but any members. &lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person {&lt;br /&gt;
  private var name = &amp;quot;Daniel Spiewak&amp;quot;&lt;br /&gt;
  val ssn = 1234567890    // public constant field&lt;br /&gt;
 &lt;br /&gt;
  def firstName() = splitName()(0)   // public method&lt;br /&gt;
 &lt;br /&gt;
  private def splitName() = name.split(&amp;quot; &amp;quot;)    // private method&lt;br /&gt;
 &lt;br /&gt;
  protected def guessAge() = {&lt;br /&gt;
    import Math._&lt;br /&gt;
    round(random * 20)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala provides the option to import into a specific scope. The import statement within guessAge()is much like a Java static import statement which only provides access to the Math members within theguessAge() method. So we couldn’t just make a call to round() from within the splitName() method.&lt;br /&gt;
Scala access modifiers are also quite a bit more powerful than Java’s. For example,protected by default limits access to only subclasses, unlike Java which also allows access to other classes in the same package.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Unified type system&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). Only reference types are part of the inheritance scheme, deriving from java.lang.Object. In Scala, however, all types inherit from a top-level class Any, whose immediate children are AnyVal(value types, such as Int and Boolean) andAnyRef (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala; boxing and unboxing is completely transparent to the user. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;For-expressions&amp;lt;/b&amp;gt;===&lt;br /&gt;
Instead of the Java &amp;quot;foreach&amp;quot; loops for looping through an iterator, Scala has a much more powerful concept of for-expressions. These are similar to list comprehensions in languages such as Haskell, or a combination of list comprehensions and generator expressions in Python. For-expressions using the yield keyword allow a new collection to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of map, flatMap and filter calls. Where yield is not used, the code approximates to an imperative-style loop, by translating to foreach. A simple example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val s = for (x &amp;lt;- 1 to 25 if x*x &amp;gt; 50) yield 2*x&lt;br /&gt;
The result of running it is the following vector:&lt;br /&gt;
Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Everything is an expression&amp;lt;/b&amp;gt;===&lt;br /&gt;
Unlike C or Java, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning void in Java, and statements like while that logically do not return a value, are in Scala considered to return the type Unit, which is a singleton type, with only one object of that type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Java:&lt;br /&gt;
int hexDigit = x &amp;gt;= 10 ? x + 'A' - 10 : x + '0';&lt;br /&gt;
&lt;br /&gt;
//Scala: &lt;br /&gt;
val hexDigit = if (x &amp;gt;= 10) x + 'A' - 10 else x + '0'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Type inference&amp;lt;/b&amp;gt;===&lt;br /&gt;
Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = &amp;quot;foo&amp;quot; (for an immutable, constant variable or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Anonymous functions&amp;lt;/b&amp;gt;===&lt;br /&gt;
In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x =&amp;gt; x &amp;lt; 2, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. &lt;br /&gt;
&lt;br /&gt;
An even shorter form of anonymous function uses placeholder variables: For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list map { x =&amp;gt; sqrt(x) }&lt;br /&gt;
&lt;br /&gt;
can be written more concisely as&lt;br /&gt;
&lt;br /&gt;
list map { sqrt(_) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutability&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with val while mutable variables use var. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Tail recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround. Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released July 14, 2010).&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pattern matching in Scala is really a lot like Java’s switch/case construct.  So in Java, one might write something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public boolean checkPrime(int number) {&lt;br /&gt;
    // checks if a number between 1 and 10 is prime&lt;br /&gt;
    switch (number) {&lt;br /&gt;
        case 1: return true;&lt;br /&gt;
        case 2: return true;&lt;br /&gt;
        case 3: return true;&lt;br /&gt;
        case 5: return true;&lt;br /&gt;
        case 7: return true;&lt;br /&gt;
 &lt;br /&gt;
        default: return false;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the major limitations of switch/case in Java  is that it can only be used on primitives.  You can’t use switch/case to test a String, for example (a need which arises more often than one would think).  In fact, the most complex type testable within switch/case is the Enum, and even this is just being reduced to its ordinal values under the surface.&lt;br /&gt;
The designers of Scala chose not to include this “feature” in their new language. Instead, they implemented a “new” concept called pattern matching. At a basic level, it allows algorithms which are very similar to the checkPrime(int) example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def checkPrime(number:Int):Boolean = {&lt;br /&gt;
  number match {&lt;br /&gt;
    case 1 =&amp;gt; return true&lt;br /&gt;
    case 2 =&amp;gt; return true&lt;br /&gt;
    case 3 =&amp;gt; return true&lt;br /&gt;
    case 5 =&amp;gt; return true&lt;br /&gt;
    case 7 =&amp;gt; return true&lt;br /&gt;
 &lt;br /&gt;
    case _ =&amp;gt; return false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The biggest difference which likely jumps out at you is the lack of a default statement. Instead, we see the return of Scala’s ubiquitous wildcard character, the underscore. Literally read, this example means: match the value within number; in the case that it is 1, return true; in the case that it is 2, return true; …; for any previously unmatched value, return false.&lt;br /&gt;
Scala case statements can’t “overflow” into each-other (causing multiple matches) like Java’s can, so even if we weren’t returning values, the algorithm would still be safe.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java’s designers recognized the need for multiple typing (e.g. CollegeStudent is both a Student and a Worker), but they wanted to avoid the issues associated with inheriting conflicting method definitions along multiple paths.  Their solution was to design the interface mechanism, a feature which allows multiple typing without the complications of multiple inheritance.  &lt;br /&gt;
Scala recognizes that interfaces have their issues.  So rather than blinding creating a reimplementation of the same problems found in either Java or C++, Scala takes a new approach.  Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
trait Book &lt;br /&gt;
{&lt;br /&gt;
  def title:String&lt;br /&gt;
  def title_=(n:String):Unit&lt;br /&gt;
 &lt;br /&gt;
  def computePrice = title.length * 10&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala’s traits are quite nice in that they can not only define abstract members, but also full method definitions. At the same time, they allow inheriting classes to inherit from more than one trait. They pass on their type information and implementations to their children, as well as enforcing the abstract members. At first glance, this seems like it would be just as bad as straight-up multiple inheritance, but it turns out the problems have been mitigated in some very clever ways.&lt;br /&gt;
Traits are actually mixins, not true parent classes. Any non-abstract trait members are actually included in the inheriting class, as in physically part of the class. Well, not physically, but you get the picture. It’s as if the compiler performs a cut-and-paste with the non-abstract members and inserts them into the inheriting class. This means that there’s no ambiguity in the inheritance path, meaning no diamond problem. We can rewrite our CollegeStudent example in Scala without redundancy or fear of paradox:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Person {&lt;br /&gt;
  def schedule:Schedule&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Student extends Person {&lt;br /&gt;
  private var classSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = classSchedule&lt;br /&gt;
 &lt;br /&gt;
  def learn() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Worker extends Person {&lt;br /&gt;
  private var workSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = workSchedule&lt;br /&gt;
 &lt;br /&gt;
  def work() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class CollegeStudent(school:School, company:Company) extends Student with Worker {&lt;br /&gt;
  // ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if we make a call to the schedule method on an instance of CollegeStudent, the compiler knows that we’re referring to the implementation of schedule in the Worker trait.  This is because Worker was mixed in after the Student trait.  &lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Further reading =&lt;br /&gt;
# [http://vimeo.com/20293743 Video to learn about Scala]&lt;br /&gt;
# [http://docs.scala-lang.org/tutorials/ Scala Documentation]&lt;br /&gt;
# [http://shipilev.net/blog/2014/java-scala-divided-we-fail/#_analyzing_bottlenecks Java vs. Scala]&lt;br /&gt;
# [http://www.cs.uku.fi/~mnykanen/FOH/lectures1.pdf  Salient Features of Functional Programming]&lt;br /&gt;
# [https://www.cs.rpi.edu/research/pdf/10-04.pdf Comparison of Object-oriented and Functional Programming]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88424</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 9 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88424"/>
		<updated>2014-09-25T21:08:27Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Pattern Matchinghttp://c2.com/cgi/wiki?PatternMatching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Functional Programming?  =&lt;br /&gt;
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. The programming is done with the use of expressions, that is, it is a [http://en.wikipedia.org/wiki/Declarative_programming declarative programming] paradigm. One key feature in a functional language is the concept of [http://en.wikipedia.org/wiki/First-class_function first-class functions]. The idea is that you can pass functions as parameters to other functions and return them as values. Also, the output value of a function depends only on the arguments that are input to the function, unlike in [http://en.wikipedia.org/wiki/Imperative_programming imperative programming] languages. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behaviour of a program, which is one of the key motivations for the development of functional programming.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_programming&amp;lt;/ref&amp;gt;&lt;br /&gt;
Some examples of functional programming languages:&lt;br /&gt;
&lt;br /&gt;
*Common Lisp&lt;br /&gt;
*Scheme&lt;br /&gt;
*Erlang&lt;br /&gt;
*Haskell&lt;br /&gt;
&lt;br /&gt;
= What is Object Oriented Programming? =&lt;br /&gt;
Object-oriented programming (OOP) is based upon the concept of real world &amp;quot;objects&amp;quot;. These objects have data fields called attributes that describe the object and some procedures associated with them called methods. Object-oriented programming takes the view that what we really care about the objects we want to manipulate rather than the logic required to manipulate them.&lt;br /&gt;
&lt;br /&gt;
Some examples of object oriented programming languages are:&lt;br /&gt;
&lt;br /&gt;
*Simula&lt;br /&gt;
*Smalltalk&lt;br /&gt;
*C++&lt;br /&gt;
*Java&lt;br /&gt;
*C#&lt;br /&gt;
&lt;br /&gt;
= Features of Functional Programming&amp;lt;ref&amp;gt;http://en.wikibooks.org/wiki/Computer_Programming/Functional_programming&amp;lt;/ref&amp;gt; =&lt;br /&gt;
===&amp;lt;b&amp;gt;Higher-order functions:&amp;lt;/b&amp;gt;===&lt;br /&gt;
Higher-order functions (HOFs) are functions that take other functions as their arguments. A basic example of a HOF is map which takes a function and a list as its arguments, applies the function to all elements of the list, and returns the list of its results. Higher-order functions are very useful for refactoring code and reduce the amount of repetition.&lt;br /&gt;
Let’s see an example of a higher order function that receives a message, transforms it in various ways, and forwards it to another server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MessageHandler {&lt;br /&gt;
    	void handleMessage(Message msg, Function getClientCode) {&lt;br /&gt;
        	// ...&lt;br /&gt;
        	Message msg1 = msg.setClientCode(getClientCode());&lt;br /&gt;
        	// ...&lt;br /&gt;
        &lt;br /&gt;
        	sendMessage(msg1);&lt;br /&gt;
    	}&lt;br /&gt;
    &lt;br /&gt;
    	// ...&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeOne() {&lt;br /&gt;
    	return &amp;quot;ABCD_123&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeTwo() {&lt;br /&gt;
    	return &amp;quot;123_ABCD&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	MessageHandler handler = new MessageHandler();&lt;br /&gt;
	handler.handleMessage(someMsg, getClientCodeOne);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we see that we have created no new types and no class hierarchy. We simply pass appropriate functions as a parameter. We don't restrict ourselves to class hierarchies: we can pass new functions at runtime and change them at any time with a much higher degree of granularity with less code.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Purity&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.haskell.org/haskellwiki/Functional_programming&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Some functional languages allow expressions to yield actions in addition to return values. These actions are called side effects to emphasize that the return value is the most important outcome of a function (as opposed to the case in imperative programming). Languages that prohibit side effects are called pure. Even though some functional languages are impure they often contain a pure subset that is also useful as a programming language. It is usually beneficial to write a significant part of a functional program in a purely functional fashion and keep the code involving state and I/O to the minimum as impure code is more prone to errors.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutable data&amp;lt;/b&amp;gt;===&lt;br /&gt;
Purely functional programs typically operate on immutable data. Instead of altering existing values, altered copies are created and the original is preserved. Since the unchanged parts of the structure cannot be modified, they can often be shared between the old and new copies, which saves memory. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Referential transparency&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pure computations yield the same value each time they are invoked. This property is called referential transparency and makes possible to conduct equational reasoning on the code. For instance if &lt;br /&gt;
y = f x&lt;br /&gt;
and &lt;br /&gt;
g = h y y&lt;br /&gt;
then we should be able to replace the definition of &lt;br /&gt;
g&lt;br /&gt;
with &lt;br /&gt;
g = h (f x) (f x)&lt;br /&gt;
and get the same result; only the efficiency might change.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Lazy evaluation&amp;lt;/b&amp;gt;===&lt;br /&gt;
Since pure computations are referentially transparent they can be performed at any time and still yield the same result. This makes it possible to defer the computation of values until they are needed, that is, to compute them lazily. [http://en.wikipedia.org/wiki/Lazy_evaluation Lazy evaluation] avoids unnecessary computations and allows, for example, infinite data structures to be defined and used. &lt;br /&gt;
Let’s take a look at the following piece of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String s1 = somewhatLongOperation1();&lt;br /&gt;
String s2 = somewhatLongOperation2();&lt;br /&gt;
String s3 = concatenate(s1, s2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an imperative language the order of evaluation would be clear. Because each function may affect or depend on an external state it would be necessary to execute them in order: first somewhatLongOperation1, then somewhatLongOperation2, followed by concatenate. Not so in functional languages. somewhatLongOperation1 and somewhatLongOperation2 can be executed concurrently because we're guaranteed no function affects or depends on global state. But what if we don't want to run the two concurrently, do we need to run them in order? The answer is no. We only need to run these operations when another function depends on s1 and s2. We don't even have to run them before concatenate is called - we can delay their evaluation until they're required within concatenate. If we replace concatenate with a function that has a conditional and uses only one of its two parameters we may never evaluate one of the parameters at all!&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
[http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html Recursion] is heavily used in functional programming as it is the canonical and often the only way to iterate. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?PatternMatching&amp;lt;/ref&amp;gt;===&lt;br /&gt;
In the context of pure functional languages, [http://en.wikipedia.org/wiki/Pattern_matching Pattern Matching] is a dispatch mechanism: choosing which variant of a function is the correct one to call. Example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        factorial(0) ::= 1&lt;br /&gt;
	factorial(n) ::= n * factorial(n-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The function has been given two definitions. Which is used for dispatch when a call is made will depend, in this case, on whether the actual parameter pattern matches 0 or not. The matching is not limited to constants; in general, functions have a [http://en.wikipedia.org/wiki/Type_signature TypeSignature] used for matching. [http://en.wikipedia.org/wiki/Currying Currying] is integrated into this mechanism. &lt;br /&gt;
1.Pattern matching is the compiler's ability to compare both the form and the content of two expressions. It is used in two ways:&lt;br /&gt;
All or part of a data structure may be assigned to one or several variables in a single expression. &lt;br /&gt;
2.A function may have several definitions (clauses), according to the form and/or content of its arguments. This second use is usually combined with the first to initialize the variables that will be used in the clause. &lt;br /&gt;
In both these uses, a pattern match has the additional benefit of making an assertion about the form and/or content of a variable.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Closures&amp;lt;/b&amp;gt;===&lt;br /&gt;
Passing functions around in impure languages is a little bit different than doing it in the confines of lambda calculus and requires support for an interesting feature often referred to as [https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Closure_(computer_science).html lexical closure]. Let's take a look at some sample code. Remember, in this case variables aren't final and functions can refer to variables outside of their scope:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Function makePowerFn(int power) {&lt;br /&gt;
   int powerFn(int base) {&lt;br /&gt;
       return pow(base, power);&lt;br /&gt;
   }&lt;br /&gt;
   return powerFn;&lt;br /&gt;
}&lt;br /&gt;
Function square = makePowerFn(2);&lt;br /&gt;
square(3); // returns 9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function makePowerFn returns a function that takes a single argument and raises it to a certain power. What happens when we try to evaluate square(3)? The variable power isn't anywhere in scope of powerFn because makePowerFn has returned and its stack is long gone. How can square work, then? The language must, somehow, store the value of power somewhere for square to work. What if we create another function, cube, that raises something to the third power? The runtime must now store two copies of power, one for each function we generated using makePowerFn. The phenomenon of storing these values is called a closure.&lt;br /&gt;
&lt;br /&gt;
= Comparison between Functional Programming and OOP &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w25_aras&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Let us compare both the programming paradigms with respect to several disctinction attributes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Point of Comparison&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functional Languages&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Object-Oriented Languages&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Primary focus&amp;lt;/b&amp;gt;&lt;br /&gt;
| Functional programming emphasizes on functions that produce results which depend only on their inputs and not on the program state - i.e. pure mathematial functions. || Focus on identifying and''' representing the problem in terms of an 'object'''' which has its own data, sub-routines and state. Different objects in the problem interact by sending messages to each other and thus result in change in its internal state. The final state and values of the objects refer to the solution. It is '''data-centric'''.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Problem Solving Approach&amp;lt;/b&amp;gt;&lt;br /&gt;
| Primarily''' Top-down''' design || '''Identification and design of necessary objects'''. Close to being 'better models of the way the world works'.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Program Flow&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Often sequential''' with program having single point of entry and exit. || '''Complex''' program flow. Can sometimes depend on the internal state of the objects.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Modularity&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Limited modularity'''. Program is divided into modules or per say procedures independent of each other but are constrained due to uniqueness to that particular problem. || '''Extremely modular''' due to the presence of objects which contain their own data and sub-routines.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Data Protection/Hiding&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''No concept of data-hiding'''. Variables local to one method cannot be accessed by other method. But, Global variables can be accessed anywhere within the program. || One of the main fundamentals of O-O languages.''' Access specifiers''' like 'public', 'private' and 'protected' dictate the rules of data-hiding. Data which is private is confined to one object and cannot be directly changed by any other method except its own. This places the responsibility of managing data with the object itself This is called as ownership. Thus, data can be accessed ( read/write/modified )''' only''' through the object's own interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Ease of Understanding&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Smaller programs''' are '''easy to understand''' but as the program increases in size; understanding the code becomes more and more difficult. || '''Easy to understand''' due to its real world-like design and flow.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Reuse of Code&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Very Limited or no''' code re-usability. ||'''Highly re-usable code''' as the code developed can be easily modified or extended to suit a problem's need.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Support for declaring new data types/classes&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Difficult '''due to limited in-built functionality. || '''Easily possible''' due to the concept of classes. Generic classes can be built as per the required specifications.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Efficiency&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Efficient''' for solving '''small''' problems. || '''Efficient''' for solving '''large problems''' which have a complex structure and require complex data-types, abstraction and data-security.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintenance&amp;lt;/b&amp;gt;&lt;br /&gt;
| Maintenance is''' easy for smaller programs''' but can consume''' a-lot of effort for larger program''' size as it requires the programmer to know and understand the dependencies of every module in the program. This makes it difficult to debug and test the program. ||'''Extremely simple''' as O-O languages aim for high modularity. Secondly, programmer is not concerned with the details of how the data is stored and represented. Thirdly, they also tend to keep low coupling which makes it easy to debug and test different modules in the program.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less Extensible''' as modules developed need to be re-organised and re-structured heavily in order to meet different needs. || '''High extensibility''' is one of the most important advantages of OOP. Code can be easily modified and 'plugged-in' to a different program. Methods can be exteneded due to many properties such as polymorphism, inheritance and support for multiple inheritance through interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Flexibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less flexible.''' Sometimes, certain problems do not fit into the 'top-down design' approach. || '''High flexibility.''' The modelling of problems into world-like objects makes it easy to solve any practical problem.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Examples&amp;lt;/b&amp;gt;&lt;br /&gt;
| [http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell], [http://en.wikipedia.org/wiki/Scala_%28programming_language%29 Scala], [http://en.wikipedia.org/wiki/Erlang_%28programming_language%29 Erlang] || [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], [http://en.wikipedia.org/wiki/Python_(programming_language) Python].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Scala : An overview  &amp;lt;ref&amp;gt;http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html&amp;lt;/ref&amp;gt;=&lt;br /&gt;
Scala is an object-functional programming and scripting language generallly used in software applications. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.) and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than most general purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.&lt;br /&gt;
&lt;br /&gt;
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries can be used directly in Scala code, and vice versa. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
object HelloWorld &lt;br /&gt;
{&lt;br /&gt;
   def main(args: Array[String]) &lt;br /&gt;
  {&lt;br /&gt;
    println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program consists of one method called main which takes the command line arguments, an array of strings, as parameter; the body of this method consists of a single call to the predefined method println with the greeting as argument. The main method does not return a value (it is a procedure method). Therefore, it is not necessary to declare a return type. Such a declaration introduces what is commonly known as a singleton object, that is a class with a single instance. The declaration above thus declares both a class called HelloWorld and an instance of that class, also called HelloWorld. This instance is created on demand, the first time it is used. Notice that the main method is not declared as static (like in Java) here. This is because static members (methods or fields) do not exist in Scala. Rather than defining static members, the Scala programmer declares these members in singleton objects.&lt;br /&gt;
&lt;br /&gt;
= Features of Scala &amp;lt;ref&amp;gt;http://www.scala-lang.org/old/node/104&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is object-oriented&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is functional&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.&lt;br /&gt;
Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of right-ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is statically typed&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. &lt;br /&gt;
In particular, the type system supports:&lt;br /&gt;
generic classes, variance annotations, upper and lower type bounds, inner classes and abstract types as object members, compound types, explicitly typed self references, views, and polymorphic methods.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is extensible&amp;lt;/b&amp;gt;===&lt;br /&gt;
In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:&lt;br /&gt;
any method may be used as an infix or postfix operator, and&lt;br /&gt;
closures are constructed automatically depending on the expected type (target typing). A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala interoperates with Java and .NET&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available.&lt;br /&gt;
&lt;br /&gt;
= Similarities between Scala and Java =&lt;br /&gt;
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy,JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.&lt;br /&gt;
&lt;br /&gt;
2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.&lt;br /&gt;
&lt;br /&gt;
3) Major Java programming IDE like Eclipse, Netbeans and InetelliJ supports Scala.&lt;br /&gt;
&lt;br /&gt;
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Scala vs JAVA &amp;lt;ref&amp;gt;http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Syntactic flexibility &amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala has a very powerful and flexible syntax as it relates to methods, both declaration and invocation. In Java you can create methods with different visibilities, modifiers and return types. Scala does allow for different visibilities on not just methods, but any members. &lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person {&lt;br /&gt;
  private var name = &amp;quot;Daniel Spiewak&amp;quot;&lt;br /&gt;
  val ssn = 1234567890    // public constant field&lt;br /&gt;
 &lt;br /&gt;
  def firstName() = splitName()(0)   // public method&lt;br /&gt;
 &lt;br /&gt;
  private def splitName() = name.split(&amp;quot; &amp;quot;)    // private method&lt;br /&gt;
 &lt;br /&gt;
  protected def guessAge() = {&lt;br /&gt;
    import Math._&lt;br /&gt;
    round(random * 20)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala provides the option to import into a specific scope. The import statement within guessAge()is much like a Java static import statement which only provides access to the Math members within theguessAge() method. So we couldn’t just make a call to round() from within the splitName() method.&lt;br /&gt;
Scala access modifiers are also quite a bit more powerful than Java’s. For example,protected by default limits access to only subclasses, unlike Java which also allows access to other classes in the same package.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Unified type system&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). Only reference types are part of the inheritance scheme, deriving from java.lang.Object. In Scala, however, all types inherit from a top-level class Any, whose immediate children are AnyVal(value types, such as Int and Boolean) andAnyRef (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala; boxing and unboxing is completely transparent to the user. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;For-expressions&amp;lt;/b&amp;gt;===&lt;br /&gt;
Instead of the Java &amp;quot;foreach&amp;quot; loops for looping through an iterator, Scala has a much more powerful concept of for-expressions. These are similar to list comprehensions in languages such as Haskell, or a combination of list comprehensions and generator expressions in Python. For-expressions using the yield keyword allow a new collection to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of map, flatMap and filter calls. Where yield is not used, the code approximates to an imperative-style loop, by translating to foreach. A simple example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val s = for (x &amp;lt;- 1 to 25 if x*x &amp;gt; 50) yield 2*x&lt;br /&gt;
The result of running it is the following vector:&lt;br /&gt;
Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Everything is an expression&amp;lt;/b&amp;gt;===&lt;br /&gt;
Unlike C or Java, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning void in Java, and statements like while that logically do not return a value, are in Scala considered to return the type Unit, which is a singleton type, with only one object of that type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Java:&lt;br /&gt;
int hexDigit = x &amp;gt;= 10 ? x + 'A' - 10 : x + '0';&lt;br /&gt;
&lt;br /&gt;
//Scala: &lt;br /&gt;
val hexDigit = if (x &amp;gt;= 10) x + 'A' - 10 else x + '0'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Type inference&amp;lt;/b&amp;gt;===&lt;br /&gt;
Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = &amp;quot;foo&amp;quot; (for an immutable, constant variable or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Anonymous functions&amp;lt;/b&amp;gt;===&lt;br /&gt;
In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x =&amp;gt; x &amp;lt; 2, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. &lt;br /&gt;
&lt;br /&gt;
An even shorter form of anonymous function uses placeholder variables: For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list map { x =&amp;gt; sqrt(x) }&lt;br /&gt;
&lt;br /&gt;
can be written more concisely as&lt;br /&gt;
&lt;br /&gt;
list map { sqrt(_) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutability&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with val while mutable variables use var. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Tail recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround. Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released July 14, 2010).&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pattern matching in Scala is really a lot like Java’s switch/case construct.  So in Java, one might write something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public boolean checkPrime(int number) {&lt;br /&gt;
    // checks if a number between 1 and 10 is prime&lt;br /&gt;
    switch (number) {&lt;br /&gt;
        case 1: return true;&lt;br /&gt;
        case 2: return true;&lt;br /&gt;
        case 3: return true;&lt;br /&gt;
        case 5: return true;&lt;br /&gt;
        case 7: return true;&lt;br /&gt;
 &lt;br /&gt;
        default: return false;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the major limitations of switch/case in Java  is that it can only be used on primitives.  You can’t use switch/case to test a String, for example (a need which arises more often than one would think).  In fact, the most complex type testable within switch/case is the Enum, and even this is just being reduced to its ordinal values under the surface.&lt;br /&gt;
The designers of Scala chose not to include this “feature” in their new language. Instead, they implemented a “new” concept called pattern matching. At a basic level, it allows algorithms which are very similar to the checkPrime(int) example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def checkPrime(number:Int):Boolean = {&lt;br /&gt;
  number match {&lt;br /&gt;
    case 1 =&amp;gt; return true&lt;br /&gt;
    case 2 =&amp;gt; return true&lt;br /&gt;
    case 3 =&amp;gt; return true&lt;br /&gt;
    case 5 =&amp;gt; return true&lt;br /&gt;
    case 7 =&amp;gt; return true&lt;br /&gt;
 &lt;br /&gt;
    case _ =&amp;gt; return false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The biggest difference which likely jumps out at you is the lack of a default statement. Instead, we see the return of Scala’s ubiquitous wildcard character, the underscore. Literally read, this example means: match the value within number; in the case that it is 1, return true; in the case that it is 2, return true; …; for any previously unmatched value, return false.&lt;br /&gt;
Scala case statements can’t “overflow” into each-other (causing multiple matches) like Java’s can, so even if we weren’t returning values, the algorithm would still be safe.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java’s designers recognized the need for multiple typing (e.g. CollegeStudent is both a Student and a Worker), but they wanted to avoid the issues associated with inheriting conflicting method definitions along multiple paths.  Their solution was to design the interface mechanism, a feature which allows multiple typing without the complications of multiple inheritance.  &lt;br /&gt;
Scala recognizes that interfaces have their issues.  So rather than blinding creating a reimplementation of the same problems found in either Java or C++, Scala takes a new approach.  Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
trait Book &lt;br /&gt;
{&lt;br /&gt;
  def title:String&lt;br /&gt;
  def title_=(n:String):Unit&lt;br /&gt;
 &lt;br /&gt;
  def computePrice = title.length * 10&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala’s traits are quite nice in that they can not only define abstract members, but also full method definitions. At the same time, they allow inheriting classes to inherit from more than one trait. They pass on their type information and implementations to their children, as well as enforcing the abstract members. At first glance, this seems like it would be just as bad as straight-up multiple inheritance, but it turns out the problems have been mitigated in some very clever ways.&lt;br /&gt;
Traits are actually mixins, not true parent classes. Any non-abstract trait members are actually included in the inheriting class, as in physically part of the class. Well, not physically, but you get the picture. It’s as if the compiler performs a cut-and-paste with the non-abstract members and inserts them into the inheriting class. This means that there’s no ambiguity in the inheritance path, meaning no diamond problem. We can rewrite our CollegeStudent example in Scala without redundancy or fear of paradox:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Person {&lt;br /&gt;
  def schedule:Schedule&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Student extends Person {&lt;br /&gt;
  private var classSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = classSchedule&lt;br /&gt;
 &lt;br /&gt;
  def learn() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Worker extends Person {&lt;br /&gt;
  private var workSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = workSchedule&lt;br /&gt;
 &lt;br /&gt;
  def work() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class CollegeStudent(school:School, company:Company) extends Student with Worker {&lt;br /&gt;
  // ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if we make a call to the schedule method on an instance of CollegeStudent, the compiler knows that we’re referring to the implementation of schedule in the Worker trait.  This is because Worker was mixed in after the Student trait.  &lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Further reading =&lt;br /&gt;
# [http://vimeo.com/20293743 Video to learn about Scala]&lt;br /&gt;
# [http://docs.scala-lang.org/tutorials/ Scala Documentation]&lt;br /&gt;
# [http://shipilev.net/blog/2014/java-scala-divided-we-fail/#_analyzing_bottlenecks Java vs. Scala]&lt;br /&gt;
# [http://www.cs.uku.fi/~mnykanen/FOH/lectures1.pdf  Salient Features of Functional Programming]&lt;br /&gt;
# [https://www.cs.rpi.edu/research/pdf/10-04.pdf Comparison of Object-oriented and Functional Programming]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88399</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 9 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88399"/>
		<updated>2014-09-25T20:47:28Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Closures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Functional Programming?  =&lt;br /&gt;
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. The programming is done with the use of expressions, that is, it is a [http://en.wikipedia.org/wiki/Declarative_programming declarative programming] paradigm. One key feature in a functional language is the concept of [http://en.wikipedia.org/wiki/First-class_function first-class functions]. The idea is that you can pass functions as parameters to other functions and return them as values. Also, the output value of a function depends only on the arguments that are input to the function, unlike in [http://en.wikipedia.org/wiki/Imperative_programming imperative programming] languages. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behaviour of a program, which is one of the key motivations for the development of functional programming.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_programming&amp;lt;/ref&amp;gt;&lt;br /&gt;
Some examples of functional programming languages:&lt;br /&gt;
&lt;br /&gt;
*Common Lisp&lt;br /&gt;
*Scheme&lt;br /&gt;
*Erlang&lt;br /&gt;
*Haskell&lt;br /&gt;
&lt;br /&gt;
= What is Object Oriented Programming? =&lt;br /&gt;
Object-oriented programming (OOP) is based upon the concept of real world &amp;quot;objects&amp;quot;. These objects have data fields called attributes that describe the object and some procedures associated with them called methods. Object-oriented programming takes the view that what we really care about the objects we want to manipulate rather than the logic required to manipulate them.&lt;br /&gt;
&lt;br /&gt;
Some examples of object oriented programming languages are:&lt;br /&gt;
&lt;br /&gt;
*Simula&lt;br /&gt;
*Smalltalk&lt;br /&gt;
*C++&lt;br /&gt;
*Java&lt;br /&gt;
*C#&lt;br /&gt;
&lt;br /&gt;
= Features of Functional Programming&amp;lt;ref&amp;gt;http://en.wikibooks.org/wiki/Computer_Programming/Functional_programming&amp;lt;/ref&amp;gt; =&lt;br /&gt;
===&amp;lt;b&amp;gt;Higher-order functions:&amp;lt;/b&amp;gt;===&lt;br /&gt;
Higher-order functions (HOFs) are functions that take other functions as their arguments. A basic example of a HOF is map which takes a function and a list as its arguments, applies the function to all elements of the list, and returns the list of its results. Higher-order functions are very useful for refactoring code and reduce the amount of repetition.&lt;br /&gt;
Let’s see an example of a higher order function that receives a message, transforms it in various ways, and forwards it to another server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MessageHandler {&lt;br /&gt;
    	void handleMessage(Message msg, Function getClientCode) {&lt;br /&gt;
        	// ...&lt;br /&gt;
        	Message msg1 = msg.setClientCode(getClientCode());&lt;br /&gt;
        	// ...&lt;br /&gt;
        &lt;br /&gt;
        	sendMessage(msg1);&lt;br /&gt;
    	}&lt;br /&gt;
    &lt;br /&gt;
    	// ...&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeOne() {&lt;br /&gt;
    	return &amp;quot;ABCD_123&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeTwo() {&lt;br /&gt;
    	return &amp;quot;123_ABCD&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	MessageHandler handler = new MessageHandler();&lt;br /&gt;
	handler.handleMessage(someMsg, getClientCodeOne);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we see that we have created no new types and no class hierarchy. We simply pass appropriate functions as a parameter. We don't restrict ourselves to class hierarchies: we can pass new functions at runtime and change them at any time with a much higher degree of granularity with less code.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Purity&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.haskell.org/haskellwiki/Functional_programming&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Some functional languages allow expressions to yield actions in addition to return values. These actions are called side effects to emphasize that the return value is the most important outcome of a function (as opposed to the case in imperative programming). Languages that prohibit side effects are called pure. Even though some functional languages are impure they often contain a pure subset that is also useful as a programming language. It is usually beneficial to write a significant part of a functional program in a purely functional fashion and keep the code involving state and I/O to the minimum as impure code is more prone to errors.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutable data&amp;lt;/b&amp;gt;===&lt;br /&gt;
Purely functional programs typically operate on immutable data. Instead of altering existing values, altered copies are created and the original is preserved. Since the unchanged parts of the structure cannot be modified, they can often be shared between the old and new copies, which saves memory. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Referential transparency&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pure computations yield the same value each time they are invoked. This property is called referential transparency and makes possible to conduct equational reasoning on the code. For instance if &lt;br /&gt;
y = f x&lt;br /&gt;
and &lt;br /&gt;
g = h y y&lt;br /&gt;
then we should be able to replace the definition of &lt;br /&gt;
g&lt;br /&gt;
with &lt;br /&gt;
g = h (f x) (f x)&lt;br /&gt;
and get the same result; only the efficiency might change.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Lazy evaluation&amp;lt;/b&amp;gt;===&lt;br /&gt;
Since pure computations are referentially transparent they can be performed at any time and still yield the same result. This makes it possible to defer the computation of values until they are needed, that is, to compute them lazily. [http://en.wikipedia.org/wiki/Lazy_evaluation Lazy evaluation] avoids unnecessary computations and allows, for example, infinite data structures to be defined and used. &lt;br /&gt;
Let’s take a look at the following piece of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String s1 = somewhatLongOperation1();&lt;br /&gt;
String s2 = somewhatLongOperation2();&lt;br /&gt;
String s3 = concatenate(s1, s2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an imperative language the order of evaluation would be clear. Because each function may affect or depend on an external state it would be necessary to execute them in order: first somewhatLongOperation1, then somewhatLongOperation2, followed by concatenate. Not so in functional languages. somewhatLongOperation1 and somewhatLongOperation2 can be executed concurrently because we're guaranteed no function affects or depends on global state. But what if we don't want to run the two concurrently, do we need to run them in order? The answer is no. We only need to run these operations when another function depends on s1 and s2. We don't even have to run them before concatenate is called - we can delay their evaluation until they're required within concatenate. If we replace concatenate with a function that has a conditional and uses only one of its two parameters we may never evaluate one of the parameters at all!&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
[http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html Recursion] is heavily used in functional programming as it is the canonical and often the only way to iterate. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?PatternMatching&amp;lt;/ref&amp;gt;===&lt;br /&gt;
In the context of pure functional languages, Pattern Matching is a dispatch mechanism: choosing which variant of a function is the correct one to call. Example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        factorial(0) ::= 1&lt;br /&gt;
	factorial(n) ::= n * factorial(n-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The function has been given two definitions. Which is used for dispatch when a call is made will depend, in this case, on whether the actual parameter pattern matches 0 or not. The matching is not limited to constants; in general, functions have a [http://en.wikipedia.org/wiki/Type_signature TypeSignature] used for matching. [http://en.wikipedia.org/wiki/Currying Currying] is integrated into this mechanism. &lt;br /&gt;
1.Pattern matching is the compiler's ability to compare both the form and the content of two expressions. It is used in two ways:&lt;br /&gt;
All or part of a data structure may be assigned to one or several variables in a single expression. &lt;br /&gt;
2.A function may have several definitions (clauses), according to the form and/or content of its arguments. This second use is usually combined with the first to initialize the variables that will be used in the clause. &lt;br /&gt;
In both these uses, a pattern match has the additional benefit of making an assertion about the form and/or content of a variable.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Closures&amp;lt;/b&amp;gt;===&lt;br /&gt;
Passing functions around in impure languages is a little bit different than doing it in the confines of lambda calculus and requires support for an interesting feature often referred to as [https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Closure_(computer_science).html lexical closure]. Let's take a look at some sample code. Remember, in this case variables aren't final and functions can refer to variables outside of their scope:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Function makePowerFn(int power) {&lt;br /&gt;
   int powerFn(int base) {&lt;br /&gt;
       return pow(base, power);&lt;br /&gt;
   }&lt;br /&gt;
   return powerFn;&lt;br /&gt;
}&lt;br /&gt;
Function square = makePowerFn(2);&lt;br /&gt;
square(3); // returns 9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function makePowerFn returns a function that takes a single argument and raises it to a certain power. What happens when we try to evaluate square(3)? The variable power isn't anywhere in scope of powerFn because makePowerFn has returned and its stack is long gone. How can square work, then? The language must, somehow, store the value of power somewhere for square to work. What if we create another function, cube, that raises something to the third power? The runtime must now store two copies of power, one for each function we generated using makePowerFn. The phenomenon of storing these values is called a closure.&lt;br /&gt;
&lt;br /&gt;
= Comparison between Functional Programming and OOP &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w25_aras&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Let us compare both the programming paradigms with respect to several disctinction attributes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Point of Comparison&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functional Languages&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Object-Oriented Languages&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Primary focus&amp;lt;/b&amp;gt;&lt;br /&gt;
| Functional programming emphasizes on functions that produce results which depend only on their inputs and not on the program state - i.e. pure mathematial functions. || Focus on identifying and''' representing the problem in terms of an 'object'''' which has its own data, sub-routines and state. Different objects in the problem interact by sending messages to each other and thus result in change in its internal state. The final state and values of the objects refer to the solution. It is '''data-centric'''.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Problem Solving Approach&amp;lt;/b&amp;gt;&lt;br /&gt;
| Primarily''' Top-down''' design || '''Identification and design of necessary objects'''. Close to being 'better models of the way the world works'.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Program Flow&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Often sequential''' with program having single point of entry and exit. || '''Complex''' program flow. Can sometimes depend on the internal state of the objects.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Modularity&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Limited modularity'''. Program is divided into modules or per say procedures independent of each other but are constrained due to uniqueness to that particular problem. || '''Extremely modular''' due to the presence of objects which contain their own data and sub-routines.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Data Protection/Hiding&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''No concept of data-hiding'''. Variables local to one method cannot be accessed by other method. But, Global variables can be accessed anywhere within the program. || One of the main fundamentals of O-O languages.''' Access specifiers''' like 'public', 'private' and 'protected' dictate the rules of data-hiding. Data which is private is confined to one object and cannot be directly changed by any other method except its own. This places the responsibility of managing data with the object itself This is called as ownership. Thus, data can be accessed ( read/write/modified )''' only''' through the object's own interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Ease of Understanding&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Smaller programs''' are '''easy to understand''' but as the program increases in size; understanding the code becomes more and more difficult. || '''Easy to understand''' due to its real world-like design and flow.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Reuse of Code&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Very Limited or no''' code re-usability. ||'''Highly re-usable code''' as the code developed can be easily modified or extended to suit a problem's need.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Support for declaring new data types/classes&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Difficult '''due to limited in-built functionality. || '''Easily possible''' due to the concept of classes. Generic classes can be built as per the required specifications.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Efficiency&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Efficient''' for solving '''small''' problems. || '''Efficient''' for solving '''large problems''' which have a complex structure and require complex data-types, abstraction and data-security.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintenance&amp;lt;/b&amp;gt;&lt;br /&gt;
| Maintenance is''' easy for smaller programs''' but can consume''' a-lot of effort for larger program''' size as it requires the programmer to know and understand the dependencies of every module in the program. This makes it difficult to debug and test the program. ||'''Extremely simple''' as O-O languages aim for high modularity. Secondly, programmer is not concerned with the details of how the data is stored and represented. Thirdly, they also tend to keep low coupling which makes it easy to debug and test different modules in the program.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less Extensible''' as modules developed need to be re-organised and re-structured heavily in order to meet different needs. || '''High extensibility''' is one of the most important advantages of OOP. Code can be easily modified and 'plugged-in' to a different program. Methods can be exteneded due to many properties such as polymorphism, inheritance and support for multiple inheritance through interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Flexibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less flexible.''' Sometimes, certain problems do not fit into the 'top-down design' approach. || '''High flexibility.''' The modelling of problems into world-like objects makes it easy to solve any practical problem.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Examples&amp;lt;/b&amp;gt;&lt;br /&gt;
| [http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell], [http://en.wikipedia.org/wiki/Scala_%28programming_language%29 Scala], [http://en.wikipedia.org/wiki/Erlang_%28programming_language%29 Erlang] || [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], [http://en.wikipedia.org/wiki/Python_(programming_language) Python].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Scala : An overview  &amp;lt;ref&amp;gt;http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html&amp;lt;/ref&amp;gt;=&lt;br /&gt;
Scala is an object-functional programming and scripting language generallly used in software applications. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.) and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than most general purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.&lt;br /&gt;
&lt;br /&gt;
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries can be used directly in Scala code, and vice versa. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
object HelloWorld &lt;br /&gt;
{&lt;br /&gt;
   def main(args: Array[String]) &lt;br /&gt;
  {&lt;br /&gt;
    println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program consists of one method called main which takes the command line arguments, an array of strings, as parameter; the body of this method consists of a single call to the predefined method println with the greeting as argument. The main method does not return a value (it is a procedure method). Therefore, it is not necessary to declare a return type. Such a declaration introduces what is commonly known as a singleton object, that is a class with a single instance. The declaration above thus declares both a class called HelloWorld and an instance of that class, also called HelloWorld. This instance is created on demand, the first time it is used. Notice that the main method is not declared as static (like in Java) here. This is because static members (methods or fields) do not exist in Scala. Rather than defining static members, the Scala programmer declares these members in singleton objects.&lt;br /&gt;
&lt;br /&gt;
= Features of Scala &amp;lt;ref&amp;gt;http://www.scala-lang.org/old/node/104&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is object-oriented&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is functional&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.&lt;br /&gt;
Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of right-ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is statically typed&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. &lt;br /&gt;
In particular, the type system supports:&lt;br /&gt;
generic classes, variance annotations, upper and lower type bounds, inner classes and abstract types as object members, compound types, explicitly typed self references, views, and polymorphic methods.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is extensible&amp;lt;/b&amp;gt;===&lt;br /&gt;
In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:&lt;br /&gt;
any method may be used as an infix or postfix operator, and&lt;br /&gt;
closures are constructed automatically depending on the expected type (target typing). A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala interoperates with Java and .NET&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available.&lt;br /&gt;
&lt;br /&gt;
= Similarities between Scala and Java =&lt;br /&gt;
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy,JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.&lt;br /&gt;
&lt;br /&gt;
2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.&lt;br /&gt;
&lt;br /&gt;
3) Major Java programming IDE like Eclipse, Netbeans and InetelliJ supports Scala.&lt;br /&gt;
&lt;br /&gt;
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Scala vs JAVA &amp;lt;ref&amp;gt;http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Syntactic flexibility &amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala has a very powerful and flexible syntax as it relates to methods, both declaration and invocation. In Java you can create methods with different visibilities, modifiers and return types. Scala does allow for different visibilities on not just methods, but any members. &lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person {&lt;br /&gt;
  private var name = &amp;quot;Daniel Spiewak&amp;quot;&lt;br /&gt;
  val ssn = 1234567890    // public constant field&lt;br /&gt;
 &lt;br /&gt;
  def firstName() = splitName()(0)   // public method&lt;br /&gt;
 &lt;br /&gt;
  private def splitName() = name.split(&amp;quot; &amp;quot;)    // private method&lt;br /&gt;
 &lt;br /&gt;
  protected def guessAge() = {&lt;br /&gt;
    import Math._&lt;br /&gt;
    round(random * 20)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala provides the option to import into a specific scope. The import statement within guessAge()is much like a Java static import statement which only provides access to the Math members within theguessAge() method. So we couldn’t just make a call to round() from within the splitName() method.&lt;br /&gt;
Scala access modifiers are also quite a bit more powerful than Java’s. For example,protected by default limits access to only subclasses, unlike Java which also allows access to other classes in the same package.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Unified type system&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). Only reference types are part of the inheritance scheme, deriving from java.lang.Object. In Scala, however, all types inherit from a top-level class Any, whose immediate children are AnyVal(value types, such as Int and Boolean) andAnyRef (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala; boxing and unboxing is completely transparent to the user. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;For-expressions&amp;lt;/b&amp;gt;===&lt;br /&gt;
Instead of the Java &amp;quot;foreach&amp;quot; loops for looping through an iterator, Scala has a much more powerful concept of for-expressions. These are similar to list comprehensions in languages such as Haskell, or a combination of list comprehensions and generator expressions in Python. For-expressions using the yield keyword allow a new collection to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of map, flatMap and filter calls. Where yield is not used, the code approximates to an imperative-style loop, by translating to foreach. A simple example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val s = for (x &amp;lt;- 1 to 25 if x*x &amp;gt; 50) yield 2*x&lt;br /&gt;
The result of running it is the following vector:&lt;br /&gt;
Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Everything is an expression&amp;lt;/b&amp;gt;===&lt;br /&gt;
Unlike C or Java, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning void in Java, and statements like while that logically do not return a value, are in Scala considered to return the type Unit, which is a singleton type, with only one object of that type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Java:&lt;br /&gt;
int hexDigit = x &amp;gt;= 10 ? x + 'A' - 10 : x + '0';&lt;br /&gt;
&lt;br /&gt;
//Scala: &lt;br /&gt;
val hexDigit = if (x &amp;gt;= 10) x + 'A' - 10 else x + '0'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Type inference&amp;lt;/b&amp;gt;===&lt;br /&gt;
Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = &amp;quot;foo&amp;quot; (for an immutable, constant variable or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Anonymous functions&amp;lt;/b&amp;gt;===&lt;br /&gt;
In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x =&amp;gt; x &amp;lt; 2, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. &lt;br /&gt;
&lt;br /&gt;
An even shorter form of anonymous function uses placeholder variables: For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list map { x =&amp;gt; sqrt(x) }&lt;br /&gt;
&lt;br /&gt;
can be written more concisely as&lt;br /&gt;
&lt;br /&gt;
list map { sqrt(_) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutability&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with val while mutable variables use var. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Tail recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround. Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released July 14, 2010).&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pattern matching in Scala is really a lot like Java’s switch/case construct.  So in Java, one might write something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public boolean checkPrime(int number) {&lt;br /&gt;
    // checks if a number between 1 and 10 is prime&lt;br /&gt;
    switch (number) {&lt;br /&gt;
        case 1: return true;&lt;br /&gt;
        case 2: return true;&lt;br /&gt;
        case 3: return true;&lt;br /&gt;
        case 5: return true;&lt;br /&gt;
        case 7: return true;&lt;br /&gt;
 &lt;br /&gt;
        default: return false;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the major limitations of switch/case in Java  is that it can only be used on primitives.  You can’t use switch/case to test a String, for example (a need which arises more often than one would think).  In fact, the most complex type testable within switch/case is the Enum, and even this is just being reduced to its ordinal values under the surface.&lt;br /&gt;
The designers of Scala chose not to include this “feature” in their new language. Instead, they implemented a “new” concept called pattern matching. At a basic level, it allows algorithms which are very similar to the checkPrime(int) example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def checkPrime(number:Int):Boolean = {&lt;br /&gt;
  number match {&lt;br /&gt;
    case 1 =&amp;gt; return true&lt;br /&gt;
    case 2 =&amp;gt; return true&lt;br /&gt;
    case 3 =&amp;gt; return true&lt;br /&gt;
    case 5 =&amp;gt; return true&lt;br /&gt;
    case 7 =&amp;gt; return true&lt;br /&gt;
 &lt;br /&gt;
    case _ =&amp;gt; return false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The biggest difference which likely jumps out at you is the lack of a default statement. Instead, we see the return of Scala’s ubiquitous wildcard character, the underscore. Literally read, this example means: match the value within number; in the case that it is 1, return true; in the case that it is 2, return true; …; for any previously unmatched value, return false.&lt;br /&gt;
Scala case statements can’t “overflow” into each-other (causing multiple matches) like Java’s can, so even if we weren’t returning values, the algorithm would still be safe.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java’s designers recognized the need for multiple typing (e.g. CollegeStudent is both a Student and a Worker), but they wanted to avoid the issues associated with inheriting conflicting method definitions along multiple paths.  Their solution was to design the interface mechanism, a feature which allows multiple typing without the complications of multiple inheritance.  &lt;br /&gt;
Scala recognizes that interfaces have their issues.  So rather than blinding creating a reimplementation of the same problems found in either Java or C++, Scala takes a new approach.  Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
trait Book &lt;br /&gt;
{&lt;br /&gt;
  def title:String&lt;br /&gt;
  def title_=(n:String):Unit&lt;br /&gt;
 &lt;br /&gt;
  def computePrice = title.length * 10&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala’s traits are quite nice in that they can not only define abstract members, but also full method definitions. At the same time, they allow inheriting classes to inherit from more than one trait. They pass on their type information and implementations to their children, as well as enforcing the abstract members. At first glance, this seems like it would be just as bad as straight-up multiple inheritance, but it turns out the problems have been mitigated in some very clever ways.&lt;br /&gt;
Traits are actually mixins, not true parent classes. Any non-abstract trait members are actually included in the inheriting class, as in physically part of the class. Well, not physically, but you get the picture. It’s as if the compiler performs a cut-and-paste with the non-abstract members and inserts them into the inheriting class. This means that there’s no ambiguity in the inheritance path, meaning no diamond problem. We can rewrite our CollegeStudent example in Scala without redundancy or fear of paradox:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Person {&lt;br /&gt;
  def schedule:Schedule&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Student extends Person {&lt;br /&gt;
  private var classSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = classSchedule&lt;br /&gt;
 &lt;br /&gt;
  def learn() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Worker extends Person {&lt;br /&gt;
  private var workSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = workSchedule&lt;br /&gt;
 &lt;br /&gt;
  def work() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class CollegeStudent(school:School, company:Company) extends Student with Worker {&lt;br /&gt;
  // ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if we make a call to the schedule method on an instance of CollegeStudent, the compiler knows that we’re referring to the implementation of schedule in the Worker trait.  This is because Worker was mixed in after the Student trait.  &lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Further reading =&lt;br /&gt;
# [http://vimeo.com/20293743 Video to learn about Scala]&lt;br /&gt;
# [http://docs.scala-lang.org/tutorials/ Scala Documentation]&lt;br /&gt;
# [http://shipilev.net/blog/2014/java-scala-divided-we-fail/#_analyzing_bottlenecks Java vs. Scala]&lt;br /&gt;
# [http://www.cs.uku.fi/~mnykanen/FOH/lectures1.pdf  Salient Features of Functional Programming]&lt;br /&gt;
# [https://www.cs.rpi.edu/research/pdf/10-04.pdf Comparison of Object-oriented and Functional Programming]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88396</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 9 aa</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_9_aa&amp;diff=88396"/>
		<updated>2014-09-25T20:46:34Z</updated>

		<summary type="html">&lt;p&gt;Aashetty: /* Recursion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Functional Programming?  =&lt;br /&gt;
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. The programming is done with the use of expressions, that is, it is a [http://en.wikipedia.org/wiki/Declarative_programming declarative programming] paradigm. One key feature in a functional language is the concept of [http://en.wikipedia.org/wiki/First-class_function first-class functions]. The idea is that you can pass functions as parameters to other functions and return them as values. Also, the output value of a function depends only on the arguments that are input to the function, unlike in [http://en.wikipedia.org/wiki/Imperative_programming imperative programming] languages. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behaviour of a program, which is one of the key motivations for the development of functional programming.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_programming&amp;lt;/ref&amp;gt;&lt;br /&gt;
Some examples of functional programming languages:&lt;br /&gt;
&lt;br /&gt;
*Common Lisp&lt;br /&gt;
*Scheme&lt;br /&gt;
*Erlang&lt;br /&gt;
*Haskell&lt;br /&gt;
&lt;br /&gt;
= What is Object Oriented Programming? =&lt;br /&gt;
Object-oriented programming (OOP) is based upon the concept of real world &amp;quot;objects&amp;quot;. These objects have data fields called attributes that describe the object and some procedures associated with them called methods. Object-oriented programming takes the view that what we really care about the objects we want to manipulate rather than the logic required to manipulate them.&lt;br /&gt;
&lt;br /&gt;
Some examples of object oriented programming languages are:&lt;br /&gt;
&lt;br /&gt;
*Simula&lt;br /&gt;
*Smalltalk&lt;br /&gt;
*C++&lt;br /&gt;
*Java&lt;br /&gt;
*C#&lt;br /&gt;
&lt;br /&gt;
= Features of Functional Programming&amp;lt;ref&amp;gt;http://en.wikibooks.org/wiki/Computer_Programming/Functional_programming&amp;lt;/ref&amp;gt; =&lt;br /&gt;
===&amp;lt;b&amp;gt;Higher-order functions:&amp;lt;/b&amp;gt;===&lt;br /&gt;
Higher-order functions (HOFs) are functions that take other functions as their arguments. A basic example of a HOF is map which takes a function and a list as its arguments, applies the function to all elements of the list, and returns the list of its results. Higher-order functions are very useful for refactoring code and reduce the amount of repetition.&lt;br /&gt;
Let’s see an example of a higher order function that receives a message, transforms it in various ways, and forwards it to another server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class MessageHandler {&lt;br /&gt;
    	void handleMessage(Message msg, Function getClientCode) {&lt;br /&gt;
        	// ...&lt;br /&gt;
        	Message msg1 = msg.setClientCode(getClientCode());&lt;br /&gt;
        	// ...&lt;br /&gt;
        &lt;br /&gt;
        	sendMessage(msg1);&lt;br /&gt;
    	}&lt;br /&gt;
    &lt;br /&gt;
    	// ...&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeOne() {&lt;br /&gt;
    	return &amp;quot;ABCD_123&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	String getClientCodeTwo() {&lt;br /&gt;
    	return &amp;quot;123_ABCD&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	MessageHandler handler = new MessageHandler();&lt;br /&gt;
	handler.handleMessage(someMsg, getClientCodeOne);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we see that we have created no new types and no class hierarchy. We simply pass appropriate functions as a parameter. We don't restrict ourselves to class hierarchies: we can pass new functions at runtime and change them at any time with a much higher degree of granularity with less code.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Purity&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.haskell.org/haskellwiki/Functional_programming&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Some functional languages allow expressions to yield actions in addition to return values. These actions are called side effects to emphasize that the return value is the most important outcome of a function (as opposed to the case in imperative programming). Languages that prohibit side effects are called pure. Even though some functional languages are impure they often contain a pure subset that is also useful as a programming language. It is usually beneficial to write a significant part of a functional program in a purely functional fashion and keep the code involving state and I/O to the minimum as impure code is more prone to errors.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutable data&amp;lt;/b&amp;gt;===&lt;br /&gt;
Purely functional programs typically operate on immutable data. Instead of altering existing values, altered copies are created and the original is preserved. Since the unchanged parts of the structure cannot be modified, they can often be shared between the old and new copies, which saves memory. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Referential transparency&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pure computations yield the same value each time they are invoked. This property is called referential transparency and makes possible to conduct equational reasoning on the code. For instance if &lt;br /&gt;
y = f x&lt;br /&gt;
and &lt;br /&gt;
g = h y y&lt;br /&gt;
then we should be able to replace the definition of &lt;br /&gt;
g&lt;br /&gt;
with &lt;br /&gt;
g = h (f x) (f x)&lt;br /&gt;
and get the same result; only the efficiency might change.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Lazy evaluation&amp;lt;/b&amp;gt;===&lt;br /&gt;
Since pure computations are referentially transparent they can be performed at any time and still yield the same result. This makes it possible to defer the computation of values until they are needed, that is, to compute them lazily. [http://en.wikipedia.org/wiki/Lazy_evaluation Lazy evaluation] avoids unnecessary computations and allows, for example, infinite data structures to be defined and used. &lt;br /&gt;
Let’s take a look at the following piece of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String s1 = somewhatLongOperation1();&lt;br /&gt;
String s2 = somewhatLongOperation2();&lt;br /&gt;
String s3 = concatenate(s1, s2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an imperative language the order of evaluation would be clear. Because each function may affect or depend on an external state it would be necessary to execute them in order: first somewhatLongOperation1, then somewhatLongOperation2, followed by concatenate. Not so in functional languages. somewhatLongOperation1 and somewhatLongOperation2 can be executed concurrently because we're guaranteed no function affects or depends on global state. But what if we don't want to run the two concurrently, do we need to run them in order? The answer is no. We only need to run these operations when another function depends on s1 and s2. We don't even have to run them before concatenate is called - we can delay their evaluation until they're required within concatenate. If we replace concatenate with a function that has a conditional and uses only one of its two parameters we may never evaluate one of the parameters at all!&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
[http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html Recursion] is heavily used in functional programming as it is the canonical and often the only way to iterate. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://c2.com/cgi/wiki?PatternMatching&amp;lt;/ref&amp;gt;===&lt;br /&gt;
In the context of pure functional languages, Pattern Matching is a dispatch mechanism: choosing which variant of a function is the correct one to call. Example: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        factorial(0) ::= 1&lt;br /&gt;
	factorial(n) ::= n * factorial(n-1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The function has been given two definitions. Which is used for dispatch when a call is made will depend, in this case, on whether the actual parameter pattern matches 0 or not. The matching is not limited to constants; in general, functions have a [http://en.wikipedia.org/wiki/Type_signature TypeSignature] used for matching. [http://en.wikipedia.org/wiki/Currying Currying] is integrated into this mechanism. &lt;br /&gt;
1.Pattern matching is the compiler's ability to compare both the form and the content of two expressions. It is used in two ways:&lt;br /&gt;
All or part of a data structure may be assigned to one or several variables in a single expression. &lt;br /&gt;
2.A function may have several definitions (clauses), according to the form and/or content of its arguments. This second use is usually combined with the first to initialize the variables that will be used in the clause. &lt;br /&gt;
In both these uses, a pattern match has the additional benefit of making an assertion about the form and/or content of a variable.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Closures&amp;lt;/b&amp;gt;===&lt;br /&gt;
Passing functions around in impure languages is a little bit different than doing it in the confines of lambda calculus and requires support for an interesting feature often referred to as lexical closure. Let's take a look at some sample code. Remember, in this case variables aren't final and functions can refer to variables outside of their scope:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Function makePowerFn(int power) {&lt;br /&gt;
   int powerFn(int base) {&lt;br /&gt;
       return pow(base, power);&lt;br /&gt;
   }&lt;br /&gt;
   return powerFn;&lt;br /&gt;
}&lt;br /&gt;
Function square = makePowerFn(2);&lt;br /&gt;
square(3); // returns 9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function makePowerFn returns a function that takes a single argument and raises it to a certain power. What happens when we try to evaluate square(3)? The variable power isn't anywhere in scope of powerFn because makePowerFn has returned and its stack is long gone. How can square work, then? The language must, somehow, store the value of power somewhere for square to work. What if we create another function, cube, that raises something to the third power? The runtime must now store two copies of power, one for each function we generated using makePowerFn. The phenomenon of storing these values is called a closure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Comparison between Functional Programming and OOP &amp;lt;ref&amp;gt;http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/ch1_1w25_aras&amp;lt;/ref&amp;gt; =&lt;br /&gt;
Let us compare both the programming paradigms with respect to several disctinction attributes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Point of Comparison&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functional Languages&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Object-Oriented Languages&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Primary focus&amp;lt;/b&amp;gt;&lt;br /&gt;
| Functional programming emphasizes on functions that produce results which depend only on their inputs and not on the program state - i.e. pure mathematial functions. || Focus on identifying and''' representing the problem in terms of an 'object'''' which has its own data, sub-routines and state. Different objects in the problem interact by sending messages to each other and thus result in change in its internal state. The final state and values of the objects refer to the solution. It is '''data-centric'''.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Problem Solving Approach&amp;lt;/b&amp;gt;&lt;br /&gt;
| Primarily''' Top-down''' design || '''Identification and design of necessary objects'''. Close to being 'better models of the way the world works'.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Program Flow&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Often sequential''' with program having single point of entry and exit. || '''Complex''' program flow. Can sometimes depend on the internal state of the objects.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Modularity&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Limited modularity'''. Program is divided into modules or per say procedures independent of each other but are constrained due to uniqueness to that particular problem. || '''Extremely modular''' due to the presence of objects which contain their own data and sub-routines.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Data Protection/Hiding&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''No concept of data-hiding'''. Variables local to one method cannot be accessed by other method. But, Global variables can be accessed anywhere within the program. || One of the main fundamentals of O-O languages.''' Access specifiers''' like 'public', 'private' and 'protected' dictate the rules of data-hiding. Data which is private is confined to one object and cannot be directly changed by any other method except its own. This places the responsibility of managing data with the object itself This is called as ownership. Thus, data can be accessed ( read/write/modified )''' only''' through the object's own interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Ease of Understanding&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Smaller programs''' are '''easy to understand''' but as the program increases in size; understanding the code becomes more and more difficult. || '''Easy to understand''' due to its real world-like design and flow.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Reuse of Code&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Very Limited or no''' code re-usability. ||'''Highly re-usable code''' as the code developed can be easily modified or extended to suit a problem's need.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Support for declaring new data types/classes&amp;lt;/b&amp;gt;&lt;br /&gt;
|'''Difficult '''due to limited in-built functionality. || '''Easily possible''' due to the concept of classes. Generic classes can be built as per the required specifications.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Efficiency&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Efficient''' for solving '''small''' problems. || '''Efficient''' for solving '''large problems''' which have a complex structure and require complex data-types, abstraction and data-security.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Maintenance&amp;lt;/b&amp;gt;&lt;br /&gt;
| Maintenance is''' easy for smaller programs''' but can consume''' a-lot of effort for larger program''' size as it requires the programmer to know and understand the dependencies of every module in the program. This makes it difficult to debug and test the program. ||'''Extremely simple''' as O-O languages aim for high modularity. Secondly, programmer is not concerned with the details of how the data is stored and represented. Thirdly, they also tend to keep low coupling which makes it easy to debug and test different modules in the program.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less Extensible''' as modules developed need to be re-organised and re-structured heavily in order to meet different needs. || '''High extensibility''' is one of the most important advantages of OOP. Code can be easily modified and 'plugged-in' to a different program. Methods can be exteneded due to many properties such as polymorphism, inheritance and support for multiple inheritance through interfaces.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Flexibility&amp;lt;/b&amp;gt;&lt;br /&gt;
| '''Less flexible.''' Sometimes, certain problems do not fit into the 'top-down design' approach. || '''High flexibility.''' The modelling of problems into world-like objects makes it easy to solve any practical problem.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* &amp;lt;b&amp;gt;Examples&amp;lt;/b&amp;gt;&lt;br /&gt;
| [http://en.wikipedia.org/wiki/Haskell_%28programming_language%29 Haskell], [http://en.wikipedia.org/wiki/Scala_%28programming_language%29 Scala], [http://en.wikipedia.org/wiki/Erlang_%28programming_language%29 Erlang] || [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby], [http://en.wikipedia.org/wiki/Python_(programming_language) Python].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Scala : An overview  &amp;lt;ref&amp;gt;http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html&amp;lt;/ref&amp;gt;=&lt;br /&gt;
Scala is an object-functional programming and scripting language generallly used in software applications. Scala has full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.) and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than most general purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.&lt;br /&gt;
&lt;br /&gt;
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries can be used directly in Scala code, and vice versa. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
object HelloWorld &lt;br /&gt;
{&lt;br /&gt;
   def main(args: Array[String]) &lt;br /&gt;
  {&lt;br /&gt;
    println(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program consists of one method called main which takes the command line arguments, an array of strings, as parameter; the body of this method consists of a single call to the predefined method println with the greeting as argument. The main method does not return a value (it is a procedure method). Therefore, it is not necessary to declare a return type. Such a declaration introduces what is commonly known as a singleton object, that is a class with a single instance. The declaration above thus declares both a class called HelloWorld and an instance of that class, also called HelloWorld. This instance is created on demand, the first time it is used. Notice that the main method is not declared as static (like in Java) here. This is because static members (methods or fields) do not exist in Scala. Rather than defining static members, the Scala programmer declares these members in singleton objects.&lt;br /&gt;
&lt;br /&gt;
= Features of Scala &amp;lt;ref&amp;gt;http://www.scala-lang.org/old/node/104&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is object-oriented&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is functional&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.&lt;br /&gt;
Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of right-ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is statically typed&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. &lt;br /&gt;
In particular, the type system supports:&lt;br /&gt;
generic classes, variance annotations, upper and lower type bounds, inner classes and abstract types as object members, compound types, explicitly typed self references, views, and polymorphic methods.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala is extensible&amp;lt;/b&amp;gt;===&lt;br /&gt;
In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:&lt;br /&gt;
any method may be used as an infix or postfix operator, and&lt;br /&gt;
closures are constructed automatically depending on the expected type (target typing). A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Scala interoperates with Java and .NET&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available.&lt;br /&gt;
&lt;br /&gt;
= Similarities between Scala and Java =&lt;br /&gt;
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy,JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.&lt;br /&gt;
&lt;br /&gt;
2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.&lt;br /&gt;
&lt;br /&gt;
3) Major Java programming IDE like Eclipse, Netbeans and InetelliJ supports Scala.&lt;br /&gt;
&lt;br /&gt;
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Scala vs JAVA &amp;lt;ref&amp;gt;http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3&amp;lt;/ref&amp;gt;=&lt;br /&gt;
===&amp;lt;b&amp;gt;Syntactic flexibility &amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala has a very powerful and flexible syntax as it relates to methods, both declaration and invocation. In Java you can create methods with different visibilities, modifiers and return types. Scala does allow for different visibilities on not just methods, but any members. &lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person {&lt;br /&gt;
  private var name = &amp;quot;Daniel Spiewak&amp;quot;&lt;br /&gt;
  val ssn = 1234567890    // public constant field&lt;br /&gt;
 &lt;br /&gt;
  def firstName() = splitName()(0)   // public method&lt;br /&gt;
 &lt;br /&gt;
  private def splitName() = name.split(&amp;quot; &amp;quot;)    // private method&lt;br /&gt;
 &lt;br /&gt;
  protected def guessAge() = {&lt;br /&gt;
    import Math._&lt;br /&gt;
    round(random * 20)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala provides the option to import into a specific scope. The import statement within guessAge()is much like a Java static import statement which only provides access to the Math members within theguessAge() method. So we couldn’t just make a call to round() from within the splitName() method.&lt;br /&gt;
Scala access modifiers are also quite a bit more powerful than Java’s. For example,protected by default limits access to only subclasses, unlike Java which also allows access to other classes in the same package.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Unified type system&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java makes a sharp distinction between primitive types (e.g. int and boolean) and reference types (any class). Only reference types are part of the inheritance scheme, deriving from java.lang.Object. In Scala, however, all types inherit from a top-level class Any, whose immediate children are AnyVal(value types, such as Int and Boolean) andAnyRef (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. int vs. Integer) is not present in Scala; boxing and unboxing is completely transparent to the user. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;For-expressions&amp;lt;/b&amp;gt;===&lt;br /&gt;
Instead of the Java &amp;quot;foreach&amp;quot; loops for looping through an iterator, Scala has a much more powerful concept of for-expressions. These are similar to list comprehensions in languages such as Haskell, or a combination of list comprehensions and generator expressions in Python. For-expressions using the yield keyword allow a new collection to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of map, flatMap and filter calls. Where yield is not used, the code approximates to an imperative-style loop, by translating to foreach. A simple example is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
val s = for (x &amp;lt;- 1 to 25 if x*x &amp;gt; 50) yield 2*x&lt;br /&gt;
The result of running it is the following vector:&lt;br /&gt;
Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Everything is an expression&amp;lt;/b&amp;gt;===&lt;br /&gt;
Unlike C or Java, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning void in Java, and statements like while that logically do not return a value, are in Scala considered to return the type Unit, which is a singleton type, with only one object of that type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Java:&lt;br /&gt;
int hexDigit = x &amp;gt;= 10 ? x + 'A' - 10 : x + '0';&lt;br /&gt;
&lt;br /&gt;
//Scala: &lt;br /&gt;
val hexDigit = if (x &amp;gt;= 10) x + 'A' - 10 else x + '0'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Type inference&amp;lt;/b&amp;gt;===&lt;br /&gt;
Due to type inference, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are val x = &amp;quot;foo&amp;quot; (for an immutable, constant variable or immutable object) or var x = 1.5 (for a variable whose value can later be changed). Type inference in Scala is essentially local.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Anonymous functions&amp;lt;/b&amp;gt;===&lt;br /&gt;
In Scala, functions are objects, and a convenient syntax exists for specifying anonymous functions. An example is the expression x =&amp;gt; x &amp;lt; 2, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. &lt;br /&gt;
&lt;br /&gt;
An even shorter form of anonymous function uses placeholder variables: For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list map { x =&amp;gt; sqrt(x) }&lt;br /&gt;
&lt;br /&gt;
can be written more concisely as&lt;br /&gt;
&lt;br /&gt;
list map { sqrt(_) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Immutability&amp;lt;/b&amp;gt;===&lt;br /&gt;
Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with val while mutable variables use var. &lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Tail recursion&amp;lt;/b&amp;gt;===&lt;br /&gt;
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. Trampolines have been suggested as a workaround. Trampoline support has been provided by the Scala library with the object scala.util.control.TailCalls since Scala 2.8.0 (released July 14, 2010).&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Pattern Matching&amp;lt;/b&amp;gt;===&lt;br /&gt;
Pattern matching in Scala is really a lot like Java’s switch/case construct.  So in Java, one might write something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public boolean checkPrime(int number) {&lt;br /&gt;
    // checks if a number between 1 and 10 is prime&lt;br /&gt;
    switch (number) {&lt;br /&gt;
        case 1: return true;&lt;br /&gt;
        case 2: return true;&lt;br /&gt;
        case 3: return true;&lt;br /&gt;
        case 5: return true;&lt;br /&gt;
        case 7: return true;&lt;br /&gt;
 &lt;br /&gt;
        default: return false;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One of the major limitations of switch/case in Java  is that it can only be used on primitives.  You can’t use switch/case to test a String, for example (a need which arises more often than one would think).  In fact, the most complex type testable within switch/case is the Enum, and even this is just being reduced to its ordinal values under the surface.&lt;br /&gt;
The designers of Scala chose not to include this “feature” in their new language. Instead, they implemented a “new” concept called pattern matching. At a basic level, it allows algorithms which are very similar to the checkPrime(int) example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def checkPrime(number:Int):Boolean = {&lt;br /&gt;
  number match {&lt;br /&gt;
    case 1 =&amp;gt; return true&lt;br /&gt;
    case 2 =&amp;gt; return true&lt;br /&gt;
    case 3 =&amp;gt; return true&lt;br /&gt;
    case 5 =&amp;gt; return true&lt;br /&gt;
    case 7 =&amp;gt; return true&lt;br /&gt;
 &lt;br /&gt;
    case _ =&amp;gt; return false&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The biggest difference which likely jumps out at you is the lack of a default statement. Instead, we see the return of Scala’s ubiquitous wildcard character, the underscore. Literally read, this example means: match the value within number; in the case that it is 1, return true; in the case that it is 2, return true; …; for any previously unmatched value, return false.&lt;br /&gt;
Scala case statements can’t “overflow” into each-other (causing multiple matches) like Java’s can, so even if we weren’t returning values, the algorithm would still be safe.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Traits&amp;lt;/b&amp;gt;===&lt;br /&gt;
Java’s designers recognized the need for multiple typing (e.g. CollegeStudent is both a Student and a Worker), but they wanted to avoid the issues associated with inheriting conflicting method definitions along multiple paths.  Their solution was to design the interface mechanism, a feature which allows multiple typing without the complications of multiple inheritance.  &lt;br /&gt;
Scala recognizes that interfaces have their issues.  So rather than blinding creating a reimplementation of the same problems found in either Java or C++, Scala takes a new approach.  Inspired by a combination of Java’s interfaces and Ruby’s mixins, the designers of Scala have created the trait construct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
trait Book &lt;br /&gt;
{&lt;br /&gt;
  def title:String&lt;br /&gt;
  def title_=(n:String):Unit&lt;br /&gt;
 &lt;br /&gt;
  def computePrice = title.length * 10&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Scala’s traits are quite nice in that they can not only define abstract members, but also full method definitions. At the same time, they allow inheriting classes to inherit from more than one trait. They pass on their type information and implementations to their children, as well as enforcing the abstract members. At first glance, this seems like it would be just as bad as straight-up multiple inheritance, but it turns out the problems have been mitigated in some very clever ways.&lt;br /&gt;
Traits are actually mixins, not true parent classes. Any non-abstract trait members are actually included in the inheriting class, as in physically part of the class. Well, not physically, but you get the picture. It’s as if the compiler performs a cut-and-paste with the non-abstract members and inserts them into the inheriting class. This means that there’s no ambiguity in the inheritance path, meaning no diamond problem. We can rewrite our CollegeStudent example in Scala without redundancy or fear of paradox:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Person {&lt;br /&gt;
  def schedule:Schedule&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Student extends Person {&lt;br /&gt;
  private var classSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = classSchedule&lt;br /&gt;
 &lt;br /&gt;
  def learn() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
trait Worker extends Person {&lt;br /&gt;
  private var workSchedule:Schedule = ...&lt;br /&gt;
 &lt;br /&gt;
  override def schedule = workSchedule&lt;br /&gt;
 &lt;br /&gt;
  def work() = {...}&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class CollegeStudent(school:School, company:Company) extends Student with Worker {&lt;br /&gt;
  // ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now if we make a call to the schedule method on an instance of CollegeStudent, the compiler knows that we’re referring to the implementation of schedule in the Worker trait.  This is because Worker was mixed in after the Student trait.  &lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Further reading =&lt;br /&gt;
# [http://vimeo.com/20293743 Video to learn about Scala]&lt;br /&gt;
# [http://docs.scala-lang.org/tutorials/ Scala Documentation]&lt;br /&gt;
# [http://shipilev.net/blog/2014/java-scala-divided-we-fail/#_analyzing_bottlenecks Java vs. Scala]&lt;br /&gt;
# [http://www.cs.uku.fi/~mnykanen/FOH/lectures1.pdf  Salient Features of Functional Programming]&lt;br /&gt;
# [https://www.cs.rpi.edu/research/pdf/10-04.pdf Comparison of Object-oriented and Functional Programming]&lt;/div&gt;</summary>
		<author><name>Aashetty</name></author>
	</entry>
</feed>