Posts Tagged ‘language’

How to Avoid the 7 Most Frequent Mistakes in Python Programming

Monday, September 9th, 2019

python-programming-language-logo

Python is very appealing for Rapid Application Development for many reasons, including high-level built in data structures, dynamic typing and binding, or to use as glue to connect different components. It’s simple and easy to learn but new Python developers can fall in the trap of missing certain subtleties.

Here are 7 common mistakes that are harder to catch but that even more experienced Python developers have fallen for.

 

1. The misuse of expressions as function argument defaults

Python allows developers to indicate optional function arguments by giving them default values. In most cases, this is a great feature of Python, but it can create some confusion when the default value is mutable. In fact, the common mistake is thinking that the optional argument is set to whatever default value you’ve set every time the function argument is presented without a value. It can seem a bit complicated, but the answer is that the default value for this function argument is only evaluated at the time you’ve defined the function, one time only.  

how-to-avoid-the-7-most-frequent-mistakes-in-python-programming-3

 

2. Incorrect use of class variables

Python handles class variables internally as dictionaries and they will follow the Method Resolution Order (MRO). If an attribute is not found in one class it will be looked up in base classes so references to one part of the code are actually references to another part, and that can be quite difficult to handle well in Python. For class attributes, I recommend reading up on this aspect of Python independently to be able to handle them.

how-to-avoid-the-7-most-frequent-mistakes-in-python-programming-2

 

3. Incorrect specifications of parameters for exception blocks

There is a common problem in Python when except statements are provided but they don’t take a list of the exceptions specified. The syntax except Exception is used to bind these exception blocks to optional parameters so that there can be further inspections. What happens, however, is that certain exceptions are then not being caught by the except statement, but the exception becomes bound to parameters. The way to get block exceptions in one except statement has to be done by specifying the first parameter as a tuple to contain all the exceptions that you want to catch.

how-to-avoid-the-7-most-frequent-mistakes-in-python-programming-1
 

4. Failure to understand the scope rules

The scope resolution on Python is built on the LEGB rule as it’s commonly known, which means Local, Enclosing, Global, Built-in. Although at first glance this seems simple, there are some subtleties about the way it actually works in Python, which creates a more complex Python problem. If you make an assignment to a variable in a scope, Python will assume that variable is local to the scope and will shadow a variable that’s similarly named in other scopes. This is a particular problem especially when using lists.

 

5. Modifying lists during iterations over it

 

When a developer deletes an item from a list or array while iterating, they stumble upon a well known Python problem that’s easy to fall into. To address this, Python has incorporated many programming paradigms which can really simplify and streamline code when they’re used properly. Simple code is less likely to fall into the trap of deleting a list item while iterating over it. You can also use list comprehensions to avoid this problem.

how-to-avoid-the-7-most-frequent-mistakes-in-python-programming-8

       

6. Name clash with Python standard library

 

Python has so many library modules which is a bonus of the language, but the problem is that you can inadvertently have a name clash between your module and a module in the standard library. The problem here is that you can accidentally import another library which will import the wrong version. To avoid this, it’s important to be aware of the names in the standard library modules and stay away from using them.

how-to-avoid-the-7-most-frequent-mistakes-in-python-programming-5

 

7. Problems with binding variables in closures


Python has a late binding behavior which looks up the values of variables in closure only when the inner function is called. To address this, you may have to take advantage of default arguments to create anonymous functions that will give you the desired behavior – it’s either elegant or a hack depending on how you look at it, but it’s important to know.

 

 

how-to-avoid-the-7-most-frequent-mistakes-in-python-programming-6

Python is very powerful and flexible and it’s a great language for developers, but it’s important to be familiar with the nuances of it to optimize it and avoid these errors.

Ellie Coverdale, a technical writer at Essay roo and UK Writings, is involved in tech research and projects to find new advances and share her insights. She shares what she has learned with her readers on the Boom Essays blog.

Unique MenuetOS – Free Software 32 / 64 bit OS entirely written in assembly language

Wednesday, July 10th, 2013

 

unique operating-system menuetos written-in-assembler-programming-logo

Something very unique, I stumbled on some time ago and worthy to mention and recommend for everyone to test is MenuetOS. Can you imagine, someone might write an operating system entirely from scratch in 32 / 64 bit Assemler? Idea sounds crazy and impossible but in fact developers of MenuetOS already achieved it!

Unique OS - menuetos asm free os start-menu screenshot

Normally every modern operating system nowadays is based on some kind of UNIX / Linux / or NT (Windows) technology or at least follows some kind of POSIX standartization.
 The design goal of MenuetOS since the first release in year 2000, is to remove the extra layers between different parts of an OS. The more the layers more complicated the programming behind is and therefore this creates bugs more bugs. MenuetOS follows the idea of KISS model (Keep It Simple Stupid). Its amazing what people can write in pure asm programming!! 64 bit version of menuet is also backward compatible with 32 bit. MenuetOS supports mostly all any other modern OS does. Here is list of Supported Features:

 

 

 

 

  • – Pre-emptive multitasking with 1000hz scheduler, multithreading, multiprocessor, ring-3 protection
  • – Responsive GUI with resolutions up to 1920×1080, 16 million colours
  • – Free-form, transparent and skinnable application windows, drag'n drop
  • – SMP multiprocessor support with currently up to 8 cpus
  • – IDE: Editor/Assembler for applications
  • – USB 2.0 HiSpeed Classes: Storage, Printer, Webcam Video and TV/Radio support
  • – USB 1.1 Keyboard and Mouse support
  • – TCP/IP stack with Loopback & Ethernet drivers
  • – Email/ftp/http/chess clients and ftp/mp3/http servers
  • – Hard real-time data fetch
  • – Fits on a single floppy, boots also from CD and USB drives

MenuetOS has fully functional Graphic interface (environment). Though it is so simple it is much more fast (as written in assembler) and behaves more stable than other OS-es written in C / C++.
Its bundled with a POP3 / Imap mail client soft

menuetos assmebly OS mail client
As of time even some major legendary Games like DoomQuake, Sokoban and Chess are ported to MenuetOS !!!

doom2-id-games-running-on-menuetos-operating-system-in-assembler-from-scratch

MenuetOS Doom

quake legendary game running on Menuetos asm free OS

Quake I port on MenuetOS

Below are some more screenshots of Apps and stuff running

Maniac Mansion running on MenuetOS assembler build free Operating system

The world famous Maniac Mansion (1987)

Prince of Persia running on 32 64 bit assembler written GPL free-OS

Arcade Classic of 16 bit and 8 bit computers Prince of Persia running on top of dosbox on MenuetOS

For those who like to program old school MenuetOS has BASIC compiler, C library (supports C programming), debuggers, Command Prompt.

It even supports Networking and has some  most popular network adapters drivers as well as has basic browsing support through HTTP application.

unique-os-menuetos-browsing-with-httpc-browser

You can listen music with CD Player but no support for mp3 yet.
To give MenuetOS a try just like any other Live Linux distribution it has Bootable LiveCD version – you can download it from here
MenuetOS is a very good for people interested to learn good 32 bit and 64 bit Assembler Programming.
Enjoy this unique ASM true hacker OS 😉

Bessarabian Bulgarians – A short documentary about 380 000 Bulgarians who live today in Territory of Moldova

Wednesday, January 30th, 2013


 

 Bessarabian Bulgarians in Moldova ex-Romania – documentary movie

Very few Bulgarians nowadays know well their history. Bulgaria has glorious and rich history. After the liberation of Bulgaria many Bulgarians migrated to Russia and Moldova, to escape the fierce wars and mass killingins from Ottoman Turkish. Nowdays most of people who live in Bulgaria has negative attitude towards our homeland. Few are those that know that 1000 kilometers from Bulgaria there are more Bulgarians, who are trying hard to preserve their nationality. It is very curious, that most of Bulgarians nowadays want to emigrate in Western countries, where Besarabian Bulgarians think and dream of going back to Bulgaria. I think we Bulgarians should re-think well before we think about emigration and try to do more for our country instead of having the post-communist and still rooted by communist negativism and pessimism that is ruling us.
 

Bulgarian Traditions of Bessarabian Bulgarians

(Note to make here is a lot of the commentaries on the video are junk especially concerning religion). Below is interesting statistics about Bulgarians who live on the lands of Besarabia. It was curious for me in Besarabia there is also Bulgarian schools and even Bulgarian universiy! There is also a city named BOLGRAD (BOLGAR GRAD – city of Bulgarians),

The general count of Besarabian Bulgarians in Republic of Moldova and Ukraine are about 230 000  There are also 151 596 who are Turkish speaking Bulgarians (Gagauzi). The complete number of Bulgarians Living in Besarabia is about 380 000!

In Ukraine, the number of Bessarabian Bulgarians is estimated at over 129,000 in Budjak (in the Odessa Oblast in the southern part of the country), and 75,000 elsewhere (mostly in other parts of Southern Ukraine), according to the 2001 Ukrainian Census, which counted a total of 204,600 Bulgarians in Ukraine. Bulgarians are a majority in Bolhrad District (45,600 of its 75,000 inhabitants), but they also inhabit other districts of Budjak: Arciz – 20,200 of the 51,700, Tarutino – 17,000 of the 45,200, Izmail – 14,100 of the 54,700, and Sarata – 10,000 of the 49,900. There are also 8,600 Bulgarians in the city of Izmayil (85,100 total population). Outside Budjak, Odessa has many Bulgarians that have moved there in recent years. The city of Bilhorod-Dnistrovsky is about 4% Bulgarian, making them the third-largest ethnicity there. The results of the census held in October 2004, there are 65,072 Bessarabian Bulgarians (1.95% of the population) in Moldova (excluding the region of Transnistria), concentrated mostly in the southern parts — chiefly in Taraclia district. In the census held in November 2004 in Transnistria, 3,164 (3.16%) Bulgarians have been counted in Tighina and surroundings and further 10,515 (2.39%) on the Eastern bank of the river Dnestr. 29,447 Bulgarians live in the cities (and represent 2.26% of the urban dwellers), and 36,215 live in the countryside (1.74% of the rural inhabitants). 90.60% of ethnic Bulgarians were born in Moldova (the national average is 94.6%), 5,968 (9.09%) in other countries that were once in the Soviet Union (the national average is 5.16%), and 199 (0.30%) were born elsewhere. In Moldova (and likely Ukraine too, although statistics are not available here), the Bulgarians tend to use their native Bulgarian in rural areas, and Russian (instead of the majority language Romanian) in cities and towns. 53,178 or 80.99% of ethnic Bulgarians declared Bulgarian language as native (69.23% in urban areas, and 90.55% in rural ones), 2,766 or 4.21% of them declared Romanian language as native (4.91% in urban areas, and 3.64% in rural ones), 9,134 or 13.91% of them declared Russian language as native (25.08% in urban areas, and 4.83% in rural ones), and 584 or 0.89% of them declared another language as native (0.78% in urban areas, and 0.98% in rural ones). 35,808 or 54.53% of ethnic Bulgarians declared Bulgarian language as first language in daily use (36.81% in urban areas, and 68.95% in rural ones), 5,698 or 8.68% of them declared Moldovan language/Romanian language as first (7.93% in urban areas, and 9.29% in rural ones), 23,259 or 35.42% of them declared Russian language as first (54.45% in urban areas, and 19.95% in rural ones), and 897 or 1.37% of them declared another first language (0.81% in urban areas, and 1.81% in rural ones). Bessarabian Bulgarians represent 28,293, or 65.56% of the population of the Taraclia district. There are also Bulgarians in Chişinău (8,868, or 1.2%), Găgăuzia (8,013, or 5.1%), Cahul district (5,816, or 4.9%), Leova district (3,804, or 7.4%), and Cantemir district (3,736, or 6.2%). The share of ethnic Bulgarians in Transnistria is 10,515 (2.39%), of which 2,450 (1.55%) in Tiraspol, and 7,323 (8.44%) in Slobozia sub-district (which contains the village of Parcani). There are also 3,001 (3.09%) Bulgarians in the city of Tighina, and 342 in 3 suburbs. In total, there are 79,520 (2.02%) Bulgarians in Moldova, including Transnistria. Bessarabian Bulgarians represent a majority in one city of Moldova, Taraclia (10,732 Bulgarians, or 78%) and in 8 communes in the country:

The Great Escape video – Why Money-less Visa, Mastercard etc. electronic transfers impose risk for our freedom

Sunday, January 27th, 2013

A friend of mine send me a video in skype. It is a representation of one sad reality. A pigs are living in a farm, being wake up with electronic signal. The pig start eating, playing, f*cking etc. It is a lot of fun happiness and freedom. Some of them which are more initiative possess the typical characteristics of middle age times explorer and the spirit of researchers and scientists who tend to explore the universe, research new things, learn and get to the limit of things. The poor animals comes up to electric fence with VISA Electroin. Though the video is intending to be anti-propaganda of use of VISA debit cards, same is more or like true for travel VISAs. Nowadays within the European Union everyone is free to travel freely, everywhere inside the EU, it seems so fun you can learn new cultures, earn money, enjoy yourself and dissolve yourself in happiness and joys forgetting your own culture language and nationality. You become part of one "happy farm" not knowing your once free land though being stretched is limited by electric powered "no escape" fence.
 

 The Great Visa Escape – The deception that moneless transfers makes you free – money-less transfers pose future risk to human freedom

 

The creator of C and UNIX Dennis Ritchie passed away R.I.P. Dennis

Thursday, October 13th, 2011

Dennis Ritchie old young picture

I just read the lwn.net – Linux Weekly news ‘s website the very sad news that one of the greatest modern day computer heroes Dennis MacAlistair Ritchie after a long illness has passed away in his home.

The original notification for this grieving news are on Rob Pike’s Google Plus wall , this is the original message:

Rob Pike - 1:02 AM - Public
I just heard that, after a long illness, Dennis Ritchie (dmr) died at home this weekend. I have no more information.
I trust there are people here who will appreciate the reach of his contributions and mourn his passing appropriately.
He was a quiet and mostly private man, but he was also my friend, colleague, and collaborator, and the world has lost a truly great mind.

For all those who haven’t heard about Dennis Ritchie , he was a computer scientist who developed the C Programming language and had an immeasurable influence on all kind of Modern programming.

C Programming Language cover Dennis Ritchie

Dennis worked on the development of Unix’s predecessor Multics as well as with Ken Thompson worked together in Bell Labs and are practically the fathers of UNIX.
Unix the Seventh Edition source code has later become the basis for the early UNIX BSD distributions. Among the most important technical contributions Dennis has done is the introduction of a Streams mechanism – pipes – (as called today in GNU/Linux and BSD and other unices).
Ritchie’s C Language creation on top of Ken Thompson’s B Programming language has been standartized and become the de-facto standard for almost every modern existing OS around.
Moreover dmr has been among the co-creators of Plan 9 Operating system (which is currently open-source distributed) as well as coded a few bits for the Inferno OS which today is known under the code name Vita Nuova

Unix Live Free or die Bell labs early UNIX logo

dmr (the hacker nickname of Dennis) lines up across the most notable computer hackers of all times. He received U.S. national Medal of Technology in 1999 from president Bill Clinton for his contributions to co-inventing the UNIX operating system and the creation of C Language

Denis Ritchie receives national prize in 1999 for Technology from president Bill Clinton
To sum it up DMR is just an “icon” in the computer geek world and his memory will surely live forever in the hacker undeground and computer geek culture.

Dennis Ritche near a personal computer picture

A few quotes dmr is so famous with:

"I am not now, nor have I ever been, a member of the demigodic party."
"Usenet is a strange place."
"UNIX is very simple, it just needs a genius to understand its simplicity."
"C is quirky, flawed, and an enormous success."
"We really didn't buy it thinking we'd have this enormous investment."

Here is also a short video telling a few words of UNIX history and showing Dennis Ritchie in his UNIX development years:

Farewell Denis! See you in Hacker’s paradise 😉