java 8 stream

Tip: Java 8 Streams flatmap map lis...

A little example, I had to develop as a teaching use case, of how to take a map with Integer keys and values with a List as value and find a specific ...

Qual o teu estilo?

Qual o teu estilo? ...

Fun – Obsolete Technology

Obsolete Technology
From xkcd.com

Tip: Java 8 Streams flatmap map lists

A little example, I had to develop as a teaching use case, of how to take a map with Integer keys and values with a List as value and find a specific value in any List in the whole map using Java Streams.

boolean b1 returns true because the element exists
boolean b2 is the response to an element that doesn’t exist

Qual o teu estilo?

Qual o teu estilo?

Different roles in meetings

it’s funny because it’s true

Deja vu?

Go Language, First Steps

Go, first experience.

What

We are living in a very rich IT ecosystem, where developers aren’t afraid to explore new languages, tools and to use out of the box thinking. It’s a great time to living in this IT era! Following this trend, and due to some need I had to start to learn
a new language, GO.

Go, also called golang, was developed at Google. The motivation was to have a language less complex than C++.

Go has great advantages, such as:

  • Concurrency system, far superior than Python, for instance.
  • Compiled language, which makes it faster
  • The executable is static linked, which allows to create an executable for the destination platform. It means, it doesn’t need an interpreter.
  • strongly handling exceptions
  • Low memory footprint
  • Very easy to learn
  • Docker is built in Go

Starting

Installation

Just visit the Golang web site
The binaries are here.

Baby steps

First things first: IDEs

Learning

I started with the “official” tutorial A Tour of Go

The big points:

  • Every Go program is made up of packages
  • Programs start running in package main
  • By convention, the package name is the same as the last element of the import path
  • In Go, a name is exported if it begins with a capital letter
  • In functions, the type comes after the variable name
  • When two or more consecutive named function parameters share a type, you can omit the type from all but the last
  • A function can return any number of results
  • Go’s return values may be named. Also called naked return
  • The var statement declares a list of variables (package or function level)
  • Inside a function, the := short assignment statement can be used in place of a var declaration with implicit type
  • The expression T(v) converts the value v to the type T (casting)
  • Constants are declared with the const keyword
  • loop: for – like c, java, c++ but without the parentesis
  • The while> in Go its the for. for {} = infine loop
  • if doesnt need the parentesis
  • the if> allows a statement before the condition: if v := math.Pow(x, n); condition {
  • switch doesnt have the “break”, it is implicit
  • switch without a condition is the same as switch true. Good for long sequence of “if”
  • A defer statement defers the execution of a function until the surrounding function returns. defer add(2,3) PS: call’s arguments are evaluated immediately
  • Go has pointers!
  • The type *T is a pointer to a T value. Its zero value is nil.
  • The &var operator generates a pointer to its operand.
  • Unlike C, Go has no pointer arithmetic.
  • A struct is a collection of fields “type Complex struct”
  • arrays: var a [10]int
  • slices: var s []int = primes[1:4] – A slice does not store any data, it just describes a section of an underlying array
  • A slice has both a length (number of elements it contains) and a capacity (the number of elements in the underlying array)
  • Slices of slices
  • A map maps keys to values: var m map[string]int
  • Go functions may be closures. return func(x int) int { return x }
  • Go does not have classes. However, you can define methods on types. func (v Vertex) Abs() float64 {}
  • An interface type is defined as a set of method signatures. type Abser interface {Abs() float64}
  • Interfaces are implemented implicitly
  • The empty interface – may hold values of any type
  • A type assertion provides access to an interface value’s underlying concrete value. t := i.(T)
  • ype switches switch v := i.(type) { case T:…
  • Go programs express error state with error values. type error interface {…
  • The io package specifies the io.Reader interface.
  • A goroutine is a lightweight thread managed by the Go runtime. go f(x, y, z)
  • Channels are a typed conduit through which you can send and receive values with the channel operator, <-.
  • Like maps and slices, channels must be created before use: ch :=make(chan int)
  • Channels can be buffered.
  • The select statement lets a goroutine wait on multiple communication operations.

Conclusion

In a first impression I would say its a very good language for scripting. No complications around object oriented concepts. Just got the best of native languages and modern languages. While reading some articles everyone has the same option, Go its very
suited for concurrent applications, since its very easy to use channels, select and goroutines.
For sure, a very good challenger to my usual preference on python

Spiritual IT–Words and Programs

spiritual_mindAt this end of year I would like to mix a little bit IT and some Christian teachings. It is not unusual, Donald Knuth on the book Things a Computer Scientist Rarely Talks About do an experience on the 3:16 versicle of the Bible.

Christian Bible talks about how God created the world using only His Words.

As humans, we use words too, of course, to talk, to transmit ideas and sometimes to change others behavior.

As IT People we develop programs with specific objectives that will run inside a computer.(or more)

If we create a metaphor and suppose we are like computers (in some way we are organic computers), we are somehow running code in our mind (in a different programming language in another paradigm). Code that can change itself or develop new code taking current statements. (Yes, this is possible now in several languages, like prolog, list, and even popular languages like C# where it is possible to “emit” code).

When we, as people, are talking to each other, we are “putting” code inside the other person, hoping it will change something inside him/her.

If she is a girl that we are trying to conquer, we create a program that will try to create a sense of good impression inside her, and try to hacker her in a way we touch the right place so she can start to be in love with us. There are books, tips, friends, all of it trying to teach us how to create a program like that.

A salesman tries to create programs to convince the others to accept his arguments, and buy his products. There are a lot of hacks about this, books, courses, seminars, etc., about hacking “persons” to force them to say yes!

Every day we are trying to hack the other person with our language.

Politicians are master hackers, with great programs, to hack several people at same time, with statements that can unify a group of people and push them to the same idea!

There are even NLP, the discipline that teaches to hack ourselves and hack the others! And, look to the name “Neuro-Linguistic Programming

You got the picture!

Moral of this

One of the most important things a person should be careful is the tongue in our mouth because it is the  keyboard that writes the program that will be inserted on the other person, and is capable of great and wonderful things and capable of really bad things, as we all know.

Every time you will be talking to someone, remember, you are inserting a program on the other person. Try to be constructive, something that brings value, and not something destructive, because there are people that have great security measures and knows how to defend from hacking, but others don’t, and this can be very destructive for their lives. Depressions, bad decisions, and others, very well know consequences of this.

Likewise, the tongue is a small part of the body, but it makes great boasts. Consider what a great forest is set on fire by a small spark.” James 3:5

Have a great new year!

dynamic and ExpandoObject

tree_volteretaThe dynamic and ExpandoObject have a relation of love and hate with .NET developers. One side defends strongly typed objects to handle data, so it’s possible to handle a lot of issues at compile time. The other side, are developers used to develop scripts, python, and in other similar languages. They defend the dynamic nature of the current projects, with a lot of Xml, Json and unstructured data, so they prefer to use the more dynamic and functional structures of C#. Both are right! Some like to live strong typed and predictable, others like to live on the edge!

Personally, I am a hybrid developer, I like the strong type of languages, but love python and dynamic freedom, like C# provides. So it’s usual for me to use strongly typed objects on my projects, but every time I have to deal with unstructured data, I use the dynamic word and other constructs like Tuple class.

Because sometimes there are too many DTOs on the project!

ExpandoObject Basic Usage

ExpandoObject with methods

Reflection on the ExpandoObject

Office Games – The Leverage

leverageOffice games is a thing in all jobs. All the time, intentionally or not, it is something being played. If you are in a game, and you don’t know the rules or even that you are playing it, you will loose it for sure.

The most important think in every office games it’s the leverage. Many people think its fairness, but it’s not. Life isn’t fair, maybe the “time” will make it fair in the long term, but for the job, most of the times it’s too late.

People aren’t on the job to be fair, they are for their personal reasons, money, success, satisfaction, recognition, power, etc. If you are an obstacle for them, they will defend their goals as they can, and usually not being fair.

The excellent Netflix series “House of Cards” is an example of managing “leverage”. There is a passage from Frank Underwood, the master of creating leverage when he is talking with the president:

“Do I think she oversteps sometimes? Yes. Does she wrongly equate her advice with mine? Often. But the question that occurs to me is not about Linda. Let’s say you refuse her resignation if this gets out, and it could, won’t you be sending a signal to anyone who works for you that you can be leveraged? “

So, learn the game, learn the rules, play it!

Here some tips to get leverage:

  • Have something the other person needs
  • Have more authority.
  • Try to have a positive attitude
  • Try to be “cold”. Don’t be too emotional.
  • Have skills hard to be replaced
  • Have a good reputation
  • Try to have something that only you can provide
  • Build a network of empathy and cooperative attitude with the others.

Yes, these are things we all know from working, but are we developing them as much as we are developing our hard skills?

One of the definitions of Leverage
“The ability to influence a system, or an environment, in a way that multiplies the outcome of one’s efforts without a corresponding increase in the consumption of resources.” (from the BusinessDictionary)

Why non-requirements are “more” important than requirements

quality attributesWhen I was studying more deeply software architectures, I learned about the most important thing to consider in an architecture (after stakeholders), the non-functional requirements. Yes! Not the functional requirements, but the non-functional requirements.
Before I explain this more careful, let me say what “I” call requirements and non-requirements. (I will use requirements from now on, meaning functional requirements and the same applies for non-requirements)
Requirements are the features the final customer wants. Something like, I want an intranet portal where all the enterprise information is presented, where the users can consult news about the company and where the users can request material, etc. Preference, very detailed, the project manager and all the developers thank you for that.
Non-requirements are the “features”/attributes not related with the business, but very important, like performance, reliability, modifiability, security, auditing, transactional, availability, interoperability, testability, usability and others.
Sometimes people mix requirements with non-requirements, and sometimes they are right. If I want to build a race car, probably performance is a requirement.
The non-requirements are also called quality attributes because they give quality to the architecture. You can build an ugly/raw intranet portal with all the requirements in there. You will have all the information and all the requirements you requested to be implemented, but as soon you present the final product to the end users you will find why the non-requirements are so important. Probably you will call soon a designer to bring some quality to the web pages, Usability. Then you will start to hear some complaints about the performance, a user opens a page and all that information takes a long time to appear. It is time to for the non-requirement, Performance. The users they need important information available on the portal, to do their work along the day, so you will want Availability. The portal should access information available in other systems, and then again, Interoperability, and we can go on and on about this.
Why is this important, and really important? These non-requirements or quality attributes change the way something is built. They should be considered before the development, for many reasons: technical, time, resources and financial, to say at least. Technical, because the architect should consider them in the design and development process. Time, because it will take more time to implement them that just code the raw functionality. Resources, because you will need to consider people expert in some areas, like designers, integration, etc. Financial, as a consequence of the others.
For instance, for usability you should consider experts in that area, like designers. For security, one of the most intrusive quality attributes, you probably need an expert in that difficult area, or consider what blocks of code or modules should be protected and how. It can be a demanding task. For interoperability, you will have to consider what information to consume and provide, protocols, security, etc. If you work in financial software, you will surely want to test deeply the software, so the code and the architecture should be testable, the code will be organized for testability, and a lot of extra code will be implemented for testing purposes.
When you buy a house, the attributes you will take into your decision are more about quality than the living ones. If you follow only the living ones, any space with some blocks adjacent to each other will be enough for living! But, you will consider the access (security), how easy is to move around the house (usability), how strong are the house, like walls, material, etc. (reliability), and if the house is custom build for you, most of the time you will be speaking to the architect to consider this and that quality attribute, you will not be telling him that the house if just for living there, sleep, being and eat. You will want more, you will want quality, you will want a house based, above all, in non-requirements, responsible for making your expected requirements richer.
Curiously, the acceptance of any project, will be based on how the requirements were implemented served by the richness brought by the non-requirements. At least if you want a customer happy.
Without the non-requirements, the requirements will, paradoxically, not be “acceptable” by the final customer.

Bad Behavior has blocked 140 access attempts in the last 7 days.

Hyper Smash