Creating Circular Mastery

Project concept

In the past few months I worked a lot with shaders in Unity which mainly uses Nvidia CG as its shader language and converts it for specific platforms. I have some shader skills with HLSL and GLSL but I started anyway studying this language and making mostly 2D shaders. I like 3D shaders but I think they need more skills than 2D shaders to be really good, so I started with the 2D ones.

Working on a widget for a in-game HUD, I  needed to create some circles (both UI and Sprite2D) and I realized that I had two choices: to use an image or to create it from scratch. Both methods have its pros and cons, which one you think I used?

 

Shader plugin

I started to look at some shaders I like on ShaderToy and I came across some pretty shaders to create simple circles and circular bars, used for loading screen. In this site the shaders are mostly in GLSL so I ported some in CG language, creating a starting point for the different kinds of shaders I had to make. I realized that I could reuse parts of these shaders for other purposes, so I came up with the idea that if these shaders are flexible enough they could do a lot of things in terms of simple “circle and bar” animation, especially for loading screens.

So, I started to write down all the things I wanted from shaders like these, planning to make flexible shaders to create a basic animation widgets. So I created a play-test scene in Unity to test the shaders I wanted to make and I started adding them more and more features as well. The graphic style and animation I want to replicate are similar to these examples of this loading widgets I found in different games (The Division, Overwatch).

Releasing Circular Mastery

After developing a reasonable amount of features for the shaders I created, I started to packing everything in order to become a product called Circular Mastery for the Unity assets store. This means creating all the product images, logos, user manual, etc… and then adding some additional support for the required features of Unity assets (like the undo function).

It was the first time I had to create a package for Unity and I have to admit, it was easier than expected because there are a lot of resources and documentation on releasing assets for the assets store, and the control panel for publisher are very simple and clear.

If you are interested in the plugin here you can find a brief description of the plugin with all the links. The plugin is out right now so go check it out!

Circular Mastery on the Assets Store

 

If you are interested on game development and game design I have a series of posts in which I show my progress of the development of a mobile game Steady Drop. HERE!

If you like retro console building I have another series of posts in which I tell my process on creating a Game Boy fused with a Raspberry. HERE!

I define myself as a creative developer.

Steady Drop – Log #12

 

In this post I will briefly describe my process to create sounds effects and music for Steady Drop. Nothing about development or code this time, sorry 🙂

 

The recording setup

Problem 1: how do I record sounds?

I started recording some sounds with my smartphone with an external mic plugged in. To achieve the best result I could with my “great and professional” gear, I used a folded blanket placed over the bed like a little camping tent, to make small recording room with no reverb, no echoes and limiting outer noises. Problem solved!

 

Problem 2: what do I record?

I literally looked around in my apartment and grubbed some random objects I thought could potentially produce some noise, like old CDs, some packaging boxes and some kitchen tools. With these I will produce sounds manipulating or letting them falling on a surface while I have the recorder on. Problem solved!

 

Problem 3: how do I mix?

To clean and mix the recordings of the sounds I chose Audacity which is a very popular software used for audio recording and editing. In this case I will use it only for the editing part, removing the background noise and isolating the individual sounds.

 

The sounds

I started with some weird high pitched sounds and some low-deep “blocky” sounds. I don’t have a list of sounds I have to produce in the game but I want to create like a little sound library that I might reuse in the future. If I need a very specific sound for Steady Drop I can record it later. For this first phase, I want to adopt a broad focus on sounds to narrow it step by step and to choose and produce very specific ones. However I will try and add sounds only if the gameplay needs it without putting sound effects for everything.

 

The Music

Meanwhile I started creating some music track with SoundTrap which is a very interesting site that provide a DAW, but you don’t have to install anything on your PC, it’s all onlineThey have different paid plans but you can choose to use the free plan with the only restriction on the number of projects, number of instruments and number of loops. So for now I’ll stay with an unpaid plan. For Steady Drop I want short music tracks (at least three) possibly suited for looping. The genre I want, I call it “dreamy electronic”, which is electronic music with a lot of echoes and delays in the pads, slow paced, clean and minimal percussions. I will try my best to achieve something like that, without going crazy, I hope.

 

Stay tuned for future posts of the series, and if you are interested on other post series don’t forget to visit the blog main page 🙂

 

I define myself as a creative developer.

Steady Drop – Log #11

 

Collecting game data for simple statistics

After the previous iteration I’ve done on graphic and UI improvements in the game I started to think about collecting some data from the game that comes from the player actions, in order to have a sort of statistics screen that the player can check from time to time to see his progress, and furthermore in this way the game can collect useful data to base some kind of achievements system in the future. For example there will be an achievement for falling through 100 game units (or meter if you want) or for playing 500 rounds. For the achievements system, I’m planning to integrate some native stuff for Android and iOS (Play Game Services for Android and Game Center for iOS), starting with Android, obviously.

 

Implementation of the statistic system

For the implementation, I chose to create a single class that handles all the requests to store and get the data collected. The data we want to collect are mostly integer numbers handled in different manners. For example, if I want to memorize the high score, I have to tell this entity that the data tagged as “high_score” has to be saved as MAX of the previous, and on every game over I have to memorize the current score. In this way, every time I memorize a new value, the entity keep the max between the previous and the current values. In a similar way, I can memorize a counter (like to count the rounds played). What I have to do is to memorize a value 1 every  game over.

This entity relies on the DataMgr to load and save the data. The DataMgr itself is an interface to read and write values from the physical memory of the device you run your Unity application. Here some snippets I took from the StatisticMgr.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//Load and save data from the device
public void loadLocalData() {
    foreach(KeyValuePair<string, StatData> entry in dataBank) {
        string readData = DataMgr.readData(entry.Key);
        if(readData != null)
            entry.Value.setInitialValue(readData);
        else
            entry.Value.setInitialValue(0f);
    }
}

public void saveLocalData() {
    foreach(KeyValuePair<string, StatData> entry in dataBank) {
        DataMgr.writeData<double>(entry.Key, entry.Value.value);
    }  
}


//For store a new value in game
public void storeNewValue<T>(T _value) where T: IConvertible {
    Double dValue = Convert.ToDouble(_value); //numbers stored as double
    switch (mType) {
    case(StatDataType.PLAIN): //saved without logic
        value = dValue;
        break;
    case(StatDataType.SUM): //saved as increment
        value += dValue;
        break;
    case(StatDataType.MAX): //saved as max (if the current max is lower
        value = Math.Max(value, dValue);
        break;
    }
}

 

Where is the sound?

I’m still planning to make sound and music for the game but the sound iteration will take some more time. I could pay somebody to make music and sound for me, or take it from some Creative Commons site, but since I have a little knowledge of music theory in general and in the past I was into recording, DAWs, MIDI and stuff, I want to try to harness my past passions to make something out of it, before asking for external help. What I have in mind, though, is to record some real sounds and manipulate and combine it to create the sounds I need.

Stay tuned for future posts of the series, and if you are interested on other post series don’t forget to visit the blog main page 🙂

 

I define myself as a creative developer.

Isometric Camera with Unity

 
I like real time cameras subject so much that I already made a post on real time cameras (here) specifically on third person cameras. This time I will show you how I set up a simple isometric camera for a game prototype I made in Unity.

 

The isometric camera

Basically an isometric camera has an isometric view in which the perspectives are avoided, it’s like having a “zero-point” perspective instead of the three-point perspective you normally have on a classic first or third person camera. As you can see, there are no perspective deformations on what the camera sees, for example, with isometric view, all the edges of the cube are parallel. Technically, by having a an isometric view, the camera is already isometric, but on top of that, in games this view is classically used used with a 45° degree rotation.

This type of camera was used a lot in the past (especially on the 16-bit era) in games like Q Bert, this first Diablo, the first Fallout and Age of Empires, mainly to give more sense of three dimensional space with a minimal computational effort. Lately it is used for nostalgic reasons and for specific artistic or design choices in games like Monument Valley.

 

The camera script

The only thing you have to do it in order to use my simple isometric camera is to add this script to a Gameobject. Since the script require a Camera, it will add it for you. When the script starts, it creates all the things needed to run an isometric camera, which essentially are a target to look to and some other Gameobjects used for camera movements (which I will show you in a minute).

Then the most important part is camera settings and rotation. The camera has (obviously) to be orthographic otherwise we have perspective involved and we don’t want it. For the rotation of the camera, I chose to make the camera a child of the target and to rotate the target instead of rotating the camera itself, just because it seems more logical to me to apply the further movements and rotations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void Awake()
{
    //Objects creation
    GameObject target = new GameObject("Camera Target");
    GameObject movableRef = new GameObject("ISO Camera Movement");
    movableRef.transform.localEulerAngles = new Vector3(0, 0, 0);
    m_IsoMov = movableRef.AddComponent<IsoMovementController>();
    m_IsoMov.init(speed, limits, invertedXAxis, invertedYAxis);

    //Camera settings
    m_Camera = GetComponent<Camera>();
    m_Camera.orthographic = true;
    m_Camera.tag = "MainCamera";
    m_Camera.orthographicSize = 20f;
    m_Camera.backgroundColor = new Color(.3f, .3f, .3f);

    //Camera positioning and objects parenting
    GetComponent<Camera>().transform.position = new Vector3(0f, 0f, -50);
    GetComponent<Camera>().transform.parent = target.transform;
    target.transform.parent = movableRef.transform;
    target.transform.localEulerAngles = new Vector3(45, 45, 0);
}

 

Camera motion

While creating this camera, I wanted to add a little bit of movements and even a rotation. To do this, I created a second script and attached to the parent of the camera target, the controller. In this way the controller rotates and moves the target (in real time), and the target has rotated (and keeps the rotation of) the camera. That’s the reason of all of those objects in camera creation.

Movements

For the movements I just taken the vertical and horizontal axis and translate accordingly but within a certain limits (setted in the inspector), in this way we can’t get outside of a certain scene or environment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void FixedUpdate ()
{
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");

    if(!h.Equals(0f) || !v.Equals(0f))
    {  
        Vector3 trans = new Vector3(h*.5f + v*.5f, 0, v*.5f - h*.5f);
        transform.Translate(trans * speed *  Time.deltaTime, transform);

        Vector3 pos = transform.position;
        pos.x = Mathf.Clamp(pos.x, -limits.max_X, limits.max_X);
        pos.y = Mathf.Clamp(pos.y, -limits.max_Y, limits.max_Y);
        pos.z = Mathf.Clamp(pos.z, -limits.max_Z, limits.max_Z);
        transform.position = pos;
    }
}

 

Rotation

As a reference for the rotations I took the camera from the game Anno 2070, which can rotate towards the target (on the horizontal plane) of a certain angle. I wanted something similar but more defined: I wanted the rotation step to be 90°. In this way when the camera has finished rotating, you are still in a isometric view but you are looking at another side of the scene. This concept of having a rotation step I saw it on Fez, which is a 2D game, where you can rotate the camera, 90° degree at the time. It is actually a 3D game. Here’s the code for the rotations.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void FixedUpdate ()
{
    if (Input.GetButtonDown("Jump"))
    {
       
        if (!m_IsRotating)
        {
            float c_rot = Input.GetAxis("Jump");
            Debug.Log(c_rot);

            m_IsRotating = true;
            m_DesiredRot = transform.rotation;
            m_DesiredRot *= Quaternion.Euler(0, 90*Math.Sign(c_rot), 0);
        }
    }
}

[...]

void Update()
{
    if (m_IsRotating)
    {
        m_RotationData.rot_value = Mathf.Lerp(m_RotationData.rot_value, m_RotationData.rot_sp_max, Time.deltaTime);
        transform.rotation = Quaternion.Slerp(transform.rotation, m_DesiredRot, Time.deltaTime * m_RotationData.rot_value);
        if((m_DesiredRot.eulerAngles - transform.rotation.eulerAngles).sqrMagnitude < 0.1)
        {
            m_RotationData.reset();
            transform.rotation = m_DesiredRot;
            m_IsRotating = false;
        }
    }
}

 

Final results

This camera works great (with some adjustments), for example for infinite runners or strategic games that need to have a top view of the “game board”. In order to work properly, however, the 3D models you put in the scene have to be created for an isometric view.

You can find the full Unity project right here (with a beautiful voxel model I made) feel free to use it and modify it.

Unity Project

I define myself as a creative developer.

Steady Drop – Log #10

Deadline changes

I had the milestone to complete the next development iteration of Steady Drop at the end of march 2017, but for the lack of time and for the efforts put in other projects (like the game I made for the Global Game Jam 2017) I’m forced to postpone this milestone and to go a little bit further with the deadlines. The project is still growing, it’s just I had little drawbacks, that’s it. I’m still adding improvements here and there, most graphical ones, and I have some “big” features I want to add before the next deadline. Like I said, I fixed most of the bugs I received from the alpha-testing phase and I’m still integrating some improvements based on the feedback I had. Goos news after all!

Visual improvements

I reviewed the color palette of the entire game, so I changed every color a little bit to make it more glued together (I used a palette generator) and to give more sense to the overall experience. But I completely changed the enemy colors: they was very similar to the avatar of the player but now, as you can see, they have their own color, and it’s more clear to the player that’s this shapes are not something related to the avatar he’s guiding down.


Another two visual improvement I’ve added are the trail behind the falling avatar and a particles generator on the bottom of the screen, they both give more sense of movement.And last but not least I’ve added a dynamic gradient un the background. So here you can see the differences between how it looked like and how it looks like now.

 

Next steps

One of the things I want to do next is to add some visual feedbacks when you lose health (or zero-gravity time) and to make some enemies a little bit more alive with some scale animations. I’m also planning to rewrite part of the UI system and replace the UI of the main menu, because I made the current placement just for the prototype, which has limited menu choices.
Next I will have to modify the tutorial (again) because I don’t like the current one, and to work on some game balance parameters like the score multiplier…a lot of magic numbers 🙂 After that, I will start to research how to integrate and produce sounds and music. It will be fun!

Just a reminder, if you want to play the alpha, just download and install this file. Steady-Drop-Alpha

I define myself as a creative developer.

Steady Drop – Log #9

Alpha released

 

I released the alpha of Steady Drop! It was a silent release (sadly I’m not a marketing guy :-P), which I’ve done only for people I know and for members of some Facebook groups I’m in, but It was the right time for a first slot of tests.

Right after releasing the alpha version, I started to receive a lots of useful feedbacks by the “alpha testers”. I gave them the possibility to leave a feedback in a traceable way (with a Google Form) or in a more direct and fast way. One of the last changes I’ve done right before the release was to add a button to leave a feedback on a form I made just for them. With this form I tried to gather all the informations I needed in order to progress the development in the right direction and make Steady Drop more playable and easy to use.

After all, seeing my game from another person’s perspective is the best way to find out some flaws which are invisible to me and just view the experience from another angle I didn’t considered before. Seeing what another person sees while playing your game is invaluable, and the more you have the possibility to let this happens, the more your game can improve. The only (little) drawback is that it’s required to filter in some way and extract the right signal from a feedback.

Thanks to all of the feedbacks, I listed a number of fixes, improvements and just some things I wanted to try, that I added to the task list I want to develop for the next step, which is a release of a beta version. I will also try to remove the sense of prototype while playing the game…it will be a hard one.

Right now I’m not putting so much effort on new features or bugfix, because I have other little projects I want to finish and publish (like this one). Right after finishing these little projects I will spend more time on this project and I will bring the development forward. If you want to try the alpha version of Steady Drop contact me 🙂

I define myself as a creative developer.

Steady Drop – Log #8

The value of the tutorial

It’s been awhile since the last devlog and from there I’ve been struggling so much in the project to create a proper tutorial.

At some point in the development (probably too late) I started thinking a way to explain to the player the main mechanics and  what are the goals of the game. There are a lot of ways of doing that (I’ve done my homework) and I thought that a short tutorial, at the first try, before starting the game, could be a good way to proceed.

I wanted a tutorial to explain the input basics and the main mechanics to the player, so in this section all the points and the game logics (talked here) and the spawn logic (talked here) have to work in a different way.

 

I started to work on this with a specific approach where the entire tutorial is a level slot (here I talk what I mean for slot) but this wasn’t really suitable for what I had in mind, so after almost forcing myself to try and develop a tutorial system that works in that way, I realize that it ain’t gonna work, so I deleted everything and started the tutorial system from scratch. After some time and some struggling, I finally have a tutorial system that “kinda” works. It’s still pretty rough but It does its job so I can refine it after the launch of the game alpha.

 

The biggest advice I want to leave is to consider designing the game and the code with a tutorial in mind, if you want one. The fact I didn’t think at all to the tutorial at the beginning of the development made me waste a lot of time to refactoring my code and redesign the levels. So, keep the rules simple and keep a simple way to explain it to the player right from the beginning of the development.

 

I think the alpha version of the game will be available in early january 2017. Stay tuned 🙂

I define myself as a creative developer.

Steady Drop – Log #7

 

In this post I will talk about how I put everything together and a little bit of code management.

Code versioning

Let’s begin with some things to remember: use a versioning system…and again, use a versioning system. I can’t stress this enough. Really, for every project you’re working on, use a versioning system like Git, SVN or Mercurial. It really helps keeping the project managed and it’s necessary for collaboration with other people. If you don’t know what is a repository you can start here.

My habit is to use repositories especially for work and since I saw more benefit using it I decided to use them on my side projects. For Steady Drop I used Git on BitBucket with only one branch (for now) it really helped me also giving more value of what I developed and I will develop.

 

Project structure

In the beginning the files are not well organized and the project was a little mess. At the time the code was really messed up and disorganized, since I started from a prototype. After some refactoring sessions, the code was more readable and clear but I still had one problem: the organization of the files (both scripts and assets).

I started to re-organize the project (with some Unity guidelines) doing a lot of folders to separate logically the assets and the scripts, but I wanted more for the scripts. So, I started to separate the scripts and to do a lot of folders. I was not sure if this approach could work out but then I started to separate the “core” scripts and the game specific scripts, finally giving a more meaningful project structure.

 

Reuse core modules

All that core scripts are inside a specific package so in the future I can take this package and use it in another project. But what is the best way to do it without going crazy on maintaining a “fork-like” package? Recently at work I started to use the git submodules which basically are repository that can be inserted in an existing repository (like an inception of repositories 😀 ), and I thought that I can create a module with all the core stuff and reuse it in different projects. This change will be the next “project-side” improvement and since I have already experience with multiple submodules in one project so, it will be a piece of cake to set things up for only one module.

 

Alpha is coming

The alpha of the game is going to be released in the next couple of months. The best way for me to release it is to give it to a restricted set of people, (like friends and relatives) and gather feedbacks from them. Then I will iterate once again to make things better and put some others features in the game to create (some day) a beta version.

 

 

I define myself as a creative developer.

Third Person Camera with Unity

 

The third person camera

The camera in a game is the eye that the player use to see inside the virtual world created for the game itself. There are tons of different types of camera, but the one we are going to analyze is the third person camera (TPC from now on) which allows to see the main character moving around in the world. In our case it’s a camera that follows the player. Great examples of games that use this type of camera are Super Mario 64, Zelda – The Wind Waker, Metal Gear Solid and Assassin’s Creed.

The purpose of this article is to show how to do a camera system in Unity, with basic intelligence that follows the player and avoids to hit walls by doing auto-adjustments of the distance from the player and the ground as well. The final results are not the best ones and there are certainly other and better ways to do it, and yes, I know there are some improvements that can be done, but the main purpose of this demonstration is to give a simple starting point.

Setups

The Unity script is located here. The only things you have to do in order to test the script are:

  • In a new Unity scene add a third person controller. You can use the standard ones
  • Add at least one floor.
  • Add a child GameObject to the controller called “target” for example, and position it where you want the camera to look.
  • Add a child GameObject to the controller called “position” to identify the position of the character: some meshes may have the anchor point positioned differently, so in this way you can decide the correct position of the anchor point. It’s a optional step but it makes things a little easier.
  • Add the script to the camera and put the child objects just created under the camera script parameters in the inspector.

The code is commented and contains also a function to draw lines in the inspector to better see what is going on with the offsets and positions.

Camera position and movements

Without further ado, let’s begin with the fun stuff. The wanted position for the camera is a point that has a distanceUp and a distanceAway from the target identifying a specific point. Obviously if there is a rotation of the character, this point rotate along with it keeping its distances. Now this point is only the wanted position and we want the camera to follow this point with a little of smoothness. Simple, in positioning phase I’ve multiplied Time.deltaTime for a smoothness value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public void Update()
{
//For collision avoidance we need 2 values:
// the distanceUp of the camera and the wanted position

Vector3 characterOffset = m_target.position +
new Vector3(0f, m_distanceUp - m_heightOffset, 0f);

drawDebugLines (characterOffset);
m_camPosWanted = m_target.position +
(m_target.up * (m_distanceUp - m_heightOffset)) -
(m_target.forward * m_distanceAway);

collisionAvoidance(characterOffset, ref m_camPosWanted);

//Positionig and orienting the camera
transform.position = Vector3.Lerp(transform.position,
m_camPosWanted, Time.deltaTime * m_smooth);

transform.LookAt(m_target);
}

 

The collision avoidance

To keep the camera in the correct position and avoid walls that can hide the character or collide, the script makes some tests:

  • Wall avoidance: if there’s a collider near the back of the character or between the camera and the character, the camera takes the position of the collision point (improvable).
  • Ceiling avoidance: if there’s a collider above the character or above the camera, the camera changes its y coordinates to stay under the collider.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Camera Wall avoidance - raycast from the back of the character and from
//characterOffset to camPosWanted
if(Physics.Linecast(fromObject, toTarget, out m_hitWall) ||
Physics.Raycast(m_characterPos.transform.position,
-m_characterPos.transform.forward, out m_hitWall, 3.0f))
{
toTarget = new Vector3(m_hitWall.point.x, toTarget.y, m_hitWall.point.z);
}

//Camera Ceil avoidance - raycast from the up of the character and from
//the up of the camera
if (Physics.Raycast(transform.position, Vector3.up,out m_hitUp, 1.0f) ||
Physics.Raycast (m_characterPos.transform.position, Vector3.up, out m_hitUp, 2.0f))
{
if (m_hitUp.collider.gameObject.layer != LayerMask.NameToLayer("Player"))
{
if (m_camPosWanted.y &gt; m_hitUp.distance)
{
Debug.Log("Ceil");
m_heightOffset += 0.2f; //adjusting the height
}
}
}

Improvements

Improvements that can be surely done are:

  • Making a FSM and attaching it to the camera: for example the camera has state like colliding, shaking, bouncing and a following common state.
  • Improving the wall collision not to see parts of the world behind the wall.
  • Adding a colliding sphere to the camera.

 

Consider also to watching this GDC video on which a creator of the game Journey talks about common mistakes and tips on creating a third person camera.

Third Person Camera (Gist)

 

 

I define myself as a creative developer.

From C++ to Python

 

This post is more theoretic than usual and I will analyze briefly my experience on passing from C++ to Python and what I found interesting to notice when learning another programming language is needed.

 

Introduction

After working with C++ for a while, I had to learn Python for the first time and use it with Panda3D engine. Right from the beginning I’ve found myself thinking in C++ style a lot of times while programming in Python, especially for the first couple of weeks. Finally I realized that the first programming language you master (or maybe your favorite one), can affect the way you program and think in other programming languages. Probably this thing is also true for the spoken languages.

When you learn your first programming language, you are learning also all the best practices and the techniques of the language itself. This type of notions aren’t merely syntactical and they belong to “programming theory” or “IT theory” rather than a specific language. But when you starting to master this language you create common mind paths for creating instructions and more complex modules that belong only to the specific language you’ve mastered. Obviously these are my opinions, I’m not an expert in psychology.

 

Programming mind path

To help passing from the C++ “mind path” to the Python ones to me has been pretty easy after all, but I recalled some struggling at the beginning. Now let’s analyze the two languages to try to facilitate the journey.

First of all, let’s talk about some actual differences from Python and C++:

  • Python is run through an interpreter and is interpreted each time it runs., whilst C++ is pre-compiled
  • In Python, there is no need to declare types explicitly
  • Python uses Garbage Collection whereas C++ does not.
  • C++ supports pointers and low-level memory management.
  • C++ is a statically typed language, while Python is a dynamically typed language.

 

As you can see in the previous short list Python and C++ are both object oriented languages but they are ruled by different philosophies. Beside these strict differences that are also some intrinsic principles and styles of coding that belong to the specific language and find place in the deepest part of a programmer’s mind, the mind paths. This more “abstract” side of the differences of usage is difficult to manage at the beginning and I think it takes some time to deal with it.

 

Things to remember

Fortunately the syntactic side of the differences is less deep-rooted and can be managed more easily: there are only some little things that can make you struggle, especially at beginning of the switch. I’ve listed a series of things I found useful to “easily” switch from C++ to Python.

  • Indentation and curly brackets: in Python there are no curly brackets to define a block of code but instead of this it use indentation
  • Loops with float: in Python you can’t easily define a loop with a float increment
  • Data structure declaration: Python has built-in lists and dictionaries and you can declare it simply with “[]” for lists and “{}” for dictionaries
  • There’s no separate char in Python
  • No switch: Python doesn’t have switch statement and you have to implement it with if, elif blocks
  • While-Else: the loops have the else statement which allows to do something when you go out of the switch
  • Use less lines: Python allows you do simple things in less lines than C++. For example: a = 5 if b == 4 else 6
  • Python allows to write if statement in a single line inside an assignment. It’s not mandatory to use this feature but since you have the chance, why shouldn’t you?
  • Function pointers: in Python there are no control on pointers in general, but since the assignment works on reference, you can do similar things. When you have to use something that works like a function pointer, all you have to do is to declare a variable and assign to a function name (without the brackets) and that’s it. Since everything is a class in Python (even functions) and everything is “callable” when you have to call the function pointer, all you have to do is to call the variable.

 

References:

  • A Byte of Python – Swaroop

 

I define myself as a creative developer.