Python language basics 15: string basics part 2


In the previous post we saw how strings are represented and constructed in Python. We also mentioned other important terms such as string concatenation, immutability and character escaping.

In this post we’ll look at a couple of other important things regarding strings. Bear in mind that Python offers a very large library regarding strings. It could take the rest of the year to blog about all of it. Here we’ll only discuss a handful. Here are a couple of useful links to help you further:

Read more of this post

Python language basics 14: string basics


You can think of a string as being a text. It is a combination of characters like “a” or “h”. Characters can just as well be non-Latin ones of course such as Greek, Cyrillic, Chinese or Japanese characters. Characters that make up a word, a sentence or a whole book are all examples of strings.

Creating strings in Python

There are various ways to create strings in Python. We’ve already seen some examples in this series. You just put the string within single or double quotes and you’ve constructed a string:

myString = "hello world, this is Python calling"
myOtherString = 'hello world, this is Python calling'

Read more of this post

Determine if two arrays are structurally equal in C# .NET

Two arrays are said to be structurally equal if they contain the same elements in the same order. Whether or not two elements are the same depends on how you define equality for your custom types. Equality for primitive types, like integers, is more or less straightforward but you’ll need to declare in code what is meant by equality for reference types.

We’ve looked at a couple of strategies to do so on this blog and here we’ll re-use the topic of implementing the IEqualityComparer of T interface.

The non-generic IStructuralEquatable interface has an equals method that accepts an object to compare with and another object which implements the non-generic IEqualityComparer interface. This is an important distinction as implementing the generic IEqualityComparer interface won’t be enough for structural equality. We’ll need to derive from the EqualityComparer base class which implements both the generic and non-generic version of IEqualityComparer. If you try to run the below example with a generic IEqualityComparer of T instance then you’ll get a compiler error.

Note that structural equality is not available for all collection types. Currently only arrays and tuples support it, i.e. they can be cast to type IStructuralEquatable. However, as List objects can be easily converted into arrays that’s not really an obstacle.

Read more of this post

SOLID principles in .NET revisited part 9: concentrating on enumerations


In the previous post we streamlined our demo code so that it adheres to the SOLID principles. You may still spot bits and pieces that violate some design principle. It’s important to remark that in a large enterprise project it’s very difficult to attain 100% SOLID, if that state exists at all. You might be able to spot “deviations” even in the most well-maintained code bases.

In this post we’ll concentrate on enumerations. We saw before in this series how false usage of enums can easily lead to maintainability problems. Enumerations seem to be very popular due to their simplicity and how easily they can be used to create a list of valid values in a certain category.

We’ll first build up a short case study with all types of mistakes with special emphasis on enumerations. We’ll then improve the code in the next post.

Read more of this post

Implementing equality of derived reference types by overriding the == operator with C# .NET

In this post we saw one solution to override the == operator for a reference type to implement equality checking. Here’s a reminder of the Person class:

public class Person
	public int Id { get; set; }
	public string Name { get; set; }
	public int Age { get; set; }

	public static bool operator ==(Person personOne, Person personTwo)
		return personOne.Id == personTwo.Id;

	public static bool operator !=(Person personOne, Person personTwo)
		return personOne.Id != personTwo.Id;

        public override int GetHashCode()
		return Id;

Read more of this post

Implementing the IEquatable of T interface for object equality in a derived class with C# .NET

In this post we saw how to implement the IEquatable of T interface for a simple Person class. We based our equality logic on the Id property of the object. We implemented the IEquatable.Equals method and also overrode the Object.Equals and GetHashCode methods.

In this post we’ll see how you might go about extending that logic in derived classes. For that purpose we’ll go with another object:

Read more of this post

SOLID principles in .NET revisited part 8: clean-up


In the previous post we covered letter ‘D’, i.e. the Dependency Inversion Principle among the SOLID principles.
A class can have a number of dependencies in order to perform its functions properly. Applying DIP will open an entry point for the clients to supply their own implementations for those dependencies when they call upon that class. The class in turn can remove all responsibility of creating concrete implementations for its abstract dependencies. The result will be loosely coupled code where a class won’t be tightly coupled to concrete services.

In this post we’ll only clean up a couple of remaining issues in the code.

Remove “virtual”

In the post on OCP we mentioned that the “virtual” keyword provided an extensibility point for a class. However, since then we know that abstractions provide a much better alternative. Hence we don’t have to make our methods virtual any more:

Read more of this post


A great site

iReadable { }

.NET Tips & Tricks

Robin Sedlaczek's Blog

Love to use Microsoft Technologies

HarsH ReaLiTy

My goal with this blog is to offend everyone in the world at least once with my words… so no one has a reason to have a heightened sense of themselves. We are all ignorant, we are all found wanting, we are all bad people sometimes.

Ricos Blog zu Softwaredesign- und architektur

Ideen und Gedanken rund um Softwaredesign und -architektur, Domain-Driven Design, C# und Windows Azure

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

.NET, SQL and Mobile

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET (WebForms / MVC), WCF, Web API & C#

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.


Get every new post delivered to your Inbox.

Join 680 other followers

%d bloggers like this: