Python: Pinging a Server Using Windows

I found a snippet online at StackOverflow:

https://stackoverflow.com/questions/2953462/pinging-servers-in-python/32684938

I am working with two FTP servers at work and am writing tests for the application we run on it. The test case I am handling right now involves having no application, no backup, and no valid application on the FTP server that will FTP it to the machine. I get an Updater FTP error. After 1s, 2s, 3s, 1m, 10m, and 1 hour it will reboot the machine and since I only have it in the log files to prove that, I need to have the test know when this reboot happens. So I am pinging the machine once a sec for 4,266 seconds and when it goes offline, it will return false.

I encountered a problem I want to document for the future in case anyone else or myself forgets this will happen.

On any other machine, a ‘Destination Host Unreachable’ error will be False, but if you specify identifying the machine as Windows, it will still return true.

Python logic to tell when the ping ends.
Python method to ping a server.

Examining Two Test Types and Their Application

Testing can focus on various aspects of a system or software. These aspects can include a focus on functionality, or what the system does, or on non-functionality, how the system does it what it does. It can also include testing on the system’s structure, changes to the system, if changes are successful, and if any unintended side effects happened. These four levels of test types are called functional, non-functional, structural, and change related. In this post, I will examine functional testing and testing pertaining to changes.

           Functional testing involves testing the specified behavior or “what it does” and may be performed at all test levels. Specification-based testing is also known as “black-box testing” since it tests without reference to the internal structure of the component or system (Black, 2012). The testing focus for functionality testing is usually suitability, interoperability, security, accuracy, and compliance, according to ISO 9126 standards. There are two main approaches to using this test type: requirements-based or business-process based.

Requirements-based testing can take the requirements from the table of contents of a specification document and use them as a test basis for creating the tests. Business-based requirements are focused more on use cases from business processes. In a payroll system, for example, business processes would include when an employee joins the company or how often employees are paid.

  Testing related to changes involves confirmation and regression testing. After a failed test, a defect is found and fixed. Confirmation testing involves re-testing the code in the same way and make sure that the new code did not bring in any unintended side effects and can be used at all test levels. Regression testing is used as a follow up to confirmation testing.

           Regression testing involves executing test cases that have already been completed and most likely passed the last time they ran. We must organically grow the regression test suite over time in line with the software just as we do with unit tests. Should one of these tests now fail, we will have found a new defect introduced to the system. Regression testing should be performed at all test levels, specifically when a new version of the software is created, or the software environment changes.  

References

Black, R. Foundations of Software Testing ISTQB Certification. [Capella]. Retrieved from https://capella.vitalsource.com/#/books/9781305175594/

Clean Code: Naming Conventions

A series of blog posts based on Robert C. Martin’s book “Clean code : a handbook of agile software craftsmanship“.

You can find the book here.

As a programmer, we are going to be naming lots of variables, classes, and methods. According to Uncle Bob in Clean Code, we should name a variable with the same care we do in naming a first-born child. After all, we are going to need to be able to call it, know what it’s for, and not confuse it with any other variables in our classes.

When we name with care, we name with “intention-revealing” names. Naming well saves you more time in the long run, saves everyone more time, and prevents a snowball of bad things happening to your precious code. The names we choose should answer the big questions:

Why does it exist?
What does it do?
How is it used?

Good and bad naming examples in code.

We need to be able to tell what the code is doing. In the example picture, it is very easy to see what the purpose is of the last three names versus the first name. Explicit names help immediately see what is going on in the code. If you MUST use a single letter name, it is best practice to use it as a local variable inside a short method. The length of a name should correspond to the size of its scope.

Using a name like h, we would have to mentally map what this variable is doing, translating it in our brain to what it actually does, using much more memory. Clarity is king. Use your powers for good naming practices to write code that everyone can understand. Pretend like the next person who will read your code is a violent psychopath who knows your address. It’s serious business!

Class and Method Names

This is something that needs to be written on your computer or tattooed on your arm or put anywhere you can see it, like an affirmation you are practicing, only programmer edition.

Photo by ThisIsEngineering on Pexels.com

Class names should have a noun or noun phrase. Class names should not be verbs.

Methods should have verb or verb phrases. Accessors, mutators, and predicates should be named for their value and prefixed with get, set, and is according to the javabean standard.
(“Oracle Java Technologies | Oracle,” 2019).

Don’t be cute in naming. Clever names are memorable only to people who share the same humor and some of us are the only ones laughing at our jokes. I know I’m funny, but others may not think so. Clarity is more important than entertainment. Our cleverness only goes so far as our cultural slang. Naming something dirtNap() meaning kill() or wipeout() meaning DeleteItems() is cute, but the latter is understood by all. A consistent lexicon is worth its weight in gold for the programmers who must use your code.

Other Important Naming Concepts

Pick one word for an abstract concept and stick with it. Using fetch, retrieve, and get as similar methods in different classes goes back to using too much mental memory. Ask yourself some questions about what these methods are doing and see if they are all serving the same purpose to choose an appropriate word.

Don’t Pun. Converse to using one word per abstract concept, do not use the same word for two purposes. Doing so would be a pun. Using “one word per concept”, could end up with a lot of classes using an “add” method as described in the book. If we are using the word for consistency rather than intent, it can get very confusing. Ask yourself what the method is actually doing so you know if you need to name it “insert” or “append”.

Use Solution Domain Names. Programmers will be reading your code so go ahead and use terms that other programmers understand like algorithm names, math terms, and pattern names.

Use Problem Domain Names. Problem domains refers to all the information that defines the problem (i.e. the problem you are solving with code). If there are no programming or computer science terms for what the code is doing, use the name from the problem domain. Good programmers and designers have the important task of separating solution and problem domain concepts.

Photo by Startup Stock Photos on Pexels.com

Add Meaningful Context, But Not Gratuitous Context. Most of the time we have successfully added meaningful context by using good naming, separation of concerns, and well-defined classes. As a last resort, you may have to add some prefixing. If you saw firstName, lastName, street, houseNumber, city, state, and zipcode in a method, you would assume it’s an address. If city was used alone in a method, would you assume it’s part of an address? The context can be added by prefixing with addrState, addrCity, etc so it’s explicitly part of an address.

This doesn’t mean to do this always. Adding gratuitous context can be very confusing, like prefixing every method with the acronym of the application. “ABCFirstName, ABCLastName, ABCStreetAddress” are too much. Shorter names are generally better than long ones when they are clear.

Following some of these rules and asking yourself the important questions about your code will help get you thinking about what and why you are naming things and keeping the code understandable for all, saving you many headaches in the future. Happy coding!

References:

Oracle Java Technologies | Oracle. (2019). Retrieved March 29, 2020, from Oracle.com website: https://www.oracle.com/java/technologies/

Martin, R. C. (2009). Clean code: A handbook of agile software craftsmanship. Upper Saddle River, NJ: Prentice Hall.




We Belong Here Podcast

I had an amazing experience this year to be on the We Belong Here Podcast with Lauren Lee Anderson (@lolocoding on Twitter).

I had heard a lot of podcasts about how they career transitioned from one career that was totally different and into tech. I didn’t hear a lot about the dark side of transitions. Transitions that come from dark, personal, life-changing experiences. My past is dark.

I got very vulnerable in this podcast to show others that it is your thoughts that allow you to keep going, a desire that keeps you going, knowing what you don’t want in your life that keeps you going.

Roadblocks happen, I believe they are supposed to. Success isn’t linear and those roadblocks build your resiliency. If you struggle with wondering if you can make it, you can. Have a listen.

I would love to hear your stories of how you overcame your obstacles!

Episode 21: Elyse Segebart
https://bit.ly/3bfXOyk

Elyse Segebart on the We Belong Here Podcast

Android N Developer Course: D3

100 days of code D6 & 7.

Created an application that takes two photos uploaded to the drawable folder. Added a button called New Cat and when clicked, will display a photo of a different cat. First tested that my button worked by using the Log.i to display a message to the log to ensure that my button was clicked. Created the onClick function called “clickCat”. Worked very similar to the EditText, only used ImageView and typecasted the findView to ImageView. The second part was to use

image.setImageResource(R.drawable.cat2);

to set the image to the second photo upon being clicked.

You can use Properties > Scale Type to change how the photo is displayed in the screen. FitXY stretches it to the edge of the container, fitStart keeps it in proportion and aligns to top of container, Center keeps it in proportion and centers the image. Center is probably one I will use the most.

And here are my results!

Beautiful cats aren’t they?

Android N Developer Course: D2

Day 5 of 100 days of code.

Learned about Toast today. I think its cute they call it toast because it pops up at the bottom of the screen like toast does out of the toaster.

Toast can only be Long or Short: meaning it will show up at the bottom of the screen for a short or long time. You can also use the variableName.getText().toString() to retrieve what the user entered and display it to the bottom of the screen as well as concatenate any message you want to go along with it. In this case, I added “Hi there, ” so it would display before the name retrieved.

I made a small toast program that has a TextView, a PlainText spot to enter your name, and a button that says “Click me!”.

In the MainActivity, I created an EditText variable and typecasted so the program can find it in the Resources. Here is the code to create this program and the result below!

Overall, I thought this was a neat little bit. I remember watching this video like a year ago and I didn’t think I was ever going to understand it. Well, LOOK AT ME NOW! 🙂

Why Read My Blog?

If you’re reading this, chances are you are in the same boat as I am: learning to code and finding your way. Most likely, you’re interested in other things and maybe you share some of the same passions as me.

I am in my last year of my BS in Information Technology with a specialization in Software Development. I have worked with HTML, CSS, JavaScript, Java, JavaFX, FXML, XML, Kotlin, and have a passion for mobile applications.

I am also interested in health and fitness, meal prepping, nutrition, helping women in technology, sharing knowledge, reading self-help books, self-care, playing piano, and advocating for others struggling with addictions and helping them overcome it.

The main focus of this blog is just to jot down all the little tips and tricks I learn along the way while coding and also post what I am working on to Twitter. I think that those things need to be shared with others (and having a log of those things will also help me remember how I did something!). How many times have you encountered an error or worked through a problem only to encounter it again and say, “I did this before and I don’t remember how to do it now! ARGH!”. Well, I have done that more times than I want to admit so this will be a collective journal that hopefully someone other than just myself will get use out of!

I would love to connect with other tech women and share experiences and learn from each other. I think that education is a social endeavor and the more we can communicate and learn from each other, the faster it will help all of us advance.

I am starting with the 100daysofcode challenge and will be updating this regularly with my progress. If you are doing the same challenge or want to learn more about it, connect with me and we can work through it together! I love accountability partners.