In the HTML and CSS snippet below we have two divs with a class called "inner". Both these divs are set to display:inline-block;
and hence they should display next to each other and not on top of each other. So why do they display on top of each other?
Note: box-sizing
is set to border-box
. Both inner divs are exactly 200px even with the 1px border and their parent is exactly 400px.
Answer?
See this post on StackOverflow. Thanks to everyone who contributed.
It has been an incredible 9 weeks at FireBootCamp (21 Jul - 19th Sep 2014).
I went into FireBootCamp as a fairly experienced developer and I feel that I've come out so much better. My key technology highlights include AngularJS, Azure Websites, WebJobs, Storage Queues. I also learnt how to do Scrum properly in order to be Agile not Fragile.
FireBootCamp not only taught us about technology skills but also about the importance of helping others, the importance of communication skills and how to enhance your own career development.
One wise piece of career advice I received from my mentor Adam Stephensen who told me: "Don't get a job and only do the job". He advised me to specialise in something and become really good at it. Blog about, present it to user groups and to help people in the community when they need help. As a result I have made my first steps towards this and have started this blog to post solutions to problems or things which I have learned along the way and to help others who might stumble upon the same issues.
I have to thank all my fellow FireBootCampers for the incredible 9 weeks. Thank you to my mentors Adam Stephensen and Adam Cogan at SSW. Thanks to all the guest speakers. Thanks to all the SSW employees who have helped out when we were stuck on a difficult problem. Thanks to Marlon Marescia for your guidance and support. I am grateful.
This has got to be the best professional training course I've been to so far. As AdamS mentioned on our last day, the real work starts after the bootcamp. And so the work for me now begins…
What does the virtual keyword in C# do? Let's look at a practical example below in .NET Fiddle:
Here we have two classes: Car and Ford. Ford inherits from Car. The Car class has two methods Move() and Stop(). The Move() method in the Car class is declared virtual. In the Move() method in the Ford class we've declared that method with the override keyword.
On line 7 we are creating an instance of Ford but using polymorphism we can store it as a Car object because Ford inherits from Car. On line 8 in our code, when we call the Move() method on the car, the Move() method on the Ford class is still being called as can be seen from the resulting output. You can't call the Car's Move() method outside of the Car or Ford class. Only the Ford's Move() method is called. This is what the virtual and override keywords in C# provide for us.
The Microsoft documentation on the virtual keyword describes the behaviour as of it follows:
When a virtual method is invoked, the run-time type of the object is checked for an overriding member. The overriding member in the most derived class is called, which might be the original member, if no derived class has overridden the member.
Let's now have a look at the new keyword. The new keyword in C# has two usages. One is to instantiate a class, the other is to hide an inherited method, like what we are doing on line 34.
The Stop() method in the Car class is not declared as virtual which is in contrast to the Move() method. On line 9 when we call car.Stop() notice how the Stop() method on the base method is called and not the Ford's Stop() method.
I hope this gives a general idea of these three keywords (virtual, override and new) and how behave in the context of inheritance and polymorphism.
Let's look at the example code below and its output in JS Bin:
var x = "string";
console.log("!!x is " + (!!x));
console.log("x == true is " + (x == true));
You might be surprised that the second statement actually prints false instead of true, even though both sides of the == operator are truthy values. So why is this the case?
This is because when
you're using the double equals operator (==) and you're comparing a
string with a boolean, both values first get converted to a Number and then they are compared.
If we convert a boolean to a number then a true converts to 1 and false converts to 0. A string like '1' can be converted to 1 but a string like 'string' can't be converted to a number so it gets converted to NaN.
So in the above code example the comparison becomes:
NaN == 1
Now NaN compared to anything is false. Hence the expression ends up being false.
If you want to see if a value is truthy, use the not operator twice (!!). This is also known as 'double bang'.
For example:
var x = "string";
console.log(!!x);
This would print true.
Reference:
http://stackoverflow.com/questions/4923631/why-does-ifstring-evaluate-string-as-true-but-if-string-true-does-not
I made this short video to explain what Dependency Injection is and how to use it to create loosely coupled and easily Unit Testable components.