Learntofish's Blog

A blog about math, physics and computer science

Archive for the ‘computer science’ Category

Python 3: Inheritance and super()

Posted by Ed on April 23, 2016

Inheritance in Object Oriented Programming (OOP) means that you create a new class by extending an existing class. For example, suppose we have a class Shape with the attribute position. Then we can create a new class Circle by taking Shape and extending it by a new attribute center: Read the rest of this entry »

Posted in computer science, programming | Tagged: , , | Leave a Comment »

Try Linux with these simple steps

Posted by Ed on March 26, 2016

Have you ever wanted to try Linux? Here is how you can do it, and all you need is a USB memory stick. Read the rest of this entry »

Posted in computer science, Education | Tagged: , , , | Leave a Comment »

Github tutorials

Posted by Ed on February 7, 2016

Here are some nice github tutorials: Read the rest of this entry »

Posted in computer science, Uncategorized | Tagged: , | Leave a Comment »

Start menu in Windows 10 does not work anymore

Posted by Ed on December 8, 2015

Today I’ve finally received the notification for downloading Windows 10 as an upgrade from Windows 7. I had reserved it earlier a few months ago and was already worried that something was broken because it took so long. The installation was  smooth and went without any problems.

One thing I don’t like in Windows 10 is how the font looks like. The letters are suddenly so thin and it appears as if the antialiasing is too high compared to how they looked in Windows 7. I will have to look into this deeper later.

The next day I encountered something annoying. The start menu would not show up anymore, symbols in the task bar on the bottom right were not being displayed, and in the center of the task bar the icons for the browsers were missing. As a result, I couldn’t reopen a browser window after having minimized it.

Turns out that the culprit was Windows’s hibernating mode. When I shut down my computer I also turn off the power completely with a switch on the power strip. However, the computer needs some power in hibernating mode, otherwise data will get lost and this is probably what lead to the problems mentioned above.

Disabling the hibernating mode shuts down the computer completely and also allows turning the power off completely. To do so press the Windows Key + X and open a command prompt with administrator rights. Enter the command

powercfg -h off

This has resolved all the problems.

Posted in computer science, Uncategorized | Tagged: , | Leave a Comment »

How to write code the pythonic way

Posted by Ed on April 24, 2015

Check out this interesting article by Constantine Lignos called Anti-Patterns in Python Programming. It demonstrates with several examples how you should write code in Python.

Posted in computer science | Tagged: , | Leave a Comment »

Introduction to generators in Python 3.4

Posted by Ed on April 22, 2015

In this blog post I will explain how generators are used in Python 3.4. Read the rest of this entry »

Posted in computer science | Tagged: , , | 1 Comment »

How to write Python code the right way

Posted by Ed on September 18, 2014

Here is a wonderful talk by Raymond Hettinger with the title Transforming Code into Beautiful, Idiomatic Python

Slides can be downloaded here and viewed online here.

His Twitter where he regularly posts short Python code.

Posted in computer science | Tagged: | Leave a Comment »

C programming tutorial (by Adam)

Posted by Ed on August 29, 2013

Here is a great C programming tutorial by Adam. It’s currently made up of 87 videos where each video lasts for 5-10 minutes. I really like the drawings that illustrate what is going on in the memory.

I went through the tutorial by watching and simultaenously copying the source code. And before I would go to the next video I recreated the code from memory which I found best to learn the concepts.

Posted in computer science | Tagged: , , , | Leave a Comment »

Visualizing references and objects in Python

Posted by Ed on April 2, 2013

Pythontutor is a website that lets you visualize your Python code.

For instance, type the following Python code into the window:

x = [1, 2, 3]

# reference to the object that x points to
y = x

# create a copy of the list [1,2,3] and store its address at z
z = x[:]

# create a copy of the list [1,2,3] and store its address at z
a = x.copy()

# reference to the object that z points to
a = z

Then, change from Python 2.7 to Python 3.3 in the drop down menu below the window and click the button Visualize Execution.
Click on forward to process the code and observe how the graphics changes on the right.
Pretty neat, isn’t it!

You can also change some settings such as choosing between Python 2.7 and Python 3.3 and using the address id instead of the arrows.
Change the following settings:
inline primitives and nested object -> render all objects on the heap
draw references using arrows -> use text labels for references

Then, paste the following code into the window:

myString = "hello"

# observe how the id changes
myString += " world"
print(myString)

Observe how the id changes if you try to append the string " world" to myString.
That is because strings are immutable in Python such that Python first creates the new string object "hello world".
The addess of this new object is then assigned to the reference myString.

Posted in computer science | Tagged: , , , | Leave a Comment »