10/06/2018 13:14 BST

I have been very busy with refactoring my site, hench the lack of update, I have made heavy use of functional programming and I got rid of most of the side effect; it had a more pleasant impact on code maintenance and writing test, I don’t have to worry about a database connection initialising while running the test, previously to stop the database from initialising I made use of build tags, I added a comment // +build !debug on top of the file where the database connection get initialised it was inelegant, with FP I don’t have to do that anymore, but I still use // +build debug for the mocks. I’m not going to go into too much about the problem of impure function, but I will leave a video, cheers.

He has inspired me to refactor my site, believe it or not.

03/04/2018 13:05 BST

Ever since my childhood, although I did pray at school (they kind of force me to, I never like my school) I have never been much of religious person, nowadays I just see myself as an agnostic-atheist, I have never seen any good scientific evidence of the existence of at least one god; however I do believe there is a possibility of life in space but in a form of aliens on another planet, it’s obviously going to be a planet that is over 100 light-years away, might be in a same galaxy as us (the Milky Way) or a different galaxy, who knows? of course we got photographics evidence of other galaxy existing on google, they all came from the hubble telescope built by NASA take you pick.

03/03/2018 12:55 GMT

First off I don’t really hate Wordpress, I’m perfectly aware that it’s is a very popular blogging platform. I just don’t think the platform is for me, there are various reasons why?

Bloatware

Wordpress contains many features, most of them I probably won’t need for example the revision system, well I got Google Docs for that and therefore I didn’t implement that on my bespoken system, because I felt that the revision system would of added stress to the database, I like to keep the database nice, clean and easy to maintain, I just respect the database. I use postgres and mongodb, wordpress forces me to use MySQL which is not really my cup of tea.

I also didn’t implement the comment system by myself, as I thought that would of been too risky for me, I have used a third party comment system (disqus) as I felt that would provide me better protection against spambots.

Wordpress allows user to use HTML directly, I would not trust anyone to use HTML via a web interface, I wouldn’t even trust myself, I’m only human just like everybody else. My own system does not allow anyone to use HTML, it’s use markdown instead.

Is there a time, when you often get tired of writing the same if logic over and over again just to validate a simple string and you’re not a fan of using OO just for something dead simple. If so this little tutorial maybe for you, or not.

It’s going to be quite similar to Symfony’s raw value validation, the big different is that Symfony’s is OO, but my example is going to be a bit more functional with a little bit of OO, I’m using closures as I find that the more cleaner solution to the problem. To be fair Symfony’s is written in PHP and mine is written in Golang.

Okay, now I’m going to start off the tutorial, first off you need to create a error collector and a validation error type, this is very easy to do.

type ErrorCollector []error

func (e ErrorCollector) Error() string {
	str := []string{}
	for _, err := range e {
		str = append(str, fmt.Sprint(err))
	}
	return strings.Join(str, "\n")
}

func (e ErrorCollector) FilterErrors() error {
	errorCollection := ErrorCollector{}
	for _, err := range e {
		if nil != err {
			errorCollection = append(errorCollection, err)
		}
	}

	if len(errorCollection) == 0 {
		return nil
	}

	return errorCollection
}

type ValidationError string

func (e ValidationError) Error() string {
	return fmt.Sprint(string(e))
}

Both of those data type, implement the builtin error interface, so we can use those data type under the type hint of error easily.

| |