Wednesday, February 20, 2019

The Features I wish Twitter had

I had a love-hate relationship with Twitter, when i had joined the platform initially. I would quit the platform owing to too much noise and then join it after a while and the cycle continued for a while.

But over time I realized that Twitter is just a tool and how you use it is totally up-to you. It could either be a place with incredible noise or it could be a platform to get information you are interested in, without getting indulged in pointless discussions, useless information or topics.

With that said, here i present the features i wish Twitter had :

Expiring Tweets

Twitter has a recency problem. For example, there could be a viral discussion on a recent issue or the relevancy of the issue / tweet would not be more than a couple of months at a stretch. Some tweets are written for the moment but it survives online for eternity unless one is conscious about deleting the tweets religiously or deletes account permanently. Also, there have been instances where old tweets have been taken out of context and propagated.

If we could set an expiry for a tweet with an hashtag like #6h representing "remove tweet after 6 hours" or #1w representing "remove tweet after a week" for example, it would be great.  The controversial tweets are going to be screenshot and shared anyway, but for most tweets with a recency context this could be useful.

Tweets Archiving

I would love to see an archive option in twitter. Our understanding of the world keeps evolving and sometimes, we end up contradicting our earlier selves. Add to this, tweeting is impulsive too. So imagine, if you would like to begin with a clean slate, you could archive all of your tweets and begin again (so new followers would be oblivious to your past tweets). We could also archive annually if this could be available as an option on the settings menu - e.g., archive tweets every month / year etc. Once the tweets are archived, those tweets should not be visible to the general public.

Public / Private visibility per Tweet

With Twitter, it has been an all or nothing affair. You can either have a private profile - in which case, your tweets aren't visible to the general public (only your private followers can see it) or your profile is public - in which case, everyone could view your tweets. If we could have an option to allow some users (say family or friends) to view private tweets and other tweets for the general consumption of the public, then this would be useful. Some tweets are of the nature of talking to oneself, i literally use my private twitter account for tweeting insights / notes to myself. And some are reactions to others tweets (which implies we wanted to say something to the user - this should ideally be public, but isn't the case if your account is private). And some tweets are good for public consumption.

The judgement about which tweet should be in the public domain and which tweets should be private should be left to the user.  

Sunday, February 17, 2019

Python Basics : Operators

The general purpose of a program is to accept data and perform some operations on the data. The data in the program is stored in variables. The symbol that performs an operation on the data is called an operator.

An operator is a symbol that performs an operation. It acts on some variables called operands. For example, if we write
a + b
the operator '+' is acting on two operands 'a' and 'b'.

If an operator acts on a single variable, its called a unary operator If an operator acts on two variables, it is a binary operator etc. We can further classify operators upon their nature as below :

  • Arithmetic operators
  • Assignment operators
  • Unary minus operators
  • Relational operators
  • Logical operators
  • Boolean operators
  • Bitwise operators
  • Membership operators
  • Identity operators

Arithmetic operators

These operators are used to perform basic arithmetic operations like addition, subtraction, division etc. There are seven arithmetic operators available in Python :
  1. Addition operator ( a + b ) : Adds two values 'a' and 'b'
  2. Subtraction operator ( a - b ) : Subtracts 'b' from 'a'
  3. Multiplication operator ( a * b ) : Multiplies two values 'a' and 'b'
  4. Division operator ( a / b ) : Divides 'a' by 'b'
  5. Modulus operator ( a % b ) : Gives remainder of 'a' by 'b' division
  6. Exponent operator ( a ** b ) : Calculates exponential power value of 'a' to the power 'b'
  7. Integer division ( a // b ) : Performs division of 'a' by 'b' and gives only integer quotient.
Where there is an expression with several arithmetic operators, the order of evaluation is done based upon operator precedence in the order shown below :
  1. Parantheses
  2. Exponentiation
  3. Muliplication, Division, Modulus and Floor Divisions
  4. Addition, Subtraction
  5. Assignment operation
Note 1 : The operators with higher precedence will be executed first than of lower precendence.

Note 2 : When evaluating the expression with operators that have the same operator precedence ( for e.g., Multiplication and Division ), the order of evaluation is done from left to right. This is called Associativity. 

Assignment operators

These operators are useful to evaluate the expression on the right side and assign the value to the left side variable. The below are some variations of the assignment operator :

Assignment operator
z = x + y
Stores right side expression value ( i.e., the value of x+y ) into 'z'

Addition assignment operator
This expression is similar to z = z + x. Adds 'x' to 'z' and stores the value in 'z'.

Subtraction assignment operator
This expression is similar to z = z - x. Subtracts 'x' from 'z' and stores the value in 'z'.

Multiplication assignment operator
This expression is similar to  z = z * x. Multiplies 'x' with 'z' and stores the value in 'z'.

Division assignment operator
This expression is similar to z = z / x. Divides 'z' by 'x' and stores the value in 'z'.

Modulus assignment operator
This expression is similar to z = z % x. Divides 'z' by 'x' and stores the remainder value in 'z'.

Exponentiation assignment operator
This expression is similar to z = z ** x. Performs power value and then stores the result into 'z'.

Floor division assignment operator
This expression is similar to z = z // x. Performs floor division and then stores the result in 'z'.

Unary Minus Operator

 The unary minus operator is denoted by the symbol minus ( - ) and when this operator is used before a variable, its value is negated.

Relational Operators

Relational operators are used to compare two quantities. The below are the relational operators :

  • Greater than operator ( a > b ) : If 'a' is greater than 'b' returns True, else returns False.
  • Greater than or equal operator ( a >= b ) : If 'a' is greater than or equal to 'b' returns True, else returns False. 
  • Less than operator ( a < b ) : If 'a' is less than 'b' returns True, else returns False.
  • Less than or equal operator ( a <= b ) : If 'a' is less than or equal to 'b' returns True, else returns False.
  • Equals operator ( a == b ) : if 'a' equals 'b' returns True, else returns False.
  • Not equals operator ( a != b ) : if 'a' does not equal 'b' returns True, else returns False.
Relational operators are generally used to construct conditions in if statements.

Logical Operators

Logical operators are useful to construct compound conditions. A compound condition is a combination of more than one simple condition. Each of the simple condition is evaluated to True or False and then the decision is taken to know whether the total condition is True or False. In case of logical operators, False indicates and True indicates any other number.

The below are the logical operators :
  • and ( x and y ) : If x is False, x is returned. Else y is returned.
  • or ( x or y ) : If x is False, y is returned. Else x is returned.
  • not ( not x ) : If x is False, it returns True and vice versa.
Note : When 'and' is used, the total condition will become True only if both conditions are True. When using 'or' if any one condition is True, it will take the total compound condition as True.

Boolean Operators

There are two 'bool' type literals and they are True and False. Boolean operators act upon 'bool' type literals and they provide 'bool' type output.

The below are the boolean operators :
  • and ( x and y ) : Boolean and operator
  • or ( x or y ) : Boolean or operator
  • not ( not x ) : Boolean not operator
Note : Here 'x' and 'y' are boolean values i.e. either True or False.

Bitwise Operators

These operators act on individual bits ( 0 and 1 ) of the operands. The results given by these operators are always in the form of integers.

There are six types of bitwise operators :
  • Bitwise Complement operator ( ~ )
    • This operator gives the complement form of a given number. 
    • The complement form is obtained by changing 0's as 1's and vice versa.
  • Bitwise AND operator ( & )
    • This operator performs AND operation on the individual bits of numbers.
    • By multiplying the input bits, we can obtain the output bits.
  • Bitwise OR operator ( | )
    • This operator performs OR operation on the individual bits of numbers.
    • By adding the input bits, we can obtain the output bits.
  • Bitwise XOR operator ( ^ )
    • This operator performs XOR operation on the bits on numbers.
    • When we have odd number of 1's in the input bits, we can get the output bit as 1.
  • Bitwise Left shift operator ( << )
    • This operator shifts the bits of the number towards left a specified number of positions.
    • If we write x << n, the meaning is to shift the bits of x towards left n positions.
  • Bitwise Right shift operator ( >> )
    • This operator shifts the bits of the number towards right a specified number of positions.
    • If we write x >> n, the meaning is to shift the bits of x towards right n positions.
    • Bitwise right shift operator preserves the sign bit, which is the leftmost bit.

Membership Operators

The membership operators are useful to test for membership in a sequence such as strings, lists, tuples or dictionaries. There are two membership operators :
  • in : This operator returns True if an element is found in the specified sequence, else False is returned.
  • not in : This operator returns True if an element is not found in the sequence, else False is returned.

Identity Operators

These operators compare the memory locations of two objects. The memory location of an object can be seen using the id() function. This function returns an integer number, called the identity number that internally represents the memory location of the object. In Python, everything is considered an object. There are two identity operator :

  • is : The 'is' operator is useful to compare whether two objects are same or not by internally comparing the identity number of the objects. If they are same, True is returned. Else, False is returned.
  • is not : The 'is not' operator returns True if the identity numbers of two objects being compared are not same. Else False is returned.

Thursday, February 14, 2019

Python Basics : Introduction and Data Types


Python is a popular, general-purpose high level programming language created by Guido van Rossum and developed by the Python Software Foundation. Python works on different platforms and has a simple syntax similar to english language. Being an interpreted language helps developers in prototyping quickly. It is a flexible language and it can be treated in a procedural, object-oriented or a functional way. Python is easily among the top programming languages according to github language trends.

Data Types in Python

A datatype represents the type of data stored into a variable or memory. The datatypes which are already available in Python language are called Built-in datatypes. The datatypes which can be created by the programmers are called User-defined datatypes.

Built-in datatypes

There are five types of built-in datatypes :

  • None Type
    • In Python, the 'None' datatype represents an object that does not contain any value. 
    • It is used inside a function as a default value of the arguments. Meaning, when calling a function, if no value is passed, then the default value is assumed to be 'None'. 
    • In Boolean expressions, 'None' datatype represents 'False'.
  • Numeric Types
    • The Numeric data type represents numbers and is further classified into the below sub types:
      • int : This datatype represents an integer number. It does not contain any decimal point. In Python, there is no limit for the size of an int datatype.
      • float : The float datatype represents floating point numbers and contains a decimal point.
      • complex : It contains a complex number of the form 'a+bi', where a and b may contain integers or floats.
      • bool : The bool datatype represents boolean values. There are only two boolean values True or False and are internally represented as 1 and 0 respectively.
  • Sequences
    • A sequence represents a group of elements or items.
    • There are six types of sequences in Python :
      • str : In Python, str represents a string datatype. A string is a group of characters.
      • bytes : A byte datatype represents a group of byte numbers just like an array. A byte number is any positive integer from 0 to 255. An important property of byte array is that, we cannot modify or edit any element in the bytes type array. bytes() function is used to convert a list into bytes array.
      • bytearray : The bytearray datatype is similar to bytes datatype except that a bytes type array cannot be modified, whereas a bytearray type array can be modified. bytearray() function is used to convert a list into bytearray datatype.
      • list : A list represents a group of elements just like an array but unlike arrays, lists are capable of storing different types of elements. Lists can also grow dynamically in memory. Lists are represented using square brackets [].
      • tuple : A tuple is like a read-only list. It also contains a group of elements which can be of different type. The elements in a tuple are enclosed in parantheses (). Whereas list elements can be modified, it is not possible to modify the tuple elements.
      • range : The range datatype represents a sequence of numbers and the numbers in the range are not modifiable.  To create a range of numbers we can use the range() function. It is generally used for repeating a loop for a specific number of times.
  • Sets 
    • A set is an unordered collection of elements and the order of the set as entered is not maintained. A set also does not accept duplicate elements. 
    • There are two sub types of sets :
      • set datatype : A set is created by entering the elements separated by commas inside curly braces {}. set() function may also be used to create a set. Since sets are unordered, we cannot retrieve the elements using indexing or slicing operations. The update() method is used to add an element and the remove() method is used to remove a particular element from the set.
      • frozenset datatype : The frozenset datatype is the same as the set datatype except that the elements in a frozenset cannot be modified, hence update() and remove() methods will not work on frozenset datatype. We can create a frozenset by passing a set to frozenset() function.
  • Mappings
    • It represents a group of elements in the form of key value pairs so that when the key is given, we can retrieve the value associated with it. The key value pairs should be separated by a colon (:) and every pair should be separated by a comma (,) and enclosed inside curly brackets {}.
    • We can retrieve the value upon giving the key. For e.g., dict_name[key].
    • We can use keys() and values() method to retrieve only keys and values respectively.
    • We can use the del module to delete a key and the corresponding value. For e.g., del dict_name[key]
Literals in Python

A literal is a constant value that is stored into a variable in a program. In an assignment operation, like
'a' is the variable into which the constant value '10' is stored. The value '10' is the 'literal' here. Since 10 indicates an integer value, it is called an 'integer literal'.

The following types of literals are there in Python :

  • Numeric literals
    • These literals represent numbers. The different types of numeric literals available in Python are Integer, Float, Hexadecimal, Octal, Binary and Complex.
  • Boolean literals
    • Boolean literals are the True and False values stored into a bool type variable.
  • String literals
    • A group of characters is called a string literal and these literals are enclosed in single quotes (') or double quotes (") or triple quotes (''' or """). In Python, there is no difference between a single and double quoted string.
User defined datatype

The datatypes which are created by the programmers are called 'user-defined' datatypes like array, class or modules.


A constant is similar to a variable but its value cannot be modified in the course of program execution. In languages like C and Java, defining constants is possible, however, its not possible in Python. We can indicate that a variable is a constant by writing its name in all capital letters, but its value can be modified.

Identifiers and Reserved words

An identifier is a name that is given to a variable or function or class and it can include letters, numbers and underscore character (_). Identifiers should always start with a non-numeric character. Python is a case sensitive programming language and hence identifiers with the same name but different case sensitivity are treated as separate by Python.

Reserved words are the words that are already reserved for some particular purpose in Python language. Examples include and, del, in, continue etc.


  • To determine the datatype of a variable or object, we can use the type() function. 
  • Every datatype is treated as an object internally by Python. Every datatype, function, method, class, module, lists, sets, etc are all objects in Python.
  • Python does not have a char datatype to represent individual characters, unlike in programming languages like C or Java. To access individual characters in a string, we have to use the index or the position number.

Wednesday, February 13, 2019

Better SMS : Ideas for the default Messaging App

I see this pattern often repeated across different OS platforms. The negligence of their core / built-in default apps.

On Android the problems are twofold : On the one hand, there is the menace of pre-installed and useless apps, and on the other, the negligence of some of the useful pre-installed apps like the SMS app with no useful features added to the app since ages.

There are many useful third party alternatives to the SMS app. But i was wondering why, when there are so many different ideas implemented in third party alternatives, is the default messaging app being neglected instead of adding useful features to the app ?

So i would like to propose a better (default) sms app, with the below feature set :

  • SMS Auto-sorting
    • Messages should be categorized automatically using learning algorithms into various categories such as Finance, Notifications, Offers, Miscellaneous, Personal etc
    • This kind of organizing is done neatly in the SMS Organizer app from Microsoft Garage. But i don't understand why this isn't the norm yet.
  • SMS Reminder Functionality
    • Like it or not, SMSes are the default notification method for payment of your dues, taxes etc. And these SMSes typically come in a format with an end date (e.g., pay by xx-yy-zz date etc). 
    • It would be a good addition to notify the user with reminders of pending dues to pay on time.
  • SMS Auto-clean
    • As time passes, we accumulate a lot of junk messages which either we have dismissed or opened and not action'ed upon etc. So we could typically set a junk folder auto-deletion mechanism. For example, messages categorized as Miscellaneous, can be auto-deleted post 60 days (this is one of the examples where clearing up SMSes can be done confidently).
These three features would super charge the experience of the default SMS app. 

If you are a OnePlus phone user, I have submitted this idea as part of the OnePlus PM Challenge and you could upvote the idea if you like, here : #PMChallenge.

Monday, February 11, 2019

Response to "The Psychological Trap of Freelancing" article

This is a response to the article titled "The Psychological Trap of Freelancing".

But once I started freelancing, things changed. I became hyperconscious of how much money I could (or should) charge for my time, and this made me unhappy and mean when my nonworking hours didn’t measure up to the same value.

In a typical salaried job, the pay is similar (if not same) for people working at the same position regardless of the quality of work output. If we had a choice and the system allowed it, we would seek a better raise and a better paycheck than the colleague who is all talk and no show. (That colleague who is good at maintaining a relationship with the manager than doing his job well.) Perceived value is so much more important than credentials in a typical job. In Freelancing, at least you have the autonomy to choose how much you get paid, what to work on and when.

New research explains the psychology behind my state of mind: People who attach dollar signs to their time — or “value time like money” — tend to be overwhelmingly less happy than those who don’t, because their nonworking hours suddenly seem less important. “Free” time gets tainted with guilt because there’s a cost associated with it.

On the contrary, your salaried job is likely to eat into your personal life and not pay you for it. This all happens in the name of "proactiveness", "go-getter attitude" etc How many times have you stretched at office to meet an arbitrary deadline ? I don't think a salaried job is better in the sense of time. [ side note : I wish more companies took up dateless delivery model. ]

Many Americans fall into this trap. A 2016 study found that 63 percent of respondents valued money over time, while the smaller percentage of people who valued time over money reported greater well-being than the larger group.

Much of American thinking is rooted in the "Time is money" quote by Benjamin Franklin which is pretty much an incorrect way of thinking about money in the first place. I sometimes wonder if that quote was taken out of context and propagated widely. Because time is always more valuable than money. Time is limited, and the worst part (or better ?) is that we don't know how much of time is left.

 “If we’re already in the time-is-money mindset, we can reframe our leisure time as something that enables us to be more productive in the future,”

This is a poor way to look at time off in my opinion. Just like you would like to work, you would also like to be away from work. Both are fundamental needs and balance each other out. If we reframe time off as something that will help us become more productive and hence we are redefining the motivation behind time off, then well we are still stuck on the "work" frame even while we are on "time away from work" frame. Though you are away from work, you are still pretty much part of the work. It's an irony to think of time off as something needed to be better at work. The motivation doesn't seem to align.

Most of what the author stated may be correct, but only when you "value time like money". If you value autonomy over your work, freelancing seems like a better option. You have better control over your time.

Disclosure : I don't freelance yet. But these points were just popping out to me as i have seen the not-so-great parts of being a salaried employee.