Categories
News

Everything You Need to Know About Bash For Loops in Linux

Bash scripts are a highly efficient means of automating tasks, particularly those that take advantage of other existing programs. This automation often requires repeating a similar operation several times, which is precisely where the for loop comes into its own.

Linux and Mac system administrators are typically familiar with scripting via the terminal, but even Windows users can get in on the action with the Windows Subsystem for Linux.

How Bash Scripts Work

A bash script is simply a plain text file containing a series of commands that the bash shell can read and execute. Bash is the default shell in pre-Catalina macOS, and most Linux distributions.

If you’ve never worked with a shell script before, you should begin with the absolute simplest case. This will allow you to practice key concepts including the creation of the script and its execution.

First, create the following file in a convenient location (ideally, open a terminal and navigate to the desired directory first):

#!/bin/bash
echo "Hello, World"

The first line tells whatever runs this program how to run it (i.e. using the bash interpreter). The second is just a command like any other you might enter on the command line. Save that file as hello_world.sh, then:

$ chmod +x hello_world.sh
$ ./hello_world.sh

The chmod command on the first line makes the file executable, meaning that it can be run by typing its name, as in the second line.

If you see the words “Hello, World” appear printed on a line in your terminal, then everything’s working as required.

How For Loops Work

In general programming, there are two main types of for loop: numeric and foreach. The numeric type is traditionally the most common, but in bash usage, it’s usually the other way round.

Numeric for loops typically focus on a single integer which determines how many iterations will be carried out, for example:

for (i = 0; i < 100; i++) {
/* statements to execute repeatedly */
}

This is a familiar-looking for loop that will iterate exactly 100 times, unless i is altered within the loop, or another statement causes execution of the for loop to halt.

Foreach loops, in contrast, tend to operate on structures such as lists or arrays, and iterate for every item within that collection:

people = [ "Peter", "Paul", "Mary" ]
foreach (people as person) {
if (person == "Paul") {
...
}
}

Some languages use a slightly different syntax which swaps the order of collection and item:

people = [ "Peter", "Paul", "Mary" ]
for (person in people) {
if (person == "Paul") {
...
}
}

For in Loops

In bash, the foreach—or for in—loop is more common. The basic syntax is, simply:

for arg in [list]
do
/* statements to execute repeatedly */
/* the value of arg can be obtained using $arg */
done

For example, to iterate through three explicitly-named files:

for file in one.c two.c three.c
do
ls "$file"
done

If such files exist in the current directory, the output from this script will be:

one.c
two.c
three.c

Instead of a fixed set of files, the list can be obtained via a glob pattern (one including wildcards – special characters that represent other characters). In the following example, the for loop iterates across all files (in the current directory) whose names end in ".xml":

for file in *.xml
do
ls -l "$file"
done

Here’s some example output:

$ -rw-r--r-- 1 bobby staff 2436 3 Nov 2019 feed.xml
$ -rw-r--r-- 1 bobby staff 6447 27 Oct 16:24 sitemap.xml

This may look very much like a long-winded way of doing:

$ ls -l *.xml

But there’s a significant difference: the for loop executes the ls program 2 separate times, with a single filename passed to it each time. In the separate ls example, the glob pattern (*.xml) matches filenames first and then sends all of them, as individual command-line parameters, to one instance of ls.

Here’s an example that uses the wc (word count) program to make the difference more obvious:

$ wc -l *.xml
44 feed.xml
231 sitemap.xml
275 total

The wc program counts the number of lines in each file separately, then prints a total count across all of them. In contrast, if wc operates within a for loop:

for file in *.xml
do
wc -l $file
done

You’ll still see the count for each file:

44 feed.xml
231 sitemap.xml

But there is no overall summary total because wc is run in isolation, each time the loop iterates.

When a List is Not a List

There’s a very easy and common mistake when dealing with for loops, due to the way bash handles quoted arguments/strings. Looping through a list of files should be done like this:

for file in one.c two.c

Not like this:

for file in "one.c two.c"

The second example encloses filenames in double-quotes which results in a list with just a single parameter; the for loop will only execute one time. This problem can be avoided by using a variable in such cases:

FILES="one.c two.c"
for file in $FILES
do
...
done

Note that the variable declaration itself does need to enclose its value in double-quotes!

For Without a List

With nothing to iterate through, a for loop operates on whatever command-line arguments were provided to the script when invoked. For example, if you have a script named args.sh containing the following:

#!/bin/sh
for a
do
echo $a
done

Then executing args.sh will give you the following:

$ ./args.sh one two three
one
two
three

Bash recognizes this case and treats for a do as the equivalent of for a in $@ do where $@ is a special variable representing command-line arguments.

Emulating a Traditional Numeric For Loop

Bash scripts often deal with lists of files or lines of output from other commands, so the for in type of loop is common. However, the traditional c-style operation is still supported:

for (( i=1; i<=5; i++ ))
do
echo $i
done

This is the classic form with three parts in which:

  1. a variable is initialised (i=1) when the loop is first encountered
  2. the loop continues so long as the condition (i<=5) is true
  3. each time around the loop, the variable is incremented (i++)

Iterating between two values is a common enough requirement that there’s a shorter, slightly less confusing alternative:

for i in {1..5}
do
echo $i
done

The brace expansion that takes place effectively translates the above for loop into:

for i in 1 2 3 4

Finer Loop Control With Break and Continue

More complex for loops often need a way of exiting early or immediately restarting the main loop with the next value in turn. To do so, bash borrows the break and continue statements that are common in other programming languages. Here’s an example that uses both to find the first file that’s more than 100 characters long:

#!/bin/bash
for file in *
do
if [ ! -f "$file" ]
then
echo "$file is not a file"
continue
fi
num_chars=$(wc -c < "$file")
echo $file is "$num_chars characters long"
if [ $num_chars -gt 100 ]
then
echo "Found $file"
break
fi
done

The for loop here operates on all files in the current directory. If the file is not a regular file (e.g. if it’s a directory), the continue statement is used to restart the loop with the next file in turn. If it’s a regular file, the second conditional block will determine if it contains more than 100 characters. If so, the break statement is used to immediately leave the for loop (and reach the end of the script).

Conclusion

A bash script is a file containing a set of instructions that can be executed. A for loop allows part of a script to be repeated many times. With the use of variables, external commands, and the break and continue statements, bash scripts can apply more complex logic and carry out a wide range of tasks.

Categories
News

Get Started With Jupyter Notebook: A Tutorial | MakeUseOf

If you're an aspiring data scientist that works with Python or R, you need to know how to use Jupyter Notebook. It's an open-source and server-based IDE for manipulating data, sharing live code, as well as managing the data science workflow.

Let's take a look at how you can install and use Jupyter Notebook on your local machine.

How to Install and Launch Jupyter Notebook With Pip

When you install Jupyter Notebook into a virtual environment via the pip install command, you get to run it as an independent package or module in a virtual space.

To use this method, you must have Python installed on your machine. Otherwise, head to the python.org website to download and install the latest version of Python. However, if you're a Mac or Linux user, you probably have Python already installed by default.

If you're a Windows user, ensure that you add Python to the Windows path after installing it to make it executable from the command line.

Once you've satisfied the above conditions, open up the command prompt to your chosen location.

Next, create and activate a Python virtual environment if you've not done so already.

While in that virtual environment, run the pip install notebook command to install Jupyter Notebook.

Next, run jupyter notebook to launch the Jupyter Notebook server in your default browser.

How to Install and Launch Jupyter Notebook With Anaconda Distribution

Anaconda distribution is an IDE manager that lets you install Jupyter Notebook within a conda virtual environment.

You can also avoid the command line technicalities when you use Anaconda distribution. It lets you create and activate your virtual environment and install Jupyter Notebook via its Anaconda Navigator in a few clicks.

To use this option, you must download and install the latest compatible version of Anaconda distribution.

Once you have Anaconda installed on your machine, launch its Anaconda Navigator. To launch it on Windows, you can open up the Windows search bar and search for Anaconda. Then click on Anaconda Navigator in the search result menu to open it up.

Although the base path environment of Anaconda Navigator has Jupyter Notebook pre-installed into it, you need to install a new one each time you create an environment with it.

You can create a conda environment and install Jupyter Notebook into it via the CMD or Anaconda Navigator.

To use the Anaconda Navigator option, on the sidebar of the app, click on Environments.

Next, look to the lower-left corner of the app and click on Create.

Enter a preferred name for your virtual environment in the Name field. Then select your chosen language and click Create to make a conda virtual environment.

Once you successfully create an environment, select it and go to Home. In the Home menu, locate Jupyter Notebook and click on Install to install it in that environment.

Click on Launch once the installation completes.

Optionally, after installing Jupyter Notebook via the Anaconda Navigator, you can open a terminal or command prompt and use the activate env_name command to activate the conda virtual environment you just created.

Replace env_name with the name of the environment you just created via Anaconda Navigator. However, to use this method on Windows, ensure that you add Anaconda to the Windows path.

Alternatively, if you wish to avoid the Anaconda Navigator option entirely, you can create a conda environment and install Jupyter Notebook into it via the terminal only.

To do that, open your terminal and run the command conda create --name env_name. If you're a Windows user, you can use conda.bat create --name env_name.

Use the pip install notebook command to install Jupyter Notebook into that environment. Replace env_name with your preferred name.

Next, launch Jupyter Notebook by running the jupyter notebook command.

Related: Windows CMD Commands You Should Know

NB: Launching Jupyter Notebook via the command line is recommended. That way, you can create a separate folder for your project and make a virtual environment to the folder's location, as well as launch Jupyter Notebook to that same directory.

How to Use Jupyter Notebook

Now that you've installed Jupyter Notebook. Let's take a look at some of the ways you can use it.

Launching Jupyter Notebook takes you to its homepage, where you get to manage your files.

NB: Typically, when you open Jupyter Notebook to an empty directory via the CMD, the homepage also inherits that empty directory. Otherwise, all the files in the parent directory reflect on Jupyter Notebook's homepage.

How to Import a File Into Jupyter Notebook

You might want to work with an external file like an Excel document. You can import that into the Jupyter Notebook's directory if it's not there already.

To import a file into Jupyter Notebook, look to the upper-right corner of the app and click on Upload to browse your PC for a file.

Next, once you've uploaded the file, click on the Upload option appearing next to the file to add it to the parent folder directory.

Working With a New Notebook

Each notebook you open runs your code on files bearing .ipynb extension. To open a notebook or a Kernel, click on New. Then select Python 3.

To save the newly opened notebook with a new name, click on File.

Next, select the Save as option and give your notebook a preferred name.

How to Shut Down a Running Notebook

To shut down a running notebook, head to the homepage and select Running. It loads a list of currently running kernels.

Click on Shutdown next to any notebook you wish to close to deactivate it.

How to Add New Cells in Jupyter Notebook

While in the Jupyter Notebook Kernel, you get to write your code in cells. To add a new cell, click on Insert. Then select your preferred option.

Alternatively, you can use keyboard shortcuts to add new cells. To add a new cell above an existing one, click on it, then hit key A on your keyboard.

To add a cell below, repeat the process above, but this time, press the key B on your keyboard.

To move a cell up or down, tap the target cell. Next, click the arrow-up or arrow-down at the top of the Kernel.

How to Run a Line or Block of Code in Jupyter Notebook

To execute a line or block of code, click on the Run option at the upper part of the Kernel.

To run a code with the keyboard shortcut, hit Ctrl + Enter on your keyboard.

Loading a Dataset With Pandas in Jupyter Notebook: A Practical Example

You can load a data set into the Kernel as well. Let's take a look at the example code below for reading an Excel file with Python:

import pandas as pd
data=pd.read_excel(r"raw_data.xlsx")
data.head(10)

Note that once you import or paste the dataset into your working directory, you can load the Excel file without calling its full path. Press Ctrl + Enter to run the code above.

The code above returns this output:

How to Use Jupyter Notebook's Markdown Property

You can use the markdown property to write mathematical expressions and plain text. To get started with the markdown property of Jupyter Notebook, you need to master some basic syntax and rules.

Take a look at some of the rules below:

  • $: open and close a markdown code
  • limits: denote a limit
  • sum: call the sum symbol
  • alpha: write an alpha symbol
  • beta: write a beta symbol
  • gamma: call a gamma symbol
  • ^{}: superscript a character within the curly braze
  • _{}: write a subscript of the character within the curly braze
  • cap: introduce a cap symbol
  • hat: put a hat symbol above the next character

To see how those rules work in practice, copy the markdown code below and paste it into a cell in the Kernel.

$beta_0{^4} cap hat 6 sum limits partial 5_{2}$

Next, tap the cell containing the code, then look to the top of the Kernel and click the Code dropdown.

Select Markdown from the list. Then run the markdown code.

Alternatively, you can press the key M on your keyboard to switch the selected cell to markdown. Hit the key Y to switch back to Code mode.

However, to get a better hold of the markdown property, you can check out the Jupyter Notebook Markdown Cells docs.

Make the Best Use of Jupyter Notebook

Jupyter Notebook lets you run and share real-time data science code via a local or remote server. With its markdown property, you can also share mathematical expressions and written texts with other people.

In addition to writing code with it, Jupyter Notebook is a productive and educative platform for tutors and learners to run data science or machine learning project chunks collaboratively.

However, this tool offers a lot of other features. The ones we discussed here should get you started.

Categories
News

How to Write a for Loop in Java | MakeUseOf

Loops are very powerful programming tools that will complete a set of instructions until a condition is met. They are very handy and should be one of the first programming concepts that you learn. There are many different types of loops, but for loops are arguably one of the most useful loops.

The For Loop in Java

For loops will continue to execute a block of code until a condition is met. It is important to note that a for loop will check the condition at the beginning of the loop, not the end. This means that if the condition is met, the loop will not start.

For loop syntax is similar across programming languages. So, if you have created a for loop in another programming language, a Java for loop will look familiar. However, if you are not familiar at all with Java, it is recommended that you read a beginner's tutorial before learning advanced topics like for loops.

for([statement1]; [condition]; [statement2]){
//code to execute each loop
}

The keyword for indicates a for loop. The condition that determines how long the loop will continue is located between the brackets. The first statement is run once when the for loop is initiated. The condition defines when the loop should stop. The second statement is executed at the end of every loop. Semicolons mark the end of statement1 and the condition. Typically, the statements are used to create a counter and the condition stops the loop once the counter reaches a specific number. Finally, the code that is executed in each loop is placed between the curly brackets.

public class Main{
public static void main(String[] args) {
for(int i = 1; i < 4; i++){
System.out.print(i);
}
}
}
//Output: 123

In the example above, the for loop prints out the value of i. The keyword for initializes the loop. The variable i is initially set to 1. The condition checks whether i is four or greater. This isn't the case, so our loop is executed. The loop code prints out the value of i, which is still 1 at this point. Once the loop code is completed, i is incremented by one and the loop begins again. At the end of the third loop, i is increased to four. When the next loop begins, our condition is met, so the loop stops.

Related: Core Java Concepts You Should Learn When Getting Started

Nested For Loop

Once you get the hang of a for loop, you should try to create a nested for loop. This is when you have a for loop inside of another for loop. This is an advanced technique because it can be difficult to understand how the two loops will interact. A good way to visualize how nested for loops work is to create the following pattern with a nested for loop.

*
**
***

To create this, we will need one loop to control how many stars are printed on each line, and another loop to control how many lines to create. When you are new to nested for loops it can be difficult to determine which loop is the inner loop. In this case, the loop that prints the stars is the inner loop. We need that loop to run each time a new line is created.

When creating a nested loop, be careful when you choose the name of your counter variables. Although often programmers use a generic i counter, using generic counters becomes confusing when multiple loops interact.

for(int lineCounter = 1; lineCounter < 4; lineCounter++){
for(int starCounter = 1; starCounter <= lineCounter; starCounter++){
System.out.print("*");
}
System.out.print("\n");
}

Let's run through this example to better understand how it works. Our first loop is counting how many lines we make. After the loop executes three times, it will stop. The next loop is a tad more complex. This loop controls how many stars are printed on each line. In our pattern, we want the same number of stars as the line number. The first line has one star, the second two, and the third three. So, we want that loop to print as many stars as our current line counter. After our star loop is completed, the line loop creates a new line by printing \n, which is the command for a new line.

Infinite Loops

One of the dangers of coding any type of loop is that you can accidentally create an infinite loop. These are loops that never stop. Although there are cases when an infinite loop is needed, generally, they are created by accident when the loop's condition is not carefully planned. In these cases, the program will continue to run until you force it to close.

To create an infinite loop, you can use the following syntax:

for(;;){
//code that never stops looping
}

Related: Websites & Apps That Can Help When Learning Java Programming

Using a For Loop with an Array

A common way to use a for loop is to iterate through an array. For example, if you want to print all of the strings in an array, you cannot simply say

System.out.print([array]);

This command would print information about the array, not the contents of the array. To print the contents of the array, you have to print each individual element in the array. This would be time-consuming to code, but you could create a for loop to go through each element.

String[] words = {"Hello", " ", "World", "!"};

for(int i = 0; i < words.length; i ++){
System.out.print(words[i]);
}

Remember, array positions start at zero, not one, so we want our loop to start at zero. Our first loop will print Hello, the second loop will print a space, and so on. After the fourth loop, our counter will be incremented to four, which is not less than the length of the array, which is also four. This will stop the loop.

Output:

Hello World!

For-Each Loop

Although you can use a for loop to iterate over an array, it is easier to use a for-each loop. These loops are designed specifically for arrays. A for each loop will go through each element in an array and execute code. For-each loops have a slightly different syntax. The keyword for is still used, but a condition is not specified.

for([dataType] [arrayElement] : [array]){
//code to be executed
}

Our previous example can be re-written as a for-each loop using this syntax:

String[] words = {"Hello", " ", "World", "!"};

for(String word : words){
System.out.print(word);
}

The loop is started with the keyword for. We then specify that the data in our array are strings. Next, we choose a variable name to refer to the elements in the array as we iterate through the loop. In this case, we used word. This is followed by a colon and the name of the array we want to iterate through. Now, inside our loop, we just have to use the variable word to refer to each element in the array.

When to Use a For Loop

For Loops are great tools that can save you a lot of coding. They are the best type of loop to use when you know exactly how many times you want your loop to run. You can even increase the complexity of for loops by nesting them. Nested for loops are particularly handy when working with multi-dimensional arrays. For loops are easy to learn and an important skill for beginners. This technique is sure to save you from coding unnecessary repetitive code.

Categories
News

How to Set a Background Image in CSS | MakeUseOf

Creating a website is a great way to express yourself. Although there are many website building tools, writing it yourself is a fun way to learn more about how websites work behind the scenes. A good beginner project is to create a website and add a background image with CSS. This project will get you up and running with both HTML and CSS.

What is CSS?

CSS stands for Cascading Style Sheet. It is a programming language that allows you to style markup languages. One such markup language is HTML or Hyper-Text Markup Language. HTML is used to create websites. Although you can control some of the website's style using HTML, CSS offers much more control and design options.

Creating a Basic Website With HTML

Since CSS is just a style language, to use it, we first need something to style. A very basic website will be enough for us to begin playing with CSS. Our page will display "Hello World."

<html>
<head>
</head>
<body>
<p>Hello World</p>
</body>
</html>

In case you are not familiar with HTML, let's quickly go over what all of the elements do. As mentioned, HTML is a markup language, which means that it uses tags to mark what the text is. Whenever you see a word surrounded by <> it is a tag. There are two types of tags, a tag that marks the beginning of a section using <> and one that marks the end of a section using </>. The text within a section is also intended to make this distinction easier to see.

In our example, we have four tags. The html tag indicates which elements are part of the website. The head tag contains the header information that is not displayed on the page but is needed to create the page. All of the displayed elements are between the body tags. We only have one displayed element, the p tag. It tells the web browser that the text is a paragraph.

Related: 10 Simple CSS Code Examples You Can Learn in 10 Minutes

Adding CSS to HTML

Now that we have a simple page, we can customize the style with CSS. Our page is pretty simple right now, and there is not much we can do, but let's begin by making our paragraph stand out so we can distinguish it from the background by adding a border.

<html>
<head>
</head>
<body>
<p style="border-style: solid;" >Hello World</p>
</body>
</html>

Now, our paragraph will be surrounded by a black border. Adding a style description in CSS to our paragraph tag told the website how to style the paragraph. We can add more descriptions. Let's increase the white-space, or padding, around our paragraph and center our text.

<html>
<head>
</head>
<body>
<p style="border-style: solid; padding: 30px; text-align: center" >Hello World</p>
</body>
</html>

Our website looks better, but our HTML is starting to look messy with all of those descriptions in the paragraph tag. We can move this information to our header. Our header is for information that we need to display the website correctly.

<html>
<head>
<style>
p {
text-align: center
}
#ourParagraph {
border-style: solid;
padding: 30px;
}
</style>
</head>
<body>
<p id="ourParagraph" >Hello World</p>
</body>
</html>

Now our HTML is easier to read. You will notice that we did have to change some things around. The style tag tells the web browser style information, but also what to style too. In our example, we have used two different ways to tell it what to style. The p in the style tag is telling the web browser to apply that style to all paragraph tags. The #ourParagraph section tells it to only style elements with the id ourParagraph. Notice that id information was added to the p tag in our body.

Importing a CSS File to Your Website

Adding the style information to the header makes our code much easier to read. However, if we want to style many different pages the same way, we have to add that text to the top of every page. That might not seem like much work, you can copy and past it after all, but it creates a lot of work if you want to change an element later.

Instead, we are going to keep the CSS information in a separate file and import the file to style the page. Copy and paste the information between the style tags into a new CSS file ourCSSfile.css.

p {
text-align: center
}
#ourParagraph {
border-style: solid;
padding: 30px;
}

Then, import the file to the HTML file.

<html>
<head>
<link rel="stylesheet" href="ourCSSfile.css">
</head>
<body>
<p id="ourParagraph" >Hello World</p>
</body>
</html>

Adding a Background Image With CSS

Now that you have a solid base in HTML and CSS, adding a background image will be a piece of cake. First, identify what element you want to give a background image to. In our example, we will add a background to the entire page. This means that we want to change the style of the body. Remember, the body tags contain all the visible elements.

body{
background-image: url("sky.jpg");
}
p {
text-align: center
}
#ourParagraph {
border-style: solid;
padding: 30px;
}

To change the body style in CSS, first use the body keyword. Then add curly brackets as we did before {}. All of the style information for the body must be between the curly brackets. The style attribute we want to change is background-image. There are many style attributes. Don't expect to memorize them all. Bookmark a CSS properties cheat-sheet with attributes that you want to remember.

Related: 8 Cool HTML Effects That Anyone Can Add to Their Website

After the attribute, use a colon to indicate how you will change the attribute. To import an image, use url(). it indicates that you are using a link to point to the image. Place the file location in the brackets between quotation marks. Finally, end the line with a semicolon. Although white space does not have meaning in CSS, use indentation to make the CSS easier to read.

Our example looks like this:

If your image is not displaying correctly because of the size of the image, you can alter the image directly. However, there are background style attributes in CSS that you can use to alter the background. Images that are smaller than the background will automatically be repeated in the background. To turn that off, add background-repeat: no-repeat; to your element.

There is also two ways to make an image cover the entire background. First, you can set the background-size to the size of the screen with background-size: 100% 100%;, but this will stretch the image and may distort the image too much. If you do not want the proportions of the image changed, you can also set the background-size to cover. Cover will make the background image cover the background, but not distort the image.

Changing the Background Color

Let's change one last thing. Now that we have a background, our paragraph is hard to read. Let's make it's background white. The process is similar. The element we want to modify is #ourParagraph. The # indicates that "ourParagraph" is an id name. Next, we want to set the background-color attribute to white.

body{
background-image: url("sky.jpg");
}
p {
text-align: center
}
#ourParagraph {
background-color: white;
border-style: solid;
padding: 30px;
}

Much better.

Continuing to Design Your Website With CSS

Now that you know how to change the style of different HTML elements, the sky is the limit! The basic method to change style attributes is the same. Identify the element that you want to change, and describe how to change the attribute. The best way to learn more is to play around with different attributes. Challenge yourself to change the color of your text next.

Categories
News

There are many JavaScript frameworks out there to help with development. Here are some you should know.

JavaScript frameworks are tools you can use to automate tasks on a website and improve general user experience (UX). They also offer faster and more efficient ways of developing websites by providing highly scalable and customizable components and modules to suit any app you want to build.

Although if you're a newcomer, jumping into JavaScript frameworks might be too technical for you, knowing more about them to make a potential choice is worth it. However, if you've been coding vanilla JavaScript for a while, it might just be high time you added some of these frameworks to your skillset.

So, for learning purposes, let's take a look at a few JavaScript frameworks you can pick up as a beginner.

1. Vue.js

Vue is a progressive JavaScript framework for building single-page applications (SPAs). It's a reactive framework that you can plug into an existing server-side language with minimum effort. If you're more interested in building progressive web apps (PWAs), then you might want to consider picking up Vue.

Vue comes with a command-line interface (CLI), which makes it easy to either add it to an existing project or start building one from the ground up. When executing a project with Vue, you can either install it via the npm install method or connect to its content delivery network (CDN) directly.

With Vue, you can separate your DOM elements and treat them as separate entities in different files. Each entity then has its own CSS and JavaScript components.

Related: A Beginner's Overview of Vue.js

However, you can also develop your app more conventionally by linking a whole DOM with its JavaScript and CSS file and connecting to Vue's CDN.

In essence, if you're plugging Vue into an app, all you need do is connect to its CDN and then link an existing DOM with the Vue instance. This way, you get to choose the parts of your project that uses Vue technology while leaving others out.

Building apps with Vue is seamless. The responsive Vue community, coupled with its detailed docs and stepwise tutorials, make it highly beginner-friendly and easy to comprehend.

2. React.js

React is a component-based JavaScript library created in 2011 by Jordan Walke, a developer at Facebook. Although its documentation says it's a library, a lot of users of React argue that it's a framework since it independently supports full front-end applications.

React simplifies complex tasks by treating each section of a webpage separately. One of React's library features is that you can decide to apply it to a specific element in a DOM without affecting how others work. However, since React is scalable, you can also use it to build the whole website.

Related: An Introduction to Web Components and Component-Based Architecture

So, the fact that you can use small parts of React in your app components means you can use it as a library. But, you can also use it as a framework when your whole app depends on it for responsiveness.

React is one of the most-used JavaScript frameworks. It also powers popular websites and mobile apps like Instagram, Facebook, Airbnb, Discord, and Skype, among others. Like Vue, React has great docs to get you started. It's beginner-friendly once you know the basics of JavaScript.

React has two technologies: Reactjs and React Native. Although these two technologies have little differences, using React Native is easy once you're a master of Reactjs. However, React Native comes in handy for building mobile apps

To get a better hold of React, you can check out its documentation at reactjs.org.

3. Angular.js

Developed in 2010 and introduced by Google in 2012, Angular is a scalable MVC-based framework for building SPAs and PWAs.

Angular uses Plain Old JavaScript Objects (POJO) to relate with its models. So it's capable of independently handling extra functionalities for controlling objects. It's a suitable framework to consider if you like to build enterprise apps.

You don't need to write extra functions to make a call in Angular. Those functions are in-built, and you can use them with your model each time you need to make a dynamic change to your DOM elements. However, Angular also has a sophisticated ecosystem that supports third-party solutions.

All these tools give Angular a unique feature that lets you execute more tasks with less code. It also has an interactive URL routing suitable for linking pages asynchronously in SPAs.

Although Angular might be a bit technical for a beginner, it has a supportive Google community that helps you out if you run into trouble. It's suitable for building both mobile and web apps. It powers popular apps like Freelancer, Gmail, Forbes, PayPal, and Upwork.

Detailed documentation of Angular is available at the Angularjs Developer Guide website.

4. Next.js

Next.js is a reactive client-side framework for building both dynamic and static web pages. It's a lightweight JavaScript framework that exports pages as React components, which is why it's also known as a React framework.

Next.js features a routing method that preloads pages for faster page load and a better user experience. If you want to build server-side apps with React, then Next.js might be the right choice.

The framework offers full image optimization and internalization properties, as well as CSS and TypeScript support. Its API route methods give it server-side functionalities that let you develop server-side apps with minimal effort.

Related: What's Typescript and Why Should Developers Try It?

Just like Vue, Next.js has a CLI that lets you build and export apps faster. It has a pretty easy learning curve to help beginners pick it up quickly. TikTok, Twitch, and HostGator are some of the popular websites that run their front-end on Next.js.

For a more detailed explanation of Next.js, you can visit nextjs.org for its documentation.

5. Express.js

Express.js is a Node.js-based framework that supports the development of modular applications. Although Express.js can be overwhelming for newcomers with little or no experience with pure JavaScript, it's worth learning, especially if you want to build your backend based on JavaScript.

Express.js is a perfect JavaScript framework for handling routes and requests in any Node.js application. It has robust HTTP tools that make building APIs a seamless task.

However, Express.js blends perfectly with Node.js, and some developers call it a Node.js module. It serves as a communication channel between the server and the client for apps that run their backend on Node.js. Typically, you can carry out Express.js tasks with pure Node.js, but using Express.js is more consistent and secure.

To learn more about this framework, you can take a look at its documentation at the Express.js homepage.

Related: How to Build a Photo Tweeting Twitter Bot With Raspberry Pi and Node.js

6. Ember.js

Ember.js is a scalable JavaScript framework that offers modern JavaScript built-in solutions for building a progressive and interactive user interface.

One of the core strengths of Ember.js is its CLI. The Ember CLI features a unique development environment that offers smart source file linking and automated unit testing to simplify the development process.

While it uses a rendering engine called Glimmer to boost the performance of its apps, the framework also offers a unique routing system that's both dynamic and supportive for asynchronous loading.

In addition to having a flexible learning curve, Ember.js has well-detailed documentation and tutorials that make it less technical for newcomers.

Why Learn JavaScript and Its Frameworks?

According to a February 2020 Stack Overflow Developer Survey, JavaScript maintains its lead as the most commonly used programming language. Based on this report, JavaScript has consistently been at the top for eight years in a row.

To back that claim up, Github Language Stats also placed JavaScript as the leading programming language in 2020 based on the number of pull requests, with Python now trailing behind it.

The popularity of JavaScript isn't surprising. Besides, using vanilla JavaScript or one of its frameworks for your front-end is practically unavoidable if you want to give your users a great experience when they visit your webpage.

The fact that it's now even server-side makes it a language of the future that's worth learning. With its current evolutionary trend, you can decide to be a JavaScript-based developer without learning any other programming language.

JavaScript, no doubt, has many frameworks that can add great UI to your apps. However, the ones we listed in this article might be easier for beginners to learn.

Categories
News

8 Cool HTML Effects Anyone Can Add to Their Websites | MakeUseOf

You want your website to look awesome---but your web development skills are lacking.

Don't despair! You don't have to know CSS or PHP to build a fancy site with cool effects. Some simple HTML tags and knowing how to copy-and-paste will do.

To get you started with some cool HTML effects, we've compiled these free HTML effect code templates. They will enhance the functionality and user experience of your site, while not breaking the bank. While they're mostly HTML these cool codes may also contain some CSS and PHP.

1. Cool Parallax Effect With HTML

You have probably seen the Parallax Effect used on websites with online ads. As you scroll down an article, the background image appears to scroll at a different pace, or an advert appears.

Alternatively, perhaps the background image changes as you visit different parts of the site. It's a cool effect that adds visual depth to the content and ideal even if you don't understand basic HTML code.

You can play with the effect and copy the code for a simple Parallax scrolling effect from W3Schools.

In its most sophisticated version, this effect is a combination of HTML, CSS, and JS.

Go ahead and fetch the codes for the above Header/Footer Parallax effect from CodePen.

2. Scrollable HTML Comment Box Code

This is a simple but helpful HTML element that lets you pack long snippets of text into a compact format. This way it doesn't take up the entire space on the page.

You can play with the colors and the size of the text box to make it fit your needs.

Input:

<div style="width: 25%; height: 50px; overflow: auto; scrollbar-face-color: #CE7E00; scrollbar-shadow-color: #FFFFFF; br /scrollbar-highlight-color: #6F4709; scrollbar-3dlight-color:#11111; scrollbar-darkshadow-color: #6F4709; br /scrollbar-track-color: #FFE8C1; scrollbar-arrow-color: #6F4709;">
Putting some text in this box will let you see how large it can stretch to - eventually the scrollbars should show, enabling you to scroll through the text. That's it! :)</div>

If you desire something a little fancier, you can also fetch code for a customizable comment box from Quackit.

They offer several templates, but you can also use their editor to manually change and test (run) your custom code.

3. A Cool HTML Trick: Highlighted Text

With a simple <span> HTML tag you can add a ton of cool effects to your text or images. Note that not all of them work across browsers. The ones mentioned here work in Google Chrome, Microsoft Edge, and Mozilla Firefox.

This HTML text effect highlights the text between the <span> tags.

Input:

<span style="background-color: #FFFF00>Your highlighted text here.</span>

Output demo:

4. Add Background Image to Text

Likewise, you can change the color of your text or add a background image. This one looks great if the text's font size is larger.

Input:

<span style="background-image: url(https://www.makeuseof.com/wp-content/uploads/2017/09/Background-Image.jpg); font-size: 20pt">MakeUseOf presents...</span>

The same effect is achieved by adding the style and font elements to text in a <strong> tag.

Output demo:

5. Useful HTML Trick to Add a Title Tooltip

A title tooltip comes up when you scroll with the mouse over a piece of "manipulated" text or image. You'll have seen these used on websites on images, linked text, or even menu items in desktop apps. Use this HTML code to add a tooltip to plain text on your webpage.

Input:

<span title="See, this is the tooltip. :)">Move your mouse over me!</span>

Output demo:

6. The Coolest HTML Tricks Yet: Scrolling or Falling Text

When you search for "marquee html" on Google, you'll discover a little Easter Egg. See the scrolling search result count at the top? That's an effect created by the now obsolete marquee tag. While this once-cool HTML text effect has been deprecated, most browsers still support it.

Input:

<marquee>I wanna scroll with it, baby!</marquee>

Output demo:

You can add further attributes to control the scrolling behavior, background color, direction, height, and more. Take care, however; these effects can become quite irritating if overused.

For a cool falling text effect, head to Quackit again and copy their highly customized marquee code.

7. Build a Cool Switchmenu With HTML

The coolest HTML tricks are dynamic HTML effects. However, they are often script based. Here is one effect for menus that you'll agree looks very slick.

It's a little more complicated than your average HTML tag because it works with a style sheet and scripts. The advantage is that you don't have to upload a CSS or script file to make it work. Instead, simply paste the following code into the <head> section of your website.

Input:

<style type="text/css">
.menutitle{
cursor:pointer;
margin-bottom: 5px;
background-color:#ECECFF;
color:#000000;
width:140px;
padding:2px;
text-align:center;
font-weight:bold;
/*/*/border:1px solid #000000;/* */
}.submenu{
margin-bottom: 0.5em;
}
</style><script type="text/javascript">/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page onlyif (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">n')
document.write('.submenu{display: none;}n')
document.write('</style>n')
}function SwitchMenu(obj){
if(document.getElementById){
var el = document.getElementById(obj);
var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
if(el.style.display != "block"){ //DynamicDrive.com change
for (var i=0; i<ar.length; i++){
if (ar[i].className=="submenu") //DynamicDrive.com change
ar[i].style.display = "none";
}
el.style.display = "block";
}else{
el.style.display = "none";
}
}
}function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunctionif (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate</script>
And this code goes wherever you want the dynamic menu to appear.
<!-- Keep all menus within masterdiv-->
<div id="masterdiv"><div onclick="SwitchMenu('sub1')">Topics</div>
<span id="sub1">
- <a href="https://www.makeuseof.com/service/browser">Browsers/Addons</a><br>
- <a href="https://www.makeuseof.com/service/web_based">Web Apps</a><br>
- <a href="https://www.makeuseof.com/service/how-to">How-To Tips</a><br>
- <a href="https://www.makeuseof.com/service/applications">Cool Software</a><br>
...and more!
</span><div onclick="SwitchMenu('sub2')">Staff Writers</div>
<span id="sub2">
- <a href="https://www.makeuseof.com/tag/author/karl-l-gechlik/">Karl Gechlik</a><br>
- <a href="https://www.makeuseof.com/tag/author/tinsie/">Tina</a><br>
- <a href="https://www.makeuseof.com/tag/author/varunkashyap/">Varun Kashyap</a><br>
...and more!
</span><div onclick="SwitchMenu('sub3')">Miscellaneous</div>
<span id="sub3">
- <a href="https://www.makeuseof.com/about/">About</a><br>
- <a href="https://www.makeuseof.com/contact">Contact</a><br>
- <a href="https://www.makeuseof.com/archives-2">Archives</a><br>
- <a href="https://www.makeuseof.com/disclaimer">Disclaimer</a><br>
</span></div>

Output demo:

Unfortunately, we cannot demonstrate this effect here. But the original source, Dynamic Drive, features a working copy of this dynamic HTML effect.

8. Get a HTML Spreadsheet With Tableizer

If you want to display a spreadsheet on your site, let Tableizer! transform your data into an HTML table. Just paste the raw data from Excel, Google Doc, or any other spreadsheet into the converter tool at tableizer.journalistopia.com. Tweak the table options, then click Tableize It to receive the HTML output.

This is perhaps one of the coolest HTML codes for your website, as Tableize It! does all the hard work.

Click Copy HTML to Clipboard to copy the HTML code and add it to your website. Consider editing the background-colors to make it look a lot cooler.

While this is not really an HTML effect, it's quite handy.

More Cool HTML Codes and Effects for Your Site

The power of HTML, CSS, and JavaScript offers potentially unlimited options for stunning effects on your website. Want more?

We've shown you eight cool HTML codes that you can copy to enhance your website. While different, they're all easy to implement as long as you know basic HTML coding techniques.

Categories
News

What Is a Function in Programming? | MakeUseOf

Do you often find yourself copying and pasting your code to reuse in different sections in your program?

If so, you might want to consider using functions. Functions are a very powerful feature of programming languages. They can make code more efficient, easier to read, and elegant.

What Is A Function?

A function is a block of code that performs a task. It can be called and reused multiple times. You can pass information to a function and it can send information back. Many programming languages have built-in functions that you can access in their library, but you can also create your own functions.

When you call a function, the program will pause the current program and execute the function. The function will be read from top to bottom. Once the function is complete, The program continues to run where it had paused. If the function returned a value, that value will be used where the function was called.

How Do You Write A Function?

There are many different ways to write functions. The exact syntax will depend on the language that you are programming in. We will show examples in Python, JavaScript, and C++ to demonstrate a range of programming syntax.

Related: Why Programming Languages Can't Exist Without Functions

Void Functions

The first type of function that we will look at is a void function. This simply means that the function does not return a value. Void functions are used to complete a set of instructions. In these examples, the function we wrote is called helloFunction. The purpose of the function is to output "Hello World".

TIP: give functions names that explain what they do. It will be easier to manage functions and read the code as your program becomes more complex.

Python

def helloFunction():
print("Hello World")
helloFunction()

The keyword def is used in Python to define and create a function. Next, is the name of the function. The instructions in the function follow on the next line after the colon. White space matters in Python, so be sure to indent all the code that you want your function to run. In the example above, the function runs one line of code.

Your keen eyes might have noticed that print() is also a function, but it is called differently than our function. Hold on to that thought right now, we will explore functions will parameters later.

JavaScript

function helloFunction(){
alert("Hello World!");
}
helloFunction();

In JavaScript, the keyword function is used to create functions. Next, we have the name of the function. Any code that falls between the curly brackets is run when the function is called.

White space is not important in JavaScript, but it is customary to indent the code in the function. Indentation makes code easier to read, which is very important as your programs become more complex.

Note: Much like print() in the earlier example, alert() is also a function.

C++

#include <iostream>
using namespace std;
void helloFunction(){
cout << "Hello World!";
}
int main(){
helloFunction();
return 0;
}

Functions are created differently in C++. Instead of a keyword to define a function, the first word describes the type of data that the function will return. In this case, our function does not return any data, so the data is void. Next, we have the function's name. Similar to JavaScript, all the code between the curly brackets is run when the function is called. Also similarly to JavaScript, white space does not affect the function but is good practice.

Did you spot another function in the C++ code? Yes, main() is a function. When you execute a C++ program, you automatically call the main function. When the main function is successfully completed, it returns 0 as it exits the program to signal there were no errors running the program.

Functions That Require Values

Void functions are great if you find that you are writing the same bit of code over and over again. But they can be limiting. They are static and don't change. They always complete the same instructions. One way we can increase their usefulness is to pass different values to the function.

You will have noticed that brackets followed the names of all of our functions. In the brackets, we can declare that data is needed to run our function. Then we can use the data passed to our function in the function. Let's take a look at the previous examples again, but this time pass the phrase that we want to be outputted.

Python

def helloFunction(newPhrase):
print(newPhrase)
helloFunction("Our new phrase")

Now, between the brackets, our function declares that it needs a variable to run. We have named the variable newPhrase and can now use it in our function. When we call the function, we need to pass the requested information by placing it in between the brackets. The same changes were made in JavaScript.

JavaScript

function helloFunction(newPhrase){
alert(newPhrase);
}
helloFunction("Our new phrase");

C++

#include <iostream>
using namespace std;
void helloFunction(string newPhrase){
cout << newPhrase;
}
int main(){
helloFunction("Our new Phrase");
return 0;
}

Our C++ function required a bit more information. We know that your function wants string data, but that's not good enough for C++. When you create your function you have to specify what type of data your function requires. If you do not send the correct type of data, the function will create an error.

This might seem a little annoying, but strict languages can often save you headaches. If you write a function in JavaScript that requires an integer, but the number is sent as a string, it can create a bug that is very hard to track down.

Related: 5 Functional Programming Languages You Should Know

Functions That Return a Value

The final function ability that we will cover is returning data. This is particularly valuable when you want to alter data before you use it. Although you could write that inline, if you will use the same calculations many times, like converting imperial to metric, it might make more sense to write it as a function. Our example will be simpler. Our function will require two integers and will return the sum.

Python

def addingFunction(a, b):
return a + b
print(addingFunction(2, 4))

In this example, our function requires two variables instead of one. We indicate that by separating our variable names with a comma. The keyword return tells the function to return the following data, in this case, 2 + 4, or 6. We call the function inside the print() function.

Once our program got to that line, it would have paused, ran our function, and then continued as if addingFunction(2, 4) was actually just the returned value 6.

JavaScript

The JavaScript code is very similar to the Python code. The primary difference is that the function is called in an alert.

function addingFunction(a, b){
return a + b;
}
alert(addingFunction(2, 4));

C++

#include <iostream>
using namespace std;
int addingFunction(int a, int b){
return a + b;
}
int main(){
cout << addingFunction(2, 4) ;
return 0;
}

The C++ code runs similarly, but as usual, requires a bit more information. First, we have to say what type of data our function will return. You will see that void has been changed to int. This means that instead of returning no data, our function will return an integer. Beyond that, the code is similar to the code we have already explored.

Manage Your Functions

A fun thing about functions is that functions can call other functions. They can even call themselves! But with great power comes great responsibility. Do not go crazy creating code with functions that call other functions that call yet more functions.

As mentioned, every time a function is called, the program pauses while it runs the function. This means that the program is being held in active memory. If you call several more functions without completing them, you are using more active memory. If you are not careful, your program can get out of hand.

Categories
News

How to Create a New Branch in Git | MakeUseOf

Branches are central to the concept of version control in programming, and Git in particular. This starter article tells you what a branch is and how to create one using a number of different tools.

What is a Git Branch?

In version control systems, the term branch is used as an analogy with trees in the sense that each branch emerges from another, eventually ending up back at the trunk. Branches allow you to create individual lines of development, in order to work on them in isolation without disturbing other work.

Related: How to Use Git Branches to Structure Your Programming Project

Using Git, you’ll be working on the master branch by default, whether you’re aware of it or not. This is often referred to as your active, current, checked-out, or HEAD branch. At any time during your development cycle, you can create a new branch and carry out separate work in each branch, from that point onwards.

Creating a New Branch on the Command Line

The command-line Git program offers the most power and flexibility, but there’s a lot to learn. If you’re comfortable digging around the man pages and make heavy use of Git, it’s a great option.

Use the git branch <branchname> command to create a new branch with the given name:

$ git branch dev
Branch 'dev' set up to track local branch 'master'.

This branches from the current branch, so make sure you’ve switched to the one you want to branch from before you execute that command.

You can list all branches and confirm the new one has been created using git branch without any arguments:

$ git branch
1 dev
2 * master

You can see more information, including which branch another one tracks, using the -vv flag:

$ git branch -vv
1 dev d1a9e5b [master] commit comment
2 * master d1a9e5b commit comment

If you try to create a branch before the first commit, you’ll get an error message like:

fatal: Not a valid object name: 'master'.

If you try to create a branch using a name that already exists, you’ll get an error message like:

fatal: A branch named 'dev' already exists.

The git branch command creates a new branch pointing to the same commit you’re currently working on. However, your working copy will still be pointing at the master branch. To switch to the new branch you just created, use git checkout:

git checkout dev

The term checkout might be confusing if you’re used to other version control systems; in Git, checkout refers to switching the currently active branch. Since you’ll usually want to switch to a new branch once it’s created, there’s a shortcut for the whole process:

git checkout -b dev

That command means “create a new branch called ‘dev’ and switch to it immediately”. It’s the equivalent of:

git branch dev
git checkout dev

In fact, you can even use git checkout to create a branch from any other, not just the one that is currently checked out. For example, to create a new branch called another, from the branch named dev:

git checkout -b another dev

Creating a New Branch Using GitHub Desktop

Another way to create Git branches on Windows or macOS is using GitHub Desktop, the official graphical user interface (GUI) program provided by GitHub. Using a GUI is perfect for beginners, and those who have nightmares when someone whispers the word Vim.

GitHub Desktop will always show your current branch in the main toolbar:

Click on that main toolbar button to show details of the repository’s branches, including the option to create a new branch:

Note that, if you start typing a branch name with no matches, GitHub Desktop prompts you to create a new branch and shows the keyboard shortcut to do so—useful if it’s really the kind of thing you find yourself doing a lot:

You can also start by pressing the New Branch button immediately. Whichever route you take, you’ll end up with a dialog to confirm the new branch name:

Your new branch will always be based on whichever branch was active when you created it. GitHub Desktop will switch to your new branch which will automatically track the branch you created it from.

Creating a New Branch Using Tower

Other GUIs are available from third-parties. Tower is free for a 30-day trial period and is available on macOS and Windows.

To create a new branch from the currently checked-out branch, select Create New Branch from the main Repository menu:

To create a new branch from any available branch, right-click on the branch in the left-hand sidebar and select Create New Branch from <branch name>:

Note that, in either case, you can enable the branch as a tracking branch, or change the Starting Point to any branch available:

Creating a New Branch Using GitKraken

GitKraken is another popular GUI that can seem intimidating at first, but it does a good job of visually representing key Git concepts, including branches. GitKraken is free for open-source use and is available for Windows, Mac, and Linux.

Make sure you’re working with the correct active branch; it’s the one highlighted in the branch listing in the left-hand sidebar:

To create a new branch, click the branch icon in the main toolbar:

Enter your branch name and hit ENTER:

The new branch will automatically be checked out and you'll receive a notification on the right-hand side of the screen.

Creating a New Branch on GitHub

As an alternative to running a local app, you can host your repository on one of two popular Git-supporting web apps. The first, GitHub, is a very popular option with the open-source community.

GitHub displays your current (active) branch in your repository view, near the top-left:

Click the button to display existing branches:

Type the name of your new branch and note that you are given the option to create it from the current branch:

Once created, your new branch becomes active.

Creating a New Branch on Bitbucket

Bitbucket is another popular version control web app that offers free accounts with an unlimited number of private repositories.

From any page within your repository, select the Branches item from the menu on the left:

Click the Create branch button in the top-right. Enter the new Branch name and click Create. If you need to branch from anywhere other than master, change the From branch first:

Bitbucket makes it easy to select a Type which is a prefix added to the branch name that can encourage a more organized approach to branches. It’s just a convention, rather than a built-in Git feature, but it can prove useful.

Once created, Bitbucket displays a view of your new branch:

Bitbucket screenshot showing new branch pageLearn to Branch Out With Git

Git is all about branches: they’re cheap to create and they allow multiple streams of work to coexist, ready to be merged when complete. Once you’re familiar with creating, switching, and merging branches, you’ll be well on the way to using Git to its full potential.

Categories
News

6 Software Development Steps All Programmers Should Know

Starting a new software project can be overwhelming. It can be helpful to break the process into smaller, more manageable steps. Traditionally, software development has been broken into six steps. Using this process can make a large project less intimidating.

What Is Software Development?

Before we dive into the process, it will be helpful to define software development. It can be tempting to think that a small project doesn't really qualify as "software development". However, no matter how big or small your project is, if you are designing a program, you are engaging in software development.

Simply put, software development is the process of creating and coding software to meet some need. It could be the needs of customers, or a personal need, such as automating a task. The program could be large or small. But, all projects benefit by breaking the project down into a series of steps.

Software Development Steps

1. Needs Assessment

As mentioned, software development solves a need. Thus, the first step of any project is clearly identifying the need that you are trying to solve. On large projects, this could involve market research and meeting with stakeholders. A smaller project might just require making a list of must-have features.

This is the most important step in the process. Without a clear understanding of what is required to solve your problem, it will be difficult to design an adequate solution. Having a clear vision of a product can also help to keep your project on track. As you begin to design your project it might be tempting to add features that are not needed but are wanted. This is called scope creep and it can derail a project.

Related: The Best Project Management Tips for Beginners

2. Design

If you love to program, it can be tempting to jump into the code as soon as you have a good idea. But your project will run much smoother if you take the time to design your software first. This step is analogous to writing an outline before you begin to write a paper. It serves to organize your thoughts. Most of your problem solving should be complete in this step so that when you start coding, there should be few complications.

In this step, there are several things you will want to consider. If your software project requires an interface, develop a prototype that outlines the look and functionality of the interface. If the project uses a database, design the tables, and map out the relationships between them.

All software development will require writing algorithms. Create flow charts that outline the program flow and describe any complex algorithms, like functions or methods.

3. Coding

This is arguably the most straightforward and fun step.

In this step, you write the code to create the software. After the needs of the project have been clearly defined, and the design outlined, this step should be straightforward---in theory at least. Realistically, issues may arise in this stage, but the more planning completed before programming, the smoother it goes.

4. Testing

After you write the code, it must be tested. You need to validate that the code works as expected and meets the needs it was designed to meet. In smaller projects, this step can be fairly straightforward and primarily involve debugging the software. In larger projects, this could involve testing the software with focus groups to refining the design and requirements of the software.

The order of this step can vary. For example, Test Driven Development creates a script to test the software first. Coding is considered complete when it passes the test. Conversely, if you use an iterative design method, testing will be integrated into several design stages.

Related: The Best Free Online HTML Editors to Test Your Code

5. Implementation

Once the software passes testing, it is ready to be deployed. At this stage, the software should be fully functional and can be released, and/or used. Large projects may be released in stages, which is called a staggered release.

When the software is placed into the hands of users, they often find issues and bugs that were not discovered during testing. A staggered release makes responding to these issues manageable.

6. Maintenance

The maintenance step is another crucial phase. Once the software is used, it might not quite meet the need it was designed for, new features might be released, or new bugs may be discovered. All of this requires monitoring and revising the software.

Development Methodologies

Although the above steps make software development seem linear, it doesn't have to be. There are many different ways to approach software development. The two most well-known methods are waterfall and agile software development.

Waterfall

Waterfall development was the traditional way to manage a project. It involves completing software development steps in sequential order. Each step would be completely finished before the team would move on to the next step.

This method is easy to manage and can work well for small software projects. Because the process is straightforward and each step has clear goals, it is easy to manage. It is suitable for projects that have a clear goal and easily understandable requirements.

The waterfall method does not work well when a project is complex, or if the requirements are not clear. It can be difficult to change the design of the software using this method. Because the steps are followed sequentially, it is difficult to go back a step, which makes it difficult to respond to issues that arise or pivot the design.

Agile

Agile was designed to address many of the shortcomings of the waterfall approach. Instead of moving from one step to the next until you are done, the process is cyclical. The project is incrementally created in a series of development cycles. Testing is central to the process. Each cycle incorporates the lessons learned from testing. This cyclical approach builds re-design into the process of software development.

Related: How to Use Agile Project Management Principles to Organize Your Life

The benefit of agile is that it allows the project to evolve to address issues discovered during testing. This is a great approach for user-focused design. Despite the development process being more complex, it can also be more cost-effective for large projects. Problems can be addressed quickly as they arise and it is easier to change the design in response to issues that arise.

Software Development

There are many considerations when beginning a new software project. The purpose and scope of the project will dictate the best software development method. However, all approaches are based on the same steps. If you are new to programming, it will always be tempting to jump straight into coding. But taking the time to plan your project is time well spent.

Categories
News

Should You Be a Programmer? 3 Programming Aptitude Tests to Help You Decide

Aptitude tests can be great tools to help you align your strengths with a career path. If you have been considering a programming career, you might want to try taking some programming aptitude tests. They can give you insight into the type of skills that programmers use regularly. The tests will also help you identify if you excel at those skills.

What Are Aptitude Tests?

Aptitude tests are designed to predict whether you will succeed at a given task. Everyone has strengths and weaknesses. Everyone has different educational backgrounds, interests, and hobbies. Therefore it is natural for some things to come easier to some than others. Aptitude tests identify if a new skill will be easy for you to acquire.

They are most commonly used to predict whether someone will succeed in a given career. But, they can also assess how well people learn different subjects. Programming aptitude tests are a bit of both. They are designed to gauge success in programming by determining how well you can solve problems requiring mathematical knowledge and logical reasoning.

If you are interested in programming or starting a computer science degree, you may want to try some free programming aptitude tests. They will give you a taste of the type of problems you will need to solve as a programmer.

ComputerAptitude.com LLC

ComputerAptitude.com LLC offers a very short sample aptitude test. The test is not timed and consists of five questions. This is a great option if you are curious about programming aptitude tests but do not have a lot of time to complete one.

You do not require an account, once you complete the questions, you can click a button to see your results. The test will tell you your score and show you the correct answers.

The questions primarily test your logical reasoning, but there are also some mathematical questions. A strength of this test is that it tests your ability to read a flowchart. Flowcharts are often used in programming when designing algorithms.

The site also offers a longer test that has 25 questions that must be completed in 25 minutes. That test does require you to create an account. However, at the time of this writing, there is a bug that breaks the signup form.

Related: The Best Free Flowchart Software for Windows

University of Kent Computer Programming Aptitude Test

The University of Kent's Careers and Employment Services website offers a Computer Programming Aptitude Test. The test is timed. You are given 25 minutes to answer 26 questions. The test begins with three untimed practice questions, so it will take a little longer than 25 minutes to complete. You do not need to create an account or provide any information to review your results.

If you are interested in completing this test, do not scroll too far down the page before you begin. The answers to the questions appear on the same page. Although it is nice to be able to see how to solve the problems, this test would have been better if the answers were hidden until the test was completed. This does have a benefit though, as if you do not have time to take the test, peeking at the answers will give you an idea of the skills involved in programming.

The test assesses logical reasoning, problem-solving, pattern recognition, and the ability to follow complex procedures. The questions are fairly simple but are difficult to complete within the timeframe provided. The test will give you a good sense of how well you can program in a high-stress environment.

Related: The Best Calming Apps to Relax, Destress, and Clear Your Mind

This aptitude test is not well suited to all people. If you have test anxiety, you may do poorly on the test because it is timed. The test then may not accurately reflect your ability. There is a section where you need to identify which blocks of random characters are different. This could be difficult for someone with dyslexia and isn't typical of how problems are solved in practice.

Programming Skill Aptitude Online Test

Training and education site Programming Skills offers aptitude tests and programming language-specific tests.

There are ten different timed aptitude tests. To complete the test, you need to answer 20 questions in 25 minutes. All of the tests assess the same skills but have different questions.

Each test primarily assesses numerical problem-solving. It'll give you a good idea of whether you excel in that skill, but they do not assess other skills necessary to succeed as a programmer. These tests would be best suited for someone who enjoys solving math problems or someone who wants to assess their mathematical abilities.

Related: Cool Math Games for Kids

Once you complete a test, you will be shown your score and the answer to all of the questions. Any questions that involved problem-solving will have a description explaining how to solve the problem. You do not need to provide any personal information to review your results.

Are Programming Aptitude Tests Helpful?

The answer to this question will depend on what you hope to learn from an aptitude test. Their greatest strength is that they give you a sense of what types of skills programmers need to be successful. If you do not enjoy slogging through a bunch of problem-solving questions, you probably won't enjoy being a programmer.

If you are interested in becoming a programmer but did not do well on an aptitude test, you shouldn't take that as a sign to quit. Tests do not simulate the act of programming. Test anxiety can decrease your score. There are also many tools that make aspects of the job easier and can help you organize your thoughts when problem-solving.

Aptitude tests are best suited for someone that is considering entering a computer science degree. Degree programs generally require a high level of mathematical skills, which is the emphasis of many programming aptitude tests. If you are learning for fun, there are many other skills that are more important, such as creativity. An alternative to aptitude tests is coding challenges and competitions, some of which can lead to cash prizes or even job opportunities.

Learning any new skill takes time. Programming is no different. Even if you are struggling with the skills now, it does not mean that you will not improve over time. These tests can be a great tool to assess your skill development.