Wöchentliche Trends aus Nahost #2 : Abo Trika, Ukraine

Die Entscheidung des Verbots der russischen Vereine und Nationalmannschaft von allem Wettbewerbe muss mit dem gleichen Verbot gegen die zionistisch  Vereine und Nationalmannschaft, weil Zionismus Angreifer ist ، und hat Frauen und Kinder seit vielen Jahren umbracht, aber ihr mit zweierlei Maß messen.

On Russia, Ukraine, the Middle east and the odds of success

Consider the random variable X which represents the likelihood of someone achieving success in his life, and the population S of all the people that you can see daily on your way to work, those who are waking up early, doing their best for at least 8 hours per day. They are ordinary people, dedicating their lives to their families and jobs. Assuming that these humans work equally hard, do they all have a level playing field?

What is success? Let me for the sake of simplicity in this article define it only using measurable dimensions ( such as your bank account, fame, impact on people, or your title in the job). In my view, success is more complicated than that and there are additional dimensions to it. I wouldn’t even use the word success as a life goal rather the feeling of content, which is different. We can see rich people who are not content with their life, while others who live by the most modest means are totally happy and satisfied, but this could be a discussion for another post.

The base case

In the following diagram, the blue curve depicts a romantic view of success, everyone has an equal chance of achieving in life as long as they exert adequate efforts and try as hard as they can. While the red distribution draws a more realistic view of life (at least in my opinion) where most people will achieve a moderate level of success, few of them will catastrophically fail and another small group of outliers will build the likes of Google, Tesla, and Microsoft or start a movement that impacts the lives of millions like Gandhi or Martin Luther King.

Chances of Success = C * Working Hard

Realistic vs Romantic Views

Chances of Success = (C * Working Hard) + (B * Upbringing and cultural context) + (A * Random factors)
where B >>> C >>> A

In his book “the outliers”, Malcolm Gladwell, inspired by research, presents multiple theses, a prominent one that can be depicted by the red curve is that: Hard work is only a factor in achieving extraordinary success in life, other factors play a great role too, such as upbringing, timing, cultural heritage …etc. It’s not enough to work hard and play fair in life to receive equal chances. The odds are not in favor of most people, only a few outliers have high chances of success.

And for the average person, the second variable “Upbringing and cultural context” in the equation above plays a greater role, hence, B would be greater than C and A. An example would be the difference in the life of a Korean born on the south or the north of a border between both countries.

A few videos went viral in the last weeks for news reporters who were covering the invasion of Russian forces of the peaceful Ukrainian cities. One of the reporters was truly shocked to the extent that although he tried to choose his words very carefully, he couldn’t hide how his mind compared the destruction of a relatively civilized European city (an unlikely event to him) to Iraq or Afghanistan where this is the (accepted) norm to see bombings, destruction, and dead bodies of women and children

“But this isn’t a place, with all due respect, like Iraq or Afghanistan, that has seen conflict raging for decades,” CBS News Reporter commented. “You know, this is a relatively civilized, relatively European – I have to choose those words carefully, too – a city where you wouldn’t expect that or hope that it’s going to happen.

And here I am not trying to play the racism card, but I rather consider this as a piece of evidence to support the main thesis. Unfortunately, it’s indeed more likely to see destruction in Baghdad than in Kyiv for example (at least in the last 2 decades), this is simply and sadly how it is. Therefore, the probability of achieving success is much higher if you are born in one of these (civilized) cities (If I would use the reporter terms).

Changing your odds

The green bell curve depicts changing of odds as observed in shifting of the population mean.

Now, the question would be how someone can adjust the odds of achievement in life. Considering the equation above, if we omit possibilities like winning a lottery or inheriting a wealthy distant relative, then the only possible factor under control is hard work. Imagine there is another smaller population group Y who still follow the general logic of the success equation, but they push their odds further by investing more time and effort. Is it enough? No, not really. The other parts of the equation will still play a key role, however, this is the best shot that we got.

I will conclude this blog post by leaving here two contradicting research articles: Ericsson’s research about the role of deliberate practice in achieving expert performance who concluded a strong correspondence between practice and expertise (which is more known to the public as the 10,000 hours rule), and Macnamara’s revisiting the same study to conclude otherwise.

In my opinion: practice makes perfect, or strictly speaking, practice increases the chances of perfection.

Wöchentlich Trends aus Nahost #1: Ryan

Eine Zeichnung aus Tebessa, eine algerische Provinz, von dem verstorben Kind: Ryan

ريان: الحزن يخيم على مواقع التواصل الاجتماعي بعد وفاة الطفل المغربي

Ryan : Trauer auf die sozial Medien nach dem Tod des marokkanischen Kindes.

تحولت مواقع التواصل الاجتماعي إلى دفتر عزاء مفتوح، بعد وفاة الطفل المغربي ريان الذي أثارت قصته المأساوية اهتمام الكثيرين في العالم العربي ودول أخرى.

Die sozial Medien Seiten hat sich in ein Kondolenzbuch verwandelt, nachdem Ryan gestorben ist , der für seine Geschichte vielen in der araber Welt und andere Länder sich interessiert habe

ووسط فرحة لم تكتمل، تمكنت فرق الإنقاذ المغربية، مساء أمس السبت، من الوصول إلى عمق البئر التي ظل ريان عالقا فيها خمسة أيام.

Inmitten einer unerfüllten Freude , konnte die marokkanische Rettungsteams am Samstag Abend , zu Brunnen tief erreichen, die ryan hat für 5 Tagen geblieben

عن الوقف الخيري لجامعة يال

Yale Endowment Fund

من الأخبار المهمة اللي شدت انتباهي مؤخرا حدوث نمو خرافي للفاند التابع لجامعة يال بنسبة ٤٠٪ من ٣١ مليار إلى قيمة أصول تتجاوز ال ٤٢ مليار.

الترجمة الحرفية للكلمة هي صندوق الهبات و لكن المعنى الأقرب و الأدق في وجهة نظري هو الوقف الخيري. أثار انتباهي إنه وقف خيري يحقق عائد خرافي يتخطى عتاولة أسواق المال و البنوك الاستثمارية الكبرى و تساءلت عن السر ورا الموضوع .

معظم الجامعات الكبرى في الولايات المتحدة و العالم بدأت عن طريق وقف خيري، و الأوقاف دي قيمة أصولها تصل لعشرات المليارات و تدر عائدات سنوية ضخمة بتمثل مصدر أساسي من مصادر الدخل للجامعة اللي بتقدر من خلالها تمول مرتبات الأساتذة و منح الطلبة و الأبحاث العلمية في الجامعة.

على اليمين نقدر نشوف نسبة الدخل من عوائد الوقف بالنسبة لدخل الجامعة الكلي و على اليسار المجالات المختلفة اللي بتتمول من عوائد الوقف.
المصدر : التقرير السنوي لوقف جامعة Yale عام ٢٠٢٠
جدول لقيمة أوقاف جامعات أمريكية بترتيب قيمة الأصول لعام ٢٠٢٠. المصدر: ويكيبيديا

في المنطقة العربية يعتبر وقف جامعة الملك عبد الله هو الأضخم على الأطلاق بقيمة أصول تصل إلى ٢٠ مليار دولار. الجامعة كانت مشروع طموح أسنده الملك عبد الله لعملاق الهندسة ارامكو و خصص له وقف عشان التعليم يكون بدون مصروفات. بالإضافة إلى ذلك تتمتع الجامعة بوضع خاص لأنها لا تخضع لسلطة وزارة التعليم العالي في السعودية و لا الهيئات الدينية و بالتالي مسموح فيها بالاختلاط و بتستقبل طلبات تقديم من جميع أنحاء العالم.

نرجع لموضوعنا الأصلي و هو جامعة يال و الوقف الخيري التابع لها اللى نما من ٥٠٠ باوند في القرن ال ١٨ إلى أن وصل لقيمة ٤٠ مليار دولار في ٢٠٢١. وقف جامعة يال اشتهر باستثماراته في مجالات غير تقليدية لأنه ما اكتفاش بالودائع النقدية و الأصول العقارية لكنه توسع في الاستثمار في الأسهم و الشركات الناشئة زي أمازون و جوجل و غيرها. بالإضافة لذلك إدارة الوقف بتستثمر في الأصول البديلة الإستثمارات البديلة غير المطروحة في أسواق المال تطبيقا لنظرية إن الاستثمارات دي بيكون تسعيرها أقل كفاءة من الأصول التانية المطروحة في الأسواق العمومية و بالتالي فرص المكسب الكبير بتكون أعلى.

توزيع استثمارات وقف Yale في أنواع أصول مختلفة. المصدر : النشرة الصحفية السنوية للوقف

بفضل السياسات الإستثمارية الناجحة قدر يحقق الوقف متوسط عائد في آخر ١٠ سنين يتخطى ١١٪ و هو أداء ممتاز ممكن مقارنته بصناديق و بنوك الاستثمار العملاقة.

تضاعف حجم أصول الوقف ٣ مرات في آخر ١٠ أعوام. المصدر : التقرير السنوي لوقف جامعة يال عام ٢٠٢٠

و ختاماً أتمنى في مصر و الوطن العربي نولى اهتمام أكبر لوزارة الأوقاف أو نلغيها تماما و ننقل أصولها لإدارات محترفة غير هادفة للربح تهدف إلى تنمية الأصول و تعزيز الإستفادة بيها لطبقات مختلفة من الشعب و في مجالات مختلفة زي الصحة و التعليم و القضاء على العشوائيات. و من الممكن إن المشروعات الخيرية الكبرى اللي بتجمع مليارات في مصر تكون إدارتها بنفس الطريقة و بدرجة شفافية تتيح لعامة الشعب متابعة إيرادات و مصروفات الأوقاف دي. شخصيا ب أحس بالغيرة من شبكة السرطان المصرية اللي لها دور كبير في تمويل مشروع ٥٧٣٧٥ و أتمنى المصريين في ألمانيا يقوموا بمشروع مماثل بنظام الوقف الخيري.

عن القومية و جروباتها

زرت متحف في برلين بيتكلم عن تاريخ ألمانيا النازية و كان في معروضات كتيرة زي أعلام الفترة دي و ملابس وحدات مختلفة في الجيش الألماني و ملصقات دعاية للحزب النازي لكن الحقيقة أكتر معروض شد انتباهي كان كتيب حكومي بيُستخدم في فرز و تصنيف الألمان أو الجنس الآري تحديدا عن الأجناس الأخرى عن طريق مواصفات جسدية محددة زي الطول و شكل الوجه و لون الشعر و العينين و على سبيل المثال العينين بالتحديد كان ليهم ليستة محددة من درجات الألوان اللي لو اتولدت ب درجة مختلفة عنهم هتتصنف تصنيف مختلف عن باقي الشعب.
لو حد تخيل إن الكلام ده بعيد عننا أو تخطاه الزمن ف هو مخطىء تماما و ده للأسف ظاهر في ممارسات و تعليقات باشوفها يوميا في جروبات جديدة بتنتشر في مصر تحت شعار (القومية) لدرجة أني حاسس إنه ناقص نعمل اختبار الحمض النووي للناس اللي جوة الجروب. الأمة المصرية أكبر من كدة بكتير و تاريخها ممتد بدأها المصري القديم و صانع حداثتها كان ألباني و قائد جيوشها اللي رد الصليبيين كان كردي ، و في فترة مش بعيدة كان عايش فيها الخواجة الإيطالي اليوناني مع المصري المسلم و المسيحي و اليهودي.

و الحدوتة السخيفة بقيت بتكرر كالآتي ، بنختار ضحية تنطبق عليها نمط معين مفيش تعاطف كبير معاه، بعدها نبدأ عليه حرب إلكترونية، سواء شماتة أو شتيمة، أو اللي بنقدر عليه من سلوك القطيع بحيث إننا نصدم الشخص ده أو دي بموجة كراهية ننام بعدها مرتاحين و نحس أننا خدمنا البلد.
السؤال اللي باسأله لنفسي و أتمنى الناس تسأله لنفسها هل الهجوم ده بيحقق أي هدف إيجابي ؟ و هل هو ده الطريقة الصحيحة عشان نقدر ننشر الفكر القومي ؟ و لا مجرد تفريغ لشحنات غضب ؟
هل الحكومة هتسمع رأي الناس المتضايقين من تدفق اللاجئين غير المنظم بالطريقة دي؟ طيب هي جماعات الإسلام السياسي هنحاربها بالضحك؟
أسئلة كتيرة بتشككني في قيمة الجروبات القومية اللي كنت متخيل في البداية إنها هتكون مصد سياسي و فكري قوي ضد الإسلام السياسي لكن يبدو إنه الموضوع بشكله الحالي مش هيروح بعيد .

و في الختام شخصيا بالنسبة لي أي حد بيحب مصر و بيحترم ناسها و قوانينها و بيعشق تاريخها و تراثها هو مصري زيه زيي ، أنتم المصري بالنسبة لكم مين ؟

عن سد النهضة

اسمحولي اخرج عن السياق الحالي و اﻷجواء الرمضانية و أزمة #الكورونا و أعيد نشر ملف عن نهر #النيل و #سد_النهضة كانت أعدته الجزيرة في واحدة من حسناتها القليلة جدا بالتزامن مع اعلان اثيوبيا أنها هتبدأ هتملى السد في شهر يوليو.


للأسف السيناريو المطروح حالياً لملأ السد في خلال ٣ سنوات هو الأقصى ضرراً بالمقابل الطرح الأصلي المفاوض المصري كان إتمام الملأ في ١٥ سنة. تقدير الأضرار مختلف لكن من المؤكد أنه هيكون في تأثير كبير على ملايين المزارعين و الأراضي الزراعية و نصيب مصر من المياة.

الرأي العام في اثيوبيا يبدو أنه متوحد بالنظر إلى وسائل التواصل الإجتماعي ده غير إن السد تم تمويله شعبيا من خلال سندات حكومية و بالتالي المواطن الإثيوبي مستثمر بماله الشخصي في بناء السد بينما على الجانب الآخر المصريين بين حالة انقسام أو لا مبالاة.

لو السد بدأ يتملي في يوليو الخيارات اللي قدام الحكومة المصرية هتكون محدودة جداً بين خيارين لا تالت لهم توجيه ضربة عسكرية أو الرضا بالأمر الواقع و اتخاذ إجراءات تانية لمواجهة الإنخفاض اللي هيحصل في منسوب نهر #النيل

خليني أعمل نشر لملف اخر أعدته صحيفة النيويورك تايمز عن نفس اﻷزمة

بقالنا سنة للأسف من البوست ده و الوضع أصبح أسوأ

مقالة أنا كاتبها على مدونتي الشخصية من ٧ سنوات وقت ما كان #سد_النهضة في مرحلة الإنشاء بنسبة ٣٠٪ فقط و كنت عامل حسبة بسيطة إن لو السد اتملى في ٥ سنوات هنخسر ٢٥٪ من نصيبنا المياة السنوي و دي هتكون كارثة بكل المقاييس و تشريد أسر كتير و خسارة فدادين أراضي زراعية لا تعوض

و مازالت الأزمة للأسف مستمرة و كل الحلول الدبلوماسية ( حتى الآن) ما حققتش أي تقدم في أزمة #سد_النهضة_الإثيوبي

رابط المقالة عن #GERD من ٢٠١٤

Originally tweeted by Ahmed abdelfattah (@aabfattah) on May 12, 2020.

My talk about virtualization in automotive on the E-OnTech#7 event

I have just decided to post a link to the talk I made on last November hoping maybe to boost the number of views which is currently below 100 (most of them are family and friends 🙂 ) to maybe 101 or 102. I am also including the slides which are not linked in the original video.

Full talk on youtube

The Traveler Guide to Shanghai

Are you staying in Shanghai for a while? Wondering about what to eat and trying to Google it out? To be honest, you will probably get much better results if you know some Chinese using Baidu search. If not, then you are stuck with me here in this blog but I will be try to be as helpful as possible.

I would like to begin with the fact that I liked Shanghai a lot. It’s really a clean, organized , has an amazing public transportation network and plenty of food places. If you are not really into Asian then you still have plenty of international options. Many people can speak English or at least a few words, the rest usually is smart enough to understand what I want using some body language.

This guide is intended to pass over my experience to people who are intending to stay in Shanghai for a couple of months or more. It’s not targeting tourists but it could help anyway.

Essential Mobile Apps

I think before everything it’s essential to prepare some apps on your mobile, otherwise it would be more difficult to survive even when some of these apps are completely in Chinese they will still prove to be useful in some situations.


WeChat  [English/Chinese]

I would say WeChat is the most important app in China, it’s much more than chat, it’s like a combination of WhatsApp, Facebook, Apple Pay and it’s also used in business frequently. For the Chinese people it’s pretty normal that your co-worker or boss asks for your WeChat id to call you for work purposes or even pass you business information through it and expects the same from you, additionally all your new Chinese friends will be on WeChat and you don’t want to miss that and on top of all that you can use it to pay nearly anywhere even at the small fruit shop around the corner.

Alipay logo

Alipay [English/Chinese]

It’s the same here, it’s just not your standard mobile payments application. Maybe because Chinese like to have many functionalities on a single platform. Some additional features that I used on Alipay:

  • Paying utilities bills: Basically you need to enter your subscription number which should be written on the bill (a friend can help you to locate it) and you will be able to pay your bills with one click. Extremely efficient.
  • Renting a bike: The usual drill, scan, unlock and pay.
  • Top up: for Chinese mobile phone numbers.
  • There are more features like booking trains, flights or even movie tickets but I didn’t really explore them.

This leads us to a crucial point which is how to activate the mobile payment feature on Alipay or WeChat? From my experience your normal credit or debit card won’t really work but adding a Chinese debit card should be straight forward. However, you need of course to open a bank account which should take a couple of hours depending on your visa type. If you have a long stay visa it should be possible but if you are on a category M visa only 2 banks as far as I know might agree to open an account for you: Eventbrite and Shanghai bank. You will also need a letter from the Chinese entity that you are working with them locally.


Google, Facebook, WhatsApp. Youtube .. and many other western world services are blocked or very slow therefore you will probably need a paid VPN service to be really able to use these services reliably (to contact your family for example). And don’t forget to figure out this before landing in the airport, once you are in China it will be a very difficult job to obtain a VPN solution.

I tested around 4-5 solutions and concluded that the most reliable ones are:

  • Ladder VPN; Cheap, mobile only, speed is ok.
  • Express VPN: Expensive, mobile and PC, speed is very good, however it’s popular and probably known to the Chinese government so it’s possible that it gets blocked for a few hours/days then returns back up.

I would recommend that you have at least 2 solutions. If you are on a work assignment then probably your company’s VPN should be a feasible resort.


Amap  [Chinese]

Google maps are not really helpful in China, they don’t have a lot of data. And won’t help you in finding the correct transportation. On the other hand Amap has accurate maps with extensive details. There are two tricks to use it if you don’t know any Chinese:

  • Try to search with English names or addresses, it will mostly work.
  • If you know a close metro station to where you are going you can also type it in English. This will definitely work.

Now, you were able to locate where are you going and have all the alternative routes listed on the app screen but unfortunately everything is in Chinese. There will be no problem reading the metro/bus line number and the poor man solution to read the destination station name (or at least what I used to do) is to look into the map in the station before you hop into the carriage and try to compare the Chinese text character by character, it might sound weird but it will eventually work because inside the metro station there are alternate English/Chinese texts on every sign. It’s really clear once you get used to it but you might to need to do this matching a few times in the beginning.


If you are willing to travel, this website will help you to book train and flight tickets. It has also a wider selection of hotels in China compared to Booking.

A tip regarding purchased train tickets through the app: You will need to give yourself some lead time to go to the ticket office before your trip to get printed tickets.

Microsoft Translator  [English]

This one saved me a lot. If at some point you need to say or understand more than your usual little dictionary of Chinese words then this app will definitely come in handy. The most useful feature is the voice translation mode where it splits the screen into 2 halves, the first half has a mic icon that listens to Chinese and translates to English while the icon on the second screen half does the inverse. It works well on most of the cases and was really useful on many situations.

Didi  [English]

Equivalent to Uber

Note: It’s not on the play store.


Ele.me [Chinese]

Food delivery is very popular here, you will find motor bikes rushing everywhere on the streets to deliver food somewhere. It’s also in Chinese but you can search in English for some kinds of food like pizza or burger and select food based on the pictures, making the order and paying via AliPay or WeChat shouldn’t be a problem. An important hint is that you need when setting up the app some help from your Chinese friend to type in your address very accurately in Chinese. When the driver arrives you will get a call from him and because you don’t know any Chinese and he won’t probably know any English you better show up quickly at your doorstep or in front of the building to receive your food.

Youku [Chinese]

It’s the YouTube + Netflix + Sports streaming of China. There are some free movies but the latest ones will be watch-on-demand. You can buy a ticket for a movie by scanning a code using AliPay or WeChat. It also has very nice sport content as I was able to watch some free premier league matches, the important matches are watch-on-demand though.


China is in my opinion at a point beyond the cashless society, mobile payments are dominant nearly everywhere. If you were able to activate any of WeChat or AliPay wallets then you are already in a very good position, however cash of course still works.

I don’t recommend exchanging money in the airport except maybe a very little amount for the taxi. (beware of scams and don’t go with anyone, just outside the airport you will find an organized line of metered cabs with well-defined tariffs and will also give you an invoice)

Back to our topic about obtaining Yuans or RMBs (the 2 names are equivalent but the later is used more) it really depends on where do you come from and how much fees your bank will charge you. MasterCard and VISA cards should work normally and there are many ATMs everywhere but maybe not all of them will work with your particular card so you need to try different banks. All ATMs I used supported English and Chinese. In my case my I could use my MasterCard to withdraw RMBs from my Euro account at the market rate with a 1.7% fee. Your bank may give you a better or worse deal. I would then take the cash and deposit it into my Chinese bank account. In China the ATMs that support depositing money are called CDSs.


Enjoy trying all sort of Chinese local recipes especially the roasted duck but if you are longing for something that you would find home, there are many alternatives.

  • Pizzahut, McDonald’s, KFC and all your lovely junk food is available nearly around each corner. I have seen more KFCs than any city I have been to.
  • The Habit Burger and Grill: Very good burgers and a great variety of tasty salads (Grilled chicken salad, Cesar salad, chicken BBQ Salad). I have eaten too much salads from this place to the extent that most of the staff recognizes me when I enter the place.
  • The blue frog bar and grill: Steaks and burgers
  • Eli Falafel (Halal): Lebanese, near People’s square, it’s on Google maps
  • Brothers Kebab (Halal): Shawrama and Koshari, many branches around the city.
  • City Center Super market: The concept of a large super market isn’t prominent here, instead there are small shops everywhere. This was the only place that actually looked like a conventional super market. It has many branches and recognizable food brands but they are overpriced because this place isn’t targeting the ordinary Chinese.

    Crazy prices for diary products.
  • Carefourr Easy Market: there are plenty of branches around the city with various sizes.


I have already blabbed a lot about the metro. It’s really clean, clear, convenient,  inexpensive (3 RMBs for a short trip, more for longer) and almost covers the whole city. I would suggest that you buy the metro card, charge it from the vending machines (have English support) instead of buying a ticket each time. There is also a mobile version but I just used the card. The electronic gate will show you your current credit at entry and credit after deduction at exit.

Buses are also OK and extremely cheap (1 RMB) but you need to have a better Chinese because unlike the metro there are no English signs.

You can use the same card for public Ferris crossing the bund and also the maglev train to the airport. (a one way ticket costs 50 RMBs)

Moving your legs

View from Jin Mao building, 88th floor observation deck. 

Sadly there isn’t a lot of green areas in the city. It needs really a big park to allow people to breathe some fresh air. Still there are a couple of places to move your legs. If you are in a shopping mode walk the Nanjing pedestrian street near the people’s square, it’s very vibrant and has a lot of shops. Yuyuan market is also very nice.

Yuyuan market.


There are tons of malls with all the well known western brands, consumerism at its best here.

My favorite walk was over the bund and in the financial district (near the fork tower). There are 2 sides of the bund, one is not very clean and usually crowded but If you took the ferry to the other side (only for 1 RMB) there is a much better walking lane for pedestrians and cyclists. There is a couple of good restaurants by the river too.

Walking the bund.


Huxi mosque from inside.

If you type in the word mosque into the Amap app you will basically find 3 main mosques in Shanghai. I only went to Huxi mosque near Changshou Road station on line 13 for Friday prayers. The prayer speech is mostly in Chinese with few Arabic sections. It’s very clean and well maintained and there is a halal meat shop just beside this mosque if you are planning to cook.

If you are not a Muslim I would still highly recommend to visit the street food market there. It’s open every Friday. There are plenty of delicious kebabs, skewers, sweets and fruits. Really cool.


That’s all. I hope that you enjoy your trip to China and explore more cities.


Relating C++ move semantics to python objects

I have been learning lately about C++11 move semantics, originally being a C programmer who is concerned with the performance it was very interesting to explore such an important optimization feature. I had to go through many articles explaining rvalues, lvalues and the && operator. I believe you still need to learn these topics to develop a firm understanding of the topic but in my point of view the move semantics can be explained intuitively by drawing the similarity between it and python’s object execution model.

The goal of move semantics is to avoid copying large objects unnecessarily when they are passed from one function to another.

How are objects passed in python?

Interestingly enough, python was created with that particular optimization in mind.

Firstly, It’s important to understand the subtle difference between the interpretation of the following statement in python and C++

str = 'medium'

view raw


hosted with ❤ by GitHub

In C++ the variable str is created in memory, this location in memory contains the data medium and str refers to this memory location.

However in python the story is different. Although this statement also creates an object with the same content, but str isn’t the object reference. str is a merely a name and the statement binds it to the object. This subtle deviation may not look crucial but it makes all the difference when passing arguments to a function.

Consider the following 2 code snippets

def modify(arg):
arg = 'hard'
str = 'medium'
print(str) # >> medium

In the first snippet, an immutable object is created containing the data ‘medium’ and str is bound to this object. When the method modify is called a new name arg is also bound to ‘medium’, but as soon as line 2 is executed the binding of arg is relocated to another new object with the data ‘hard’ because there is no way to change an immutable. The resulting behavior appears as a conventional pass by value call.

def modify(arg):
arg += [1]
l = [2]
print(l) # >> [2, 1]

view raw


hosted with ❤ by GitHub

On the other hand, the behavior depicted in the second snippet resembles a pass by reference call as modify here doesn’t rebind arg to a new object because this object is mutable. arg and l are two names bound to the same object. When line 2 is executed this object is modified.

In python object references are passed by value, in other words objects are moved.

C++ move semantics in layman terms

Before the move semantics there were a couple of ways to avoid unnecessary large copies by passing pointers around which is somehow considered an unsafe practice compared to use an instantiated object which auto destructs.

Move semantics are based on rvalue references. An rvalue appears on the right hand side of the assignment statement. Example of an rvalue could be “medium” here:

string str = "medium";

view raw


hosted with ❤ by GitHub

Also the function getName() can return an rvalue because it appears on the right side of the statement.

string getName() {
string str = "medium";
return s;
// getName() returns an rvalue
string&& name = getName();

view raw


hosted with ❤ by GitHub

name is an rvalue reference.

I like to think of an rvalue as a python object and the rvalue reference as the name bound to this object. The difference being that an rvalue can’t exist on its own while python relies on garbage collection to clean up objects which are no longer bound to any scope.

class Obj {
//default constructor
Obj(int size){
//copy constructor
Obj(const Obj& other){
//assignment operator
Obj& operator= (const Obj& other){
Obj B;
B = Obj(1000);

view raw


hosted with ❤ by GitHub

Without a move constructor the last line assignment will

  • allocate memory for the temporary object (and destruct it later)
  • allocate memory again at the destination

Adding a move constructor to the object definition will optimize out the second allocation and reuse the previous allocation for the destination.

class Obj {
//move constructor
Obj(const Obj&& other){
//move assignment operator
Obj& operator= (const Obj&& other){

view raw


hosted with ❤ by GitHub


Having this analogy in head, comprehending the power of move semantics was no more complicated. When a move constructor is defined for an object, it will be possible to rebind it to different name while avoiding expensive copies.







It Begins ..

I have been aspiring to improve my writing skills and vocabulary since a while ago but never really took any steps towards this goal. I think if you need to achieve something you need to do it , so I will define a goal for myself to write a biweekly 250 words essay.

This means by the end of this year I should have published 14 short articles (not counting this one)

A simple structure will suffice for a 250 words essay , it will be composed of :

  • Interesting Introduction
  • Body
  • Conclusion

And a simple methodology will do too

  • Choose a topic
  • Research
  • Write ( Learn some new vocabulary in the process)
  • Proof read
  • Publish !

Having defined a SMART objective and a lucid approach to accomplish it , see you after 2 weeks then !