Matt Hines Development

Matt Hines.
Software Engineering Student.
London.
This blog is mainly to display my different projects, as well as a place for me to share and discuss technology news.

Recent Tweets @MattDevUK
Posts tagged "software engineering"

rmtsoftware:

Associative arrays in PHP, Hashmaps in Java and Dictionaries in Python. All these terms mean a list that has a key and a value. You access the value in the dictionary but sending in its key. 

To Initialize that dictionary in python you got to use squiggly braces.

dictionary = {1:”hello”,2:”world”}

This sets up a dictionary with two keys each with its own values. You can access the value of “hello” by using its key “1”. Example:

print dictionary[1]

This statement will print the world “hello”

After this post I will be using comments in the code snippets. A comment is something that is ignored by the compiled and is used for documentation. In python the comment character is the “#”.

print “Hello world” #This prints hello world

This will ignore everything after the # symbol but it serves as a good tool that will help another person understand what that line does. Or it will help yourself if you come back to this code after a couple of months.

Coming back to dictionaries, they are very useful and are fairly easy to use. You should already know how to create a dictionary but inserting and removing are very easy as well. Example:

dictionary[3] = “New value” #This adds the key “3” with its value “New value”

To remove a key and value you have to use the keyworld “del”

del dictionary[2] #removes the key “2” and its value.

You can also get all the keys or all the values in the dictionaries by using “.keys()” and “.values()” respectively. These methods return a list containing either keys or values.

I hope this has taught you something about dictionaries in python. Please don’t hesitate to ask any questions if you need to. 

Thanks for reading.

rmtsoftware:

In every programming languages you use data types to store your data/information. As an easy example we will create an “Array”. An array is a data type in most programming languages that stores information sequentially. For a reason that I do not know python calls arrays “lists” and other languages like Java call them arrays but also have lists which is another sort of abstract data type. The way to create an array is by using the square brackets “[]”. Inside the square brackets you put your information. 

Example: 

testArray = [“hello”,”this”,”is”,”a”,”test”]

This code snippet creates an array of length 5 (5 words). Each word is separated by a comma. You are not limited to strings in array you can add other data types like integers or doubles in them as well.You can even put different types inside an array, as an example, 2 strings and an int. If you are feeling even more adventurous you can even put an array inside an array. This is called “Nested Arrays”. Arrays are a data type that is used quite often. 

The way to access an element in an array is by something called indexing.

print testArray[2]  

This will print out the word “is”. A common question is Why does it print out “is” and not “this” since “this” is the second element in the list. When it comes to indexing, python uses 0 based counting (Like every programming language). So if you want to access the first element in the list you have to type:

print testArray[0]

To add an element in the array you use the “append” method of the array.Example:

testArray.append(“new Element”)

This will add it to the end of the list, if you want to add anywhere in the list you have to use the “insert” method.

testArray.insert(2,”new element”)

The 2 is the position in where I would like to insert my element. Again this uses 0-based counting.

Removing an element if you cannot already guess is the “remove” method. All you have to do is supply the element in which you want to be removed. This method will give an error if the element is not already in the list.

testArray.remove(“new element”)

There are other useful method that you can use like “count” which returns the number of elements in the array, and “sort” which will sort the elements in the array.

If for what ever reason you are looking to create an array of integers from 1-40. instead of creating the array, and starting from 1 adding all the numbers into the array, python gives you a easy way of doing it. the method is called “range”

print range(1,40)

This will display an array with the values from 1-40. If you add a 3 parameter you can even put an increment value.

print range(1,40, 2) 

This will display an array with the values from 1-40 skipping every other number.

These is just one of the data types that python has to offer. If you have any questions about arrays or want to learn more, please don’t hesitate to ask.

rmtsoftware:

Python is a loosely typed programming language. This means that you do not have to specify the type of the variable. For example this is perfectly valid in python:

abc = “hello world”

This is a simple variable declaration that sets the string “hello world” to the variable abc. Notice that there is no indication that the variable is a string except for the actual value of the variable. In other programming languages you have to specify the type of variable (for example Java).

String abc = “hello world”;

Another thing that python has to offer is that you can change the type of the variable very quickly. 

variable change

This is a quick example of how the variable “abc” was changed from a string containing “hello world” to a integer value of 10.

In the python programming language there is a simple command to print something to the screen. The comment is “print”. So when debugging a program and you cannot figure out why you are getting weird data or it is not going into a loop/if statement. Use the print statement to display the value of the variable to the console.

There are a few data types in python that will be used numerous times in these post/examples so I am going to run through a couple so you get an idea.

String —- A string is a simple value containing text. EX: “hello”

int —- A integer is a real number. EX: 10 or 5

double —- A double is a number that can have decimal values (Fractions) EX: 2.3

Next post I will get into most complex data types in python like Arrays, Lists, Stacks and Queues.

samuraikitty:

Ok, short list of what I’ve learned (went through my journal today, and was pretty amazed at how far I’ve actually come):

  • Indirection: FUCKING USE IT
  • That little “Refactoring” pullout in your context menu? MOST USEFUL THING ON THE PLANET AND YOUR LECTURERS WERE TOO SHIT TO MENTION IT
  • When it…

mylifeasarry:

this summer i want to learn java and javascript in as much depth as possible.

i need to learn java better before a class next semester. i know it a little but i’m really bad at it….

also javascript is just essential for anyone going into web dev. and it’d just be nice to be…

hugohabel:

Excellent article explaining why you shouldn’t consider hiring more developers when all your developers are fully loaded with work. The only part I disagree with is when the author mentions that fixing bugs is not a priority, which I believe is one of the most important priorities, even on some books you can read it costs less to a company fix a bug as soon as it is detected.

(via hugohabel-deactivated20120502)