HOME | Blog | YouTube | LinkedIn | About Me         || Calculators    | SoftEng/Tech Posts    | Code/Scripts

Saturday, January 21, 2017

Use of var in C# -- We need to have some discipline

As C# language evolves, programmers need to have the discipline and keep the code as elegant as possible. Some new capabilities with "var" declaration could make the code less readable if you don't follow simple guidelines.

Here are a few examples with comments showing what is good and what is bad practice:


var customerInfo = RetrieveCustomerInfo(customerId);  // Bad, not readable
CustomerInfo customerInfo = RetrieveCustomerInfo(customerId);  //Good


var settings = GetInboxSettings();      // Bad, not readable
InboxSettings settings = GetInboxSettings();   // Good


Dictionary<string, List<string>> myDictionary = new Dictionary<string, List<string>>();   // redundant
var myDictionary = new Dictionary<string, List<string>>();    // OK



Almir M.

#Csharp #DotNet #programming #code #coding #SoftwareDevelopment #SoftwareEngineering 


Thursday, January 19, 2017

Generate a random word in Python

In order to keep uniqueness of records in some of your tests, you may have a need to generate a random word (alpha ONLY). Here is a Python function to achieve this:


For example, I am using this to randomize first and last name in the JSON block before I pass this JSON as payload to an API that tests Customers microservice.  


Almir M. 

Friday, January 13, 2017

Delivering on time — it is a skill of knowing when to slow down

Delivering projects / initiatives on time is a skill of knowing when to step on the brakes, slow down, and clean up things and make it production worthy.
If you are sprinting trying to get more feature squeezed in all the way until the finish line, then you don’t have time to slow down, polish up things and launch; oops, you just ran over the line.
Yes, if you slow down, you will deliver fewer features, but you WILL deliver a defined business value on time. What is an alternative?
My above statements obviously have different meanings within the waterfall vs. agile development methodologies, but the overall essence is the same.
Almir M.

Monday, January 2, 2017

Python Modules - Simple Example

I have written a lot of Python code in last year or so, but I realized that I have not been doing the modules and the import of modules properly. I have been concentrating mostly on the logic of my applications and I have ignored the distribution part of the modules and these applications. Yes, my applications have been mostly POCs for my team and some tools, but these still deserve to be implemented to enterprise standards.

There is a lot of material on internet about Python modules, but it takes time to conclude what the simplest way is. I spend last few days doing some research and trying out things until I arrived at something simple and what I believe could be used at the enterprise level.

I am in the process of learning this and I decided to document it for others with very simple examples that you can download and try yourself.

Click HERE to download the code from my Google Drive.

Below are the screenshots of the code structure. You will see that there are two modules that are bundled under one module_util:

  • util_general
  • util_math

To make the example more realistic, the util_math module using code from util_general module. 

The code in main.py shows you you can properly import the modules and use the functions from these modules. 












NOTE:

My next post will be about making some additions in this code to make this code distributed in the form of Python eggs.

Then the post after that will about using this Python egg in a different application as a black box.



Almir M.