Monday, September 17, 2012

D Programming Language

 
A, B, C,...D! Programming Language



I. Formal Definition
           The D programming language is an object-oriented, imperative, multi-paradigm system programming language and is originated as a re-engineering of C++. Even though it is mainly influenced by that language, D has redesigned some C++ features and has been influenced by concepts used in other programming languages, such as Java, Python, Ruby, C#, and Eiffel. In addition, D is a language with C-like syntax and static typing which pragmatically combines efficiency, control, and modeling power, with safety and programmer productivity. 


 II.  History
Walter Bright is a computer programmer known for being the designer of the D programming language. He decided to start working on this language in 1999 and was first released in December 2001. In January 2007, D reached version 1.0 which concentrated on the imperative, object oriented and meta-programming paradigms, similar to C++. D community created an alternative runtime and standard library in which they named as Tango. 

In June 2007, version 2.0 was released. The beginning of D 2.0's development signaled the stabilization of the first version of the language since it is been in maintenance, only receiving corrections and implementation bug fixes. D 2.0 added numerous other language features, such as closures, purity, and support for the functional and concurrent programming paradigms. D 2.0 also solved standard library problems by separating the runtime from the standard library. The completion of a D 2.0 Tango port was announced in February 2012.



III. What does it do? 

  • Binary C Compatibility
               D programs can import and link against C code and libraries, providing D with free access to a huge amount of pre-written code. Note, however, that D is not link-compatible with C++, so pure C wrappers are required to access C++ code in D.
  • Systems Programming
             Because D is compiled to binary rather than bytecode, and it does not run inside a virtual machine, D can be used for systems and low-level programming. It allows in-line assembly, and the garbage collector can be regulated (or even disabled) if real-time capabilities are necessary.
  • Lexicial, Syntactic, and Semantic Clarity
            One of the major goals of D is to eliminate a lot of the complexity of C++ that has made it so hard for compilers to live up to the standard. A simplified syntax makes the job of both the compiler and the programmer easier, as it allows compilers to be more efficient and reduces the likelihood of compiler bugs. As an example, D drops the much-contested angular bracket syntax for declaring templates, making code easier both to read and parse.
  • Design-by-Contract and Automatic Testing
            D advocates the use of design-by-contract and provides built-in facilities for automatic unit-testing. While both are technically possible in C++, D makes them core tenets of the language to make them easier to use for novices. The hope is that with testing built into the language bugs will be easier to identify and fix, especially if programmers get into the habit of using the testing features.
  • Removal of Archaic Features
            Probably the language's greatest goal is the elimination of archaic and/or needlessly complicated features. For instance, D does away completely with the C preprocessor, relying instead on built-in versioning capabilities. Forward declarations are out the window on the same token. Also, it replaces the often-complicated multiple inheritance of C++ with Java's single inheritance and interfaces. Most of these features are also related with the above of clarity, making the code easier for a human to read as well as easier for a compiler to convert into binary.



Some addition on its features:
         
           The inline assembler typifies the differentiation between D and application languages like Java and C#. It allows a programmer to enter machine-specific assembly code alongside standard D code—a technique often used by systems programmers to access the low-level features of the processor needed to run programs that interface directly with the underlying hardware, such as operating systems and device drivers. Built into the language is a documentation generator called Ddoc.


IV. Advantages


  • D allows writing large code fragments without redundantly specifying types, like dynamic languages do.
  • Automatic memory management makes for safe, simple and robust code.
  • Built-in linear and associative arrays, slices and ranges make daily programming simple and pleasant for tasks, both small and large.
  •  

V. Disadvantages 
  •  It is not predictable when a collection gets run, so the program can arbitrarily pause.
  • The time it takes for a collection to run is not bounded. While in practice it is very quick, this cannot be guaranteed.
  •  All threads other than the collector thread must be halted while the collection is in progress.





VI. Sample Code

Hello World Program
 

Factorial Program


Fibonacci Sequence Program



VII. Updates / Recent News

DFL 0.9.8 release


Highlights include:
  • ToolBar control added.
  • ImageList added, including image support to controls ToolBar, ListView and TreeView.
  • Now works with version 2 D compilers! but this is not officially supported since D 2.x is a moving target.
  • Updated support for D compilers and Tango library.
Check this link for further details: http://www.dprogramming.com/dfl.php



VIII. Shoutouts! 
     “It seems to me that most of the ‘new’ programming languages fall into one of two categories: Those from academia with radical new paradigms and those from large corporations with a focus on RAD and the web. Maybe it’s time for a new language born out of practical experience implementing compilers.” -- Michael

“Great, just what I need.. another D in programming.” -- Segfault

"I have heard of D but never really bothered to read about its salient features. I was hoping to learn something from your posting on D but unfortunately there isn’t much (I will follow the links you provide). Dare I say, compiler writing and language design are orthogonal skills? It might be better to characterize Walter as a talented language designer." -- PhilM

IX. Sources

http://www.informit.com/articles/article.aspx?p=1381876
http://en.wikipedia.org/wiki/D_(programming_language)
http://digitalmars.com/d/1.0/index.html
http://www.dprogramming.com/
http://en.wikibooks.org/wiki/D_Programming#gdc
http://en.wikibooks.org/wiki/D_(The_Programming_Language)/d2/Lesson_6
http://en.wikibooks.org/wiki/D_(The_Programming_Language)/d2/Intro_to_Functions
http://progopedia.com/language/d/
http://thecybershadow.net/d/Memory_Management_in_the_D_Programming_Language.pdf
http://progopedia.com/example/factorial/140/
http://www.docwiki.net/view.php?pageid=92
http://lambda-the-ultimate.org/node/2421
http://www.johndcook.com/blog/2012/04/12/d-programming-language/


X. Credits

Members: CMSC 124 T-6L

Abelardo, Darwin James A. 2010-60334
Dimacuha, Samantha Patricia A. 2010-56586
Flores, Paulene Nicole DC. 2010-50427
Gasis, Christian Ray B. 2010-01699
 


Friday, September 14, 2012

LOVE MATLAB


MATLAB

MATrix LABoratory is a high level language with interactive environment developed by MathWorks. It was designed to aid numerical computation, visualization and application development. It also allows matrix manipulations, plotting of functions and data, and interfacing with programs written in other languages like C, C++, Java and Fortran. One can write programs and develop algorithms faster than traditional languages.

Key Features
  • Interactive environment for iterative exploration, design, and problem solving 
  • Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, numerical integration, and solving ordinary differential equations 
  • Built-in graphics for visualizing data and tools for creating custom plots 
  • Tools for building applications with custom graphical interfaces


NUMERIC COMPUTATIONS (Methods)

  • Interpolation and regression 
  • Differentiation and integration 
  • Linear systems of equation 
  • Fourier analysis 
  • Eigenvalues and singular values 
  • Ordinary differential equations (ODEs) 
  • Sparse matrices


DATA ANALYSIS AND COMPUTATIONS

  • Acquiring Data: Accessing through files, other applications, databases and external devices (e.g. Microsoft Excel, image, sound, video files)
  • Analyzing Data: Manage, filter, and preprocess your data. Add-on products provide capabilities for curve and surface fitting, multivariate statistics, spectral analysis, image analysis, system identification, and other analysis tasks
  • Visualizing Data: MATLAB provides built-in 2-D and 3-D plotting functions; Plots can be customized either interactively or programmatically. 
MATLAB Plot Gallery

  • Documenting and Sharing Results: Automatically generates a report when you execute a MATLAB program. The report contains your code, comments, and program results, including plots. Reports can be published in a variety of formats, such as HTML, PDF, Word, or LaTeX.


PROGRAMMING AND ALGORITHM DEVELOPMENT
MATLAB provides features of traditional programming languages, including flow control, error handling, and object-oriented programming (OOP). You can use fundamental data types or advanced data structures, or you can define custom data types.

Development Tools: MATLAB includes a variety of tools for efficient algorithm development including: 
  • Command Window - Lets you interactively enter data, execute commands and programs, and display result 
  • MATLAB Editor - Provides editing and debugging features, such as setting breakpoints and stepping through individual lines of code 
  • Code Analyzer - Automatically checks code for problems and recommends modifications to maximize performance and maintainability 
  • MATLAB Profiler - Measures performance of MATLAB programs and identifies areas of code to modify for improvement 

APPLICATION DEVELOPMENT AND DEPLOYMENT

Designing Graphical User Interface: Using GUIDE (Graphical User Interface Development Environment), you can lay out, design, and edit custom graphical user interfaces. You can include common controls such as list boxes, pull-down menus, and push buttons, as well as MATLAB plots. Graphical user interfaces can also be created programmatically using MATLAB functions.


WHO'S WHO?

Cleve Barry Moler

Cleve Moler is the chief mathematician, chairman, and cofounder of MathWorks. He received his bachelor's degree from Caltech in 1961 and Ph.D. from Stanford University. He is the chairman of the computer science department at the University of Mexico when he started developing MatLab in the 1970s. His design of MatLab is intended to give his students access to LINPACK and EISPACK without them having to learn Fortran.



According to Moler, his creation of MatLab was very primitive, written in Fortran and was hardly even a programming language. He acknowledged Jack Little’s involvement in giving a promising debut to MatLab. He added, as he is the Father of MatLab Little is the real heart and soul and the basis for the success of the company, MathWorks.



John (Jack) Little

Jack Little is the president and one of the founders of MathWorks. He holds a bachelors degree in Electrical Engineering and Computer Science from Massachusetts Institute of Technology (1978) and also receive his Master’s degree from Stanford University (1980).

In 1979 Little was first exposed to MatLab during a visit of Cleve Moler to Stanford University. He heard about MATLAB from some friends that took Moler’s course. Realizing the helpful use of MatLab in engineering he then joined Moler and his friend Steve Bangert in rewriting MatLab in C and founding MathWorks in 1984.

HISTORY

The history of MATLAB starts in the early 1970s, with the development of two libraries of FORTRAN mathematical subroutines in the mid-1970s under a grant from the National Science Foundation. These two libraries were called LINPACK and EISPACK.

LINPACK was written by Jack Dongarra, Jim Bunch, Cleve Moler, and Pete Stewart.

 Jim Bunch                                 Jack Dongarra                               Pete Stewart

In order to make these packages easier for students to use, Moler created MATLAB, whose name is a contraction of "Matrix Laboratory."

The original MATLAB was a FORTRAN program designed for the era of timesharing and ASCII terminals. It had only one data type (the matrix of complex doubles) and a fixed collection of 80 functions. Moler used the FORTRAN MATLAB in teaching numerical analysis at Stanford in 1979.

Word of the program reached Jack Little, who grasped the potential of MATLAB in signal processing and control, and the possibility of making a successful software product based on MATLAB for the new IBM PC.

Jack Little and Steve Bangert developed PC MATLAB by porting Moler's code from FORTRAN to C, adding user-defined functions (in effect making MATLAB into a programming language rather than a calculator), improved graphics, and libraries of MATLAB routines, the toolboxes. Moler, Little, and Bangert formed the Mathworks in 1984, with PC MATLAB as the first product. Their first sale was an order for ten copies placed by Professor Nick Trefethen at MIT.

There have been several major revisions and enhancements to MATLAB, including an extended set of graphics tools and primitives, multidimensional arrays and lists (known in MATLAB as cell arrays), classes and objects, economical storage schemes and algorithms for sparse matrices, a debugger, a profiler, a GUI builder, a lower cost student edition, and Just-In-Time (JIT) compilation for improved performance. The computational core has been upgraded through the incorporation LAPACK (a state-of-the-art library for matrix computation), as well as software for computation of definite integrals, integration of ordinary differential equations, and root finders. Toolboxes created by the Mathworks and other contributors have expanded the scope of MATLAB, adding capabilities in areas such as optimization, signal and image processing, fuzzy logic, splines, wavelets, statistics, partial differential equations, bioinformatics, and mathematical finance. SIMULINK, an extensible block diagram environment for simulation and model-based design appeared as a second Mathworks product in 1990.





The Mathworks logo is a picture (generated by MATLAB) of a numerical approximation to the fundamental mode of a vibrating L-shaped membrane, a topic that Moler discussed in his Stanford Ph.D. thesis in 1965.





ACCESSING MATLAB


1 By default, MATLAB console looks like this (with file browser and command history):

2 To use MatLab without console, use –nojvm flag.

3 Matlab can be run in background. For long running labs, there are 2 options.

          a Under csh,

matlab < matlab.in >& matlab.out &

          b Under bash, 

matlab < matlab.in > matlab.out 2>&1 &

Note: Redirecting error messages are critical and cannot be retrieved.

MATLAB BASICS


SYMBOL/ COMMANDS
FUNCTIONS/DESCRIPTION
%
 comment character
Variable Name
 maximum of 63 characters
Three periods (…)
 usually at the end of the line
 allows continuation
;
 terminates displaying of output in the input line
ans
 default object storage
 holds the current object value until the next statement is executed
help (text)
helpwin (separate window)
doc (browser)
lookfor (apropos)
 available help is accessible by using this

Remarks
     1 Use single quotes, not double quotes.
     2 Emacs-style editing is always available at the command line.


SAMPLE CODE

% HELLO is a simple script to say “Hello, world!”
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    26 January 2007
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'HELLO:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  This is how to say:\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Hello, world!\n' );

  quit


>> hello_run
HELLO_RUN will run the "hello.m" M file.
Hello, world!
Elapsed time is 0.024424 seconds.
HELLO_RUN: Normal end of execution.
>> 

Some insights

"Pros"

“At the time, I was still convinced that C was the way to go, so the first advanced item I learned how to do was to use the MEX interface. I eventually realized the error of my ways and slowly began to learn about vectorization and logical indexing through the resident MATLAB guru in my group, and the rest is history! I’m now convinced that MATLAB is one of the best and most accessible programming paradigms in existence for scientific computing.”

-Bryant Tran (Cody Champion)

 "MATLAB is the language of choice for people doing mathematical development".

-Randy Allen, Chief Executive Officer of Catalytic (Palo Alto, Calif.)

Members

Emirrah said, "MATLAB? It's simply AMAZING."
Briar said, "."
Leira said, "One got to love MATLAB because of its fantastic features. In our CMSC150 class, I am so fascinated with how Maxima manipulates such numerical computations. But with what MATLAB has to offer, everything will be easier especially on computing. Furthermore, it is interactive at its finest. I hope UPLB-ICS will use MATLAB in the near future."
Tricia said, "MATLAB is exceptionally a complete programming language at its own field. It has everything any numerical computing has to offer. It is interactive. However it will consume very large chunks of your computer memory. Then again, space has to suffer for wholeness.”

Sources

http://www.mathworks.com/products/matlab/

Brought to you by

lotlotandfriends CMSC 124 T-1L
Dogelio, Emirrah Hazelle
Nuestro, Briar Rose B. 2010-11820
Panol, Maria Leira P.
Posadas, Tricia Joy R.

Tuesday, September 4, 2012

LUA

What is Lua?

Lua is a powerful, fast, lightweight, embeddable scripting language.
Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.


Where does Lua come from?

Lua is a scripting language born in 1993 at PUC-Rio, the Pontifical Catholic University of Rio de Janeiro in Brazil.
Since then, Lua has evolved to become widely used in all kinds of industrial applications, such as robotics, literate programming, distributed business, image processing, extensible text editors, Ethernet switches, bioinformatics, finite element packages, web development, and more. In particular, Lua is one of the leading scripting languages in game development.


What's in a name?

"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
Why choose Lua?

  • PROVEN, ROBUST language
  • FAST   
  • PORTABLE.
  • EMBEDDABLE.
  • POWERFUL (but SIMPLE)
  • SMALL
  • FREE
  • EXPRESSIVE

One-on-One:

  • Lua Vs Python


Lua 's not whitespace sensitive. While this has its downsides when compared with Python, there is no need to worry about automatic editor space-to-tab conversion or vice versa. When using a proportional width font, Lua allows use of as much indentation as necessary to make the code easy to read.


Python is extremely high performance numeric computing (ala scientific and graphics) is possible with an add-on module that implements true multidimensional arrays. Strictly speaking, Lua has no arrays and must use a table structure for them.



When it comes to OO models, Python dictates a specific model for object-oriented programming. It has rich OO capabilities, including metaclasses, multiple inheritance, and so on. Lua does not dictate any particular OO system. Instead you can build your own (using meta-methods) and tailor it to your needs.
  • Lua Vs Perl
Memory Management:

 Lua 5.1 has an incremental garbage collector. Perl uses a simple but efficient reference-based garbage collection that will leak on cycles.


Stability: 

Very few bugs can be found in Lua. The code is small, highly stable, and extensively reviewed. The Perl core is larger, does more, and is much more complex, so naturally it would be harder to ensure validity. That said, Perl is widely used and tested, and the core is generally quite stable. If one includes non-core modules, then Perl may be more stable/mature in general. 

  • Lua Vs Go
Types:
Go has a larger number of built-in types (e.g. integers of various sizes and signedness), whereas Lua code normally just uses the number type (typically floating point).
Multiple  return values are supported by both languages. Strings are immutable in Go and Lua. 
Pointers:
Go has pointers but no pointer arithmetic, for safety. Lua has no pointers.
  • Lua Vs Ruby                                Lua  already had a very good VM which allows Lua programs to be compiled and also to execute a lot faster than Ruby(x2 in most case).

SAMPLE PROGRAMS:

  • Hello World!






  • Factorial



Strings in Lua are subject to automatic memory management, like all Lua objects. That means that you do not have to worry about allocation and deallocation of strings; Lua handles this for you. A string may contain a single letter or an entire book. Lua handles long strings quite efficiently. Programs that manipulate strings with 100K or 1M characters are not unusual in Lua!!!

There is a function called "dofile" which is very useful when you are testing a piece of code. You can work with two windows: One of them is a text editor with your program (in a file prog.lua, say) and the other is a console running Lua in interactive mode. After saving a modification that you make to your program, you execute dofile("prog.lua") in the Lua console to load the new code; then you can exercise the new code, calling its functions and printing the results.



QUOTEs:

“Lua is a brilliant, tiny powerhouse.” 
Lucas Ackerman, in rec.games.roguelike.development (2003).

“Lua - The most useful piece of truly free software I've ever used.” 
David Jeske, in his list of recommended products (2000?).
“This fine, little, free scripting engine is one of the most reusable parts in software industry I ever found. I could not imagine any better way of incorporating a scripting system into a game engine than this one.” 
Harald Nowak, in the Station 5 web site.
“If you compare Scheme and Lua for the things you'd want in a game console scripting language, I think Lua will come out ahead. It's smaller, portable, uses less memory, and is faster.”Steve Dekorte, in comp.lang.objective-c (1997).
“Learn it at once. It's lovely.”
Rob Kendrick, in comp.sys.acorn.programmer (2000).


Heart to Heart :">

"I thought that Lua is just like a child of python but when you read more about it, you'll discover that it offers more. =) It's more readable and writable compare to other PLs. Small but terrible...fast and easy to extend." 
-Vice Ganda 2010-41749 T-9L
 "I think it's cool. But the name sucks." -Zukee 2010-57236    T-9L
Installer for Windows: Lua For Windows
Programming in LuaCode Examples

References:


http://www.lua.org/pil/1.1.html
http://www.lua.org/quotes.html




CMSC 124 LUA MEMBERS:
2010-41749 Vice Ganda
2010-57236 Zukee