Posts

FizzBuzz - my first interview task on whiteboard

Image
 I think we all know the FizzBuzz task, when we a function shall print fizz if the number is divided by 3, buzz if by 5 and fizzbuzz when by both. Yesterday I did a small research about how many different implementations we can have using C# and there were many. Ones looks very common with "if"   statement tree, some of them were using LINQ and looking hard to understand what is going on in a first instance. StackOverflow has this one question with a bunch of examples  Writing FizzBuzz , that I will use to check how those solutions work from a performance perspective, code complexity and human understanding. listing 1 fizzbuzz question As we can see, OP introduced a tuple to solve the problem, which in my opinion gives a lot of opportunists for extensions with a little code changes.  The metric looks good, but if we move the list declaration outside the function (so it is not recreated every time the function is called we shall be good) To do benchmark I will convert

ach - why we do not put attention to what we are doing???...

Image
 Ach, humans don't want to be fast, they just CTRL+C and CTRL+V, shit over shit, but it is working so what do you want a...!!! see this snippet: Is there anything suspicious for you? NO??? Yesterday I was reading Aaron Stannard blog entry about DRY and above snippet just jumped at me from the corner of my screen.  DRY DRY DRY. Now: what's wrong with this one? It is not human friendly (formatting) It is not CPU friendly as there are two string interpolations instead of one we could introduce a helper variable to make it nicer to read (and this is a bit of WTF -  see below) So what we can do with this? Firstly use a single interpolation with a proper formatting like {date:MMM-yy} , this will do the job nicely and we don't need to decipher two statements to get the output when reading the code, now we also could format it a bit, so it is not spread on the wide screen edge to edge... So what do you think about this: Looks better? For me this is true, but is t

github time travelling explained (it is not what you are thinking about)

Image
Do you know how much freedom we got by having git? I am always amazed by reviewing pull requests where there is confirmed by a developer only one commit. By confirmed, I mean that I asked a dev if there was more of them, but mostly it is the only one that is pushed to the PR (sometimes there are 2 or 3 as the branch needed to be adjusted with the main/master one). That situation can bring a few issues: There is a risk that all changes will be lost when a device that is in use will have a big boom and there will be  commit/push to the remote/global repo There is no restore point, which is helpful to try/test different solutions, CTRL+Z not always works as a charm  Pushing code, in most cases, means that it will trigger CI/CD pipeline and find any issues early As git is giving us very fast commiting experience (it is not a slow VPN connection to TFS, it is local repo) then you can be as extreme as crazy to commit every 5 seconds. So that means we are recording most actions, especially wh

are YOU a garbage collector?

Image
 If I will ask you: "Are you a garbage collector" - I bet I will hear: " NO ", so I ask you: show me your code.... It is unbelievable that so many developers are pushing changes with commented out code, because  there could be a chance to re-use that piece. In fact that time never comes to me and the lines stays there forever. Clean code means no rubbish commented code - we have git to remember that for us. Now, when you need to comment a few lines in a row... there are better solutions, but if someone is lazy and slumsy then we can see diffs on code review like that: Now this is a mystery for me, when I am able to see that this is going to the main branch as the guys who is called code reviewer is there only to click Approve -  I am truly believing that it is not you my reader. I need to admit that, when I was a kid, together with grandma we were collecting garbage as a way to get some $$ for a life and then every piece we found had a material value and were able t

everyday learn a new thing!! IEnumerable.ZIP for brekfast.

Image
Whoaaaa!  I am sometimes impressed with my ignorance and inability to learn new things, especially that the incredible stuff is already there for YEARS! Today I was reviewing a great git repository with algorithms  and fond a ZIP linq function. I was looking at it like a cow is looking for a newborn, my jaw dropped to the keyboard and euuureeeka!! no more for in for loops!! Zip solves a simple problem, allows us to make an union/operation on elements on two enumerable objects (arrays, lists, etc) documentation here The example from MS docs is clear, and easy to swallow, but if the input objects have different number of elements, then we will get a truncation. As the function looks cool, it also works nice,  As IEnumerable is a basic way of having collections, it is very fast as well. As I was not able to hold off myself from LINQPad to make a test. See this listing below pretty easy code right? but now see the benchmark results. Accessing IE using element at wil iterate the co

actor or standard class? - part 2

Image
In previous post  an actor was benchmarked against a standard class, and for a single user there was almost no diffrence in performance, but with multiple issues a class run in to a concurrent access problems, so the performance dropped more than 10prc and we got some not processed requests ended with 500.  Now we will replace storage with a MariaDB database (why Maria? - my friend asked for help and  I just used it here as well) and run those  parallelly to exhaust  DB capabilities. As we can see, JMeter was spreading the workload, and we hit the database limit which is around 1500 requests/sec. Now our business guys come to us and ask: we need it faster, don't send us Id of the created record - as we don't needed, we need to save at least 5x more records. So how we can do it? Hmm. The best way will be to bulk insert, like 250 records at once, or every 1 second depending on the traffic. In first case let's focus on enabling a bulk save, which will be a counter and an if st

actor or standard class? - how to explore the differences

Image
 Many times I was talking with developers about using an actor system as a way to gain productivity and scalability. What I found that most peoples had no experience and no time to try it out, moreover existing projects and teams are on the hesitating side as new stuff will require a learning time (and who want to learn when all is gooooing goooood and sloooow). Let me share some concepts that were able to help me to understand and use actor system in C#, so we are talking about akka.net .  First listing contains a class and an actor. Please read it carefully.  listing 1: What we can see at the first glance that actor class is inheriting after ReceiveActor, has a strange Receive<T>(). In standard approach when we create an instance of class c, then we are calling their methods and passing parameters to do the job. In actor system, we are not calling methods inside an actor - we are passing messages - so we need to receive them and then handle.  This makes it a bit harder t