Monday, February 27, 2023 | Permalink
Viewpoint may be largely unrelated to its usefulness. Many if not most of the software we use is probably obsolete according to the latest design criteria. Most users could probably care less if the internals of the operating system they use is obsolete. They are rightly more interested in its performance and capabilities at the user level.
Ken Thompson, The Tanenbaum-Torvalds Debate
This note or tutorial is written as part of the learning process. So, obviously it will have errors in terms of grammar, typo, code, explanation and so on. You are welcome to suggest a correction. The note is concise and contains numerous reference (archive) links for detail/better explanation. Enjoy!
Create a new file with name hello.vala
. Here, hello
is the name of the file and .vala
is the extension of the Vala programming language.
(Of course, you can create this new file in many different ways. I wrote command to make instruction clear!)
Open the created hello.vala
in text-editor of your choice and write the text hello, world as that's what we're interested to print.
This hello, world
text is string
in Vala. String in Vala must be enclosed within double quotes only (single quotes are for characters).
The string hello, world is not going to be printed in terminal by default. We need to invoke printf()
method from stdout
object to print the string in terminal. Don't worry about this stdout
object for now. It is default available in any project to use.
stdout.printf("hello, world")
Vala is one of those programming language that requires semicolon or ;
to terminate the statement.
stdout.printf("hello, world");
Vala, being compiled programming language requires main()
method to start the execution.
int main() {
stdout.printf("hello, world");
}
We need to return 0
from the main()
method at the end as we have already mentioned int
as return type of this method.
int main() {
stdout.printf("hello, world");
return 0;
}
Finally, let's add \n
after hello, world text to print it nicely in terminal.
int main() {
stdout.printf("hello, world\n");
return 0;
}
That's it! This is our hello, world program in Vala!
To run this program, we need to invoke Vala compiler or valac
on this file using following command.
After successful compilation, you'll get hello
(after the name of the file) as an executable. You can simply run this executable using following command.
In other words, you need to run two command to see the final output in Vala.
$ valac hello.vala
$ ./hello
hello, world
Or you can use &&
operator to run both commands in single command line.
$ valac hello.vala && ./hello
hello, world
In future, we'll going to accept the command-line arguments while running the program/application. To make that works, I'm updating the prototype of the main()
method to access the command-line arguments.
int main(string[] args) {
stdout.printf("hello, world\n");
return 0;
}
You wouldn't see any difference while running this program again in terms of output. But, this modification is good to have.
$ valac hello.vala && ./hello
hello, world
Let's do some modifications in this hello.vala
program while on the same time printing the hello, world text in the terminal. How about creating a new method with name greet()
that prints the same hello, world text?
void greet() {
stdout.printf("hello, world\n");
}
int main(string[] args) {
stdout.printf("hello, world\n");
return 0;
}
This greet()
method returns nothing hence I mentioned void
as return type of this method. We can call this method from main()
method at the place of printf()
statement.
void greet() {
stdout.printf("hello, world\n");
}
int main(string[] args) {
greet();
return 0;
}
Even after doing these changes, we'll see the same output in the terminal as it was previously - hello, world text.
$ valac hello.vala && ./hello
hello, world
Let's even go further and print the text world from the name
variable define inside the main()
method as follows.
void greet(string name) {
stdout.printf("hello %s\n", name);
}
int main(string[] args) {
string name = "world";
greet(name);
return 0;
}
In main()
method, we defined the name
variable with world
as the initial value. Then in next line, we passed this defined variable to greet()
method as an argument. We also modifies the greet()
method to accept one string parameter. Finally, we used %s
placeholder to print the value of name
at the place of text world.
Again, running this program prints the same output.
$ valac hello.vala && ./hello
hello, world
This is still hello, world program in Vala but with variable and supporting method.
Let's take a break and meet again to write the hello, world program but this time in object-oriented manner.
Labels: gtk, vala
Saturday, February 25, 2023 | Permalink
ગિરનારનાં પગથિયાં પાર ઢબ ઢબ લાકડીઓ ટેકા લેતી આવતી હતી. નાનાં છોકરાંને તેડીને બે મજૂરણો ચડી આવતી હતી. એમના બોલ મોતી જેવા વીણી શકાતાં હતાં. એક ડોસીનો બોલ પકડાયો: "શું કરું બાઈ? ગાંડી થઇ જાઉં તો મલક ઠેકડી કરશે કે હારીને ગાંડી થઇ ગઈ. એટલે જ રોજ ડુંગરા ચડવા-ઊતરવા રિયા."
જુવાનજોધ દીકરાઓના અકાળ મોત પછી સંસારમાં એકલી થઇ પડેલી શ્રમજીવી મા ઉપહાસ ન થાય તે સારું ઉદ્યમમાં મસ્ત છે; છતાં આપણા વાર્તાકારો એ પાત્રોને ગાંડપણ અને આત્મહત્યા સુધી લઇ જવામાં જ શોભા સમજે છે.
*
ત્રણ ડોળીવાળા ગિરનારની પહેલી ટૂક પર ચોથાની રાહ જોતા હતા.
'આવ્યા, આવ્યા. બાપુ આ આવ્યા.' બોકાનીદાર એક ખડતલ મરદ આવી પહોંચ્યો. 'આહીં ધૂણે આવો. જરા તાપી લ્યો. ચા પી લ્યો.'
મૂંગા મરદે તાપ્યું. ચા પતાવી ડોળી લઈને ચાર મરદો પગથિયાં ઊતરવા લાગ્યાં. અરધો રસ્તો કપાયો તેટલામાં જ 'બાપુ'નો જીવન-ઇતિહાસ જડી ગયો. ચાર દીકરા, દીકરાના પણ જુવાન પરણાવેલા દીકરા, ચાલી નીકળ્યા. દીકરાની ને દીકરાના દીકરાની વહુઓ જુદાં ઘર માંડીને મજૂરીએ ચડી ગઈ હતી. બાપુ એંશી વર્ષની અવસ્થાએ ડોળીઓ ચડાવતા-ઉતારતા રહ્યા છે. એમનો જીવનસંતોષ એક જ હતો: સાઠ વર્ષથી જાત્રાળુ બાયું-બેન્યુંને ગરનાર ચડાવ્યો-ઉતરાવ્યો છે, કોઈની સામે કે'દી ય નજર માંડી નથી, કોઈને કે'દી કષ્ટ દીધું નથી, આઘુંપાછું વેણ કહ્યું નથી.
ડોળી ઊંચકનાર પચાસ-સો મજૂરોનો નૈતિક આદર્શ આ ઇસ્માઇલ-બાપુ છે. એમની આપવીતી એ શ્રમજીઓની મહાગાથા છે. મૂંગું રહેવામાં જ માનવતાનું ગૌરવ સમજનાર એ ડુંગર જેવડું દુખ પચીસ-પચાસ સાથીઓની મૂંગી દિલસોજીથી મધુર બની ટાંટિયામાં જીવન-વાટ ખેંચવાનું જોર મૂકે છે.
આપણે [લેખક] ચીતરીએ છીએ જુદ્ધિ પાત્રસૃષ્ટ્રિ, પલેપલ દયાની યાચનાઓ પુકારતી, દુખ અને અન્યાનના બબડાટા કરતી. આપણને સ્વાનુભવ નથી.
- ઝવેરચંદ મેઘાણી
Labels: ઝવેરચંદ મેઘાણી
Sunday, February 19, 2023 | Permalink
Writing a condition is quite easy in Rust and follow simple and intuitive syntax and rule.
- No need to write the condition within bracket.
fn main() {
let x = 4;
if x % 2 == 0 {
println!("{} is even.", x);
}
}
- The expression must be evaluated to boolean value, otherwise, Rust will complain.
fn main() {
let x = 4;
if x {
println!("{} is even.", x);
}
}
As usual, we've the else
with if
.
fn main() {
let x = 4;
if x % 2 == 0 {
println!("{} is even.", x);
} else {
println!("{} is odd.", x);
}
}
Or you can even use else if
in some specific scenario.
fn main() {
let x = 4;
if x > 0 {
println!("{} is positive.", x);
} else if x < 0 {
println!("{} is negative.", x);
} else {
println!("{} must be zero.", x);
}
}
Labels: rust
Friday, February 17, 2023 | Permalink
Rust is static typed language and we need to define data with the types. The above program works due to a concept called the type inference which is supported by Rust nicely.
When you assign an initial value to a variable, Rust will infer the initial value and based on it, it'll auto assign the default type good type. In following example, the type of x will be i32
as an integer.
fn main() {
let x: i32 = 12;
println!("{}", x);
}
We've few integer data types in Rust such as i8
, i16
, i32
, i64
, and i128
as signed integer and u8
, u16
, u32
, u64
and u128
as unsigned integer.
fn main() {
let x: u8 = 12;
println!("{}", x);
}
If the assigned value contains decimal point in it, it'll be treated as floating-point number and the default value will be f64
. For the float, we've f32
and f64
and f64
being the default one.
fn main() {
let x = 13.3;
println!("{}", x);
}
As usual, we've more primitive data types as we have found in other programming language such as char
for character with single character. The main difference in Rust that you'll notice is, you can have the UTF-8 character. The default and the only type for the character is char
.
fn main() {
let x = '🥳';
println!("{}", x);
}
Finally, the bool
or boolean is yet another primitive data type that has true
and false
as one of the possible values.
fn main() {
let x: bool = true;
println!("{}", x);
}
We've seen the string in double quotes. But, string is not the primitive data type in Rust. We'll talk about string in future.
Labels: rust
Tuesday, February 14, 2023 | Permalink
let
keyword is used to define a variable in Rust.
fn main() {
let name = "Bruce";
println!("Hello, {}", name);
}
We can define as many variables as we want using let
. But, we need to use them once defined. Otherwise, compiler will throw a warning (not error) as unused variables.
fn main() {
let name = "Bruce";
let age = 29;
println!("Hello, {}", name);
}
Even further, compiler also suggests the variable to prefix with _
if variable is defined in this way (defined but no plan to use for now) to remove the warning.
let
actually create an immutable variable. In other words, you can't change the value of it once defined. You'll get an error about assigning the value to immutable variable.
fn main() {
let x = 12;
x = 13;
println!("{}", x);
}
If we're intentionally plan to change the value as suggested above, we need to mut
the variable.
fn main() {
let mut x = 12;
x = 13;
println!("{}", x);
}
But, this again throw a warning about unused assignment as value 12 that is assigned in above program is re-assigned again before it actually used. So, assigning 12 is useless.
Labels: rust
Sunday, February 12, 2023 | Permalink
We can print as many text on the terminal as we want using println!()
macro. These text are known as string in Rust and must be written enclosed in double quotes only.
fn main() {
println!("hello, world");
println!("how are you?");
}
{}
within println!()
macro is used to substitute the values from associated arguments.
fn main() {
println!("hello, {}", "world");
println!("how are {}?", "you");
}
You can have more than one upto as many as you want substitution in println!()
macro. The order is important in argument. See the second println!()
as an example.
fn main() {
println!("{}, {}", "hello" "world");
println!("{} {} {}?", "how", "you", "are");
}
Labels: rust
Thursday, February 9, 2023 | Permalink
સોળ વર્ષ પહેલાં બાબુ રવીન્દ્રનાથ ઠાકુરે અવાજ ઉઠાવેલો કે રાજદ્વારી રમતો ને પ્રપંચો મૂકી દો. દેશનાયકો, ગામડાં સજીવન કરો, ઠેર ઠેર મેળા ભરો, ઉજાણીઓ કરો,રામાયણ-મહાભારતનો રસ પાવા માંડો. જન્મભૂમિ આજે નાની નાની નદીઓને કિનારે ઊભી ઊભી ગારાનાં ઝૂંપડામાં જૂથની અંદરથી ડોકિયાં કરતી કરતી નાસેલાં સંતાનોને બોલાવે છે. એ સાદ કોઈ સાંભળે છે કે?
- ઝવેરચંદ મેઘાણી
Labels: ઝવેરચંદ મેઘાણી
Wednesday, February 8, 2023 | Permalink
The obvious next step is to create the hello, world application in Nest. Run
the following command to create the hello, world application using Nest CLI.
$ nest new hello-world
Nest will ask you to choose the package manager from the options. Go with the
default npm
(or you can choose yarn
if you like) and
wait for the Nest CLI to scaffold the application and also install the
dependencies of the application.
Once the process is finished, go inside the created
hello-world
application.
$ cd hello-world
Then run the following command to start and run the application (as they
mentioned in logs).
$ npm run start
Then open the http://localhost:3000 in the browser and you should see the
"Hello World!". If that is the case, you just created the hello,
world application in Nest. Congratulations 🎉!
Labels: nest
Sunday, February 5, 2023 | Permalink
Following command will install the Nest CLI. This CLI will help us to scaffold the Nest application and provide the toolchain to do many other important things with Nest application. We'll cover most of the toolchain functionalities in future.
$ npm i -g @nestjs/cli
You might need to wait for a couple of minutes to finish the installation. Once the installation is done, you have the nest
command in your terminal. Run the following command to confirm the installation of Nest CLI or nest
.
$ nest --version
9.1.8
If you see some version as output, you've correctly installed the Nest CLI or nest
on your computer.
Labels: nest
Wednesday, February 1, 2023 | Permalink
Welcome to the first session of the MARN Workshop and in specific 1a of the today's session. This is a day long session where we'll talk/learn about the following topics.
- Introduction
- JavaScript
- ES6
- Node
- NPM
- Basics of Express
You can consider these topics as the sub-sections of today's session. We'll talk about the particular topic and then will give you some space to do the practice or ask questions in form of discussion.
This is an introductory session. We're going to touch these mentioned topics in introductory way, without going more details. The plan with this introductory session is to get you started with MERN and more specifically with Node. Learning each and everything at one go make this session boring and distracting! We're going to learn/talk MERN like child learn natural language, just start to use without knowing the exact details of pronunciations and grammar! Don't worry, we have enough sessions in this workshop to cover the details to make you expert programmer.
Ready? Let's get started with Introduction.
Introduction
In this sub-session, we're going to welcome you and give you a brief introduction on what MERN stack is and why it is popular while confirming the prerequisites for the workshop.
Welcome to the MERN Workshop. I'm Kiran and I'm your instructor for this workshop. In this sub-session, we're going talk about MERN as acronym, what it is popular, and why you should consider MERN as serious option for your career as web developer.
Before we start, following are the assumption we already made about all of you.
- You have installed the all needed software mentioned previously.
- You're web developer.
- You know JavaScript.
Okay! So, M-E-R-N or MERN, what is it and what it stands for? Anybody know? Yeah, right -
- MongoDB
- Express
- React
- Node
But not in this particular order! I mean we're not going to learn these technologies in this mentioned order.
Let me ask you another question after knowing what MERN stands for - Why MERN only, what not P (of PHP) or D (of DotNet)? I mean one can easily create an application using PHP and React or DotNet and MongoDB. But, still these options are less popular (like acronym) than compare to MERN. You'll not hear PRM (PHP, REACT, MySQL) or DRM (DotNet, React, MonogoDB). Why? Anybody know?
The reason is JavaScript. Take a section look at the stack.
- MongoDB
- Express
- React
- Node
You see the common thing between all these four technologies? Yes, all these mentioned technologies use JavaScript as the language to write the code (directly or indirectly).
If you take a look at the agenda of this session then you'll find that we'll start with JavaScript even though we have made assumption about you that you know JavaScript! Because, we think JavaScript is essential for this workshop and covering a little bit JavaScript in the first session wouldn't hurt!
With this we just mark the end of first sub-session "Introduction" of today's session. After a small break we'll start second sub-session "JavaScript". Question?
Labels: mern