570 likes | 750 Views
بسم الله الرحمن الرحيم. اللهم صلي على محمد و ال محمد. مدخــــــــــل الى عالم البرمجة. اعداد علي Perl_sourcer@yahoo.com. What is programming?.
E N D
بسم الله الرحمن الرحيم اللهم صلي على محمد و ال محمد
مدخــــــــــل الى عالم البرمجة اعداد علي Perl_sourcer@yahoo.com
What is programming? • Computer programming (often shortened to programming or coding) is the process of designing, writing, testing, debugging / troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language. The code may be a modification of an existing source or something completely new. The purpose of programming is to create a program that exhibits a certain desired behaviour (customization). The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic.
What do you need? • Text Editor • Compiler or Interpreter
What do you need ? • Or just use and IDE:
What do you need ? • Or just use and IDE:
What do you need ? • Or just use and IDE:
What do you need ? • Or just use and IDE:
What do you need ? • Or just use and IDE:
Program. Langs. Categorization • Microsoft(Windows): vb, asp, C#, .NET..etc • Unix: C|C++, python, perl, php, ruby…etc • Sun JVM: Java, Groovy, Fortress, Scala, Jython…etc.
Programming Paradigm: • A programming paradigm is a fundamental style of computer programming. (Compare with a methodology, which is a style of solving specific software engineering problems.) Paradigms differ in the concepts and abstractions used to represent the elements of a program (such as objects, functions, variables, constraints, etc.) and the steps that compose a computation (assignment, evaluation, continuations, data flows, etc.).
Programming Paradigms: • Procedural • Object Oriented • Event driven • Functional
Sequenced • Like get two numbers, add them, return the result. • {my $number =1; • my $number2 =2; • print $number+$number2; }
Control Structeres • IF statement: • if ($user eq "Ali") • {print "Access granted!"} • Adding else: • else{ print "I don't know you"} • Introducing more conditions: • elsif($user eq "fatima") • {print "I love u!"}
Control Structeres • Unless: • unless($a == 10) • { • print "The number isn't 10";} • if ($a != 10) • { • print "The number isn't 10"; • }
Control Structres: • FOR • for (1..10) • {print "looping 10 times!\n"} • Long style: • for ($a=0;$a<10;$a++) • {print "loop $a"}
Control Structers • Foreach : • my @list = qw/Ali Sara YosraMamdoh/; • foreach (@list){ • print $_, " You are a member of the family!\n"; • }
Control Structers: • WHILE • $a= 10; • while ($a != 0) • {print $a--;} • Ouputs: 10987654321
Control Structers: • Introducing until: • my $controller = 10; • until ($controller == 20) • { • print"going up unitl 19\n"; • $controller++; • }
Control Structers • given( $name ){ • when("Ali"){ say "welcome $name your are the 1st"} • when("Saleh"){say "welcome $name your are the 2nd"} • when("Hashem"){say "welcome $name your are the 3d"} • default{say "I don't know you"}}
Control Structures • use Switch; • switch ( $name ){ • case "Ali" { say "welcome $name your are the 1st"} • case "Saleh" {say "welcome $name your are the 2nd"} • case "Hashem" {say "welcome $name your are the 3d"} • else {say "I don't know you"} • }
Expression Modifiers • use 5.010; • $bool = 1; • $a = 5; • say "I am in love" if $bool; • say "false" unless $bool; • say "my name is", ($a++) while $a < 9;
Records • Variable : can hold one item only; • my $number = 1; • Array: can hold more than one item • my @array = qw\ali yasser salman\; • print $array[0];
Records • Null value: • if (defined($my_total)){} • my $var = undef;
Records • Hashes: • my %hash= qw/ • 0555555 ali • 0666666 yasser • 0899999 basem/; • foreach $phoneNumber(keys %hash) • { • print "$phoneNumber = $hash{$phoneNumber} \n"}
Subroutines: • Chunks of frequent used code: like headers, footers,..etc • &hello(); sub hello(){ • print "welcome to ali website";} • Passing parameters: • &hello("Visitor1"); sub hello(){ • $name = shift; • print "welcome to ali website\n"; • print "welcome $name";}
Subroutines: • Passing more than one item: • &hello("Visitor1","Visitor2"); • sub hello(){my ($name1, $name2) = @_; • print "welcome to ali website\n"; • print "welcome $name1"; • print "welcome $name2";} • Returning: • print &hello(); sub hello(){ • return 1;}
Scoping: • $total = 10; • $number = 12; • &adding($number); • sub adding() • { • $number = shift; • $total = $total + --$number; • } • print $number; • print $total;
Naked block Control Structer • { • my $name = "Ali", $age="24", $location="SA"; • print $name; • print $age; • print $location • }
Regular Expressions: • if($string =~ m/(A|E|I|O|U|Y|a|e|i|o|u|y)/) {print "String contains a vowel!\n"} • $string =~ s/Ali Yami/Ali Qahtani/; • Change everything to upper case: $string =~ tr/[a-z]/[A-Z]/; • Change everything to lower case $string =~ tr/[A-Z]/[a-z]/;
Modules • Ready to use libraries for the language: • Like bindings for GUI libraries, or facilities to work with internet, etc. • CPAN…
Object Oriented • Objects • Data fields • Methods • Classes
Exceptions: • Eval • $total = 13/0; • print $total; • Program fails with: Illegal division by zero
Exceptions • Defensive programming: • $a= 10; • $b = 0; • if ($b == 0){ print"you are trying to divide by zero"} • else { print $a/$b;}
Tests • use Test::Simple tests => 2; • use Date::ICal; • my $ical = Date::ICal->new; # create an object • ok( defined $ical ); # check that we got something • ok( $ical->isa('Date::ICal') ); # and it's the right class