Software Engineer
Software engineeringPosted over 2 months agofrom Valorx's own hiring page
- Work type
- On-siteAhmedabad
- Experience
- Not stated
- Pay
- Not listedUsually ₹8.2 LPASoftware engineering, median, all levels, in India (Payscale)
- Posted
- Over 2 months agoOpen over 3 years
Skills it mentions
Add your skills to see which ones you have.
About the job
Interested?Software Engineer at Valorx
Apply on company site (opens in a new tab)The job ad ends here
Interview questions for this job6 with answers, on C# and C++
Interview questions for this job
For the skills the ad mentions: C# and C++.
What is a NullReferenceException, and how do I fix it?C#
What is the cause?
Bottom Line
You are trying to use something that is
null(orNothingin VB.NET). This means you either set it tonull, or you never set it to anything at all.Like anything else,
nullgets passed around. If it isnullin method "A", it could be that method "B" passed anullto method "A".nullcan have different meanings:- Object variables that are uninitialized and hence point to nothing. In this case, if you access members of such objects, it causes a
NullReferenceException. - The developer is using
nullintentionally to indicate there is no meaningful value available. Note that C# has the concept of nullable datatypes for variables (like database tables can have nullable fields) - you can assignnullto them to indicate there is no value stored in it, for exampleint? a = null;(which is a shortcut forNullable<int> a = null;) where the question mark indicates it is allowed to storenullin variablea. You can check that either withif (a.HasValue) {...}or withif (a==null) {...}. Nullable variables, likeain this example, allow to access the value viaa.Valueexplicitly, or just as normal viaa.
Note that accessing it viaa.Valuethrows anInvalidOperationExceptioninstead of aNullReferenceExceptionifaisnull- you should do the check beforehand, i.e. if you have another non-nullable variableint b;then you should do assignments likeif (a.HasValue) { b = a.Value; }or shorterif (a != null) { b = a; }.
The rest of this article goes into more detail and shows mistakes that many programmers often make which can lead to a
NullReferenceException.More Specifically
The
runtimethrowing aNullReferenceExceptionalways means the same thing: you are trying to use a reference, and the reference is not initialized (or it was once initialized, but is no longer initialized).This means the reference is
null, and you cannot access members (such as methods) through anullreference. The simplest case:string foo = null; foo.ToUpper();This will throw a
NullReferenceExceptionat the second line because you can't call the instance methodToUpper()on astringreference pointing tonull.Debugging
How do you find the source of a
NullReferenceException? Apart from looking at the exception itself, which will be thrown exactly at the location where it occurs, the general rules of debugging in Visual Studio apply: place strategic breakpoints and inspect your variables, either by hovering the mouse over their names, opening a (Quick)Watch window or using the various debugging panels like Locals and Autos.If you want to find out where the reference is or isn't set, right-click its name and select "Find All References". You can then place a breakpoint at every found location and run your program with the debugger attached. Every time the debugger breaks on such a breakpoint, you need to determine whether you expect the reference to be non-null, inspect the variable, and verify that it points to an instance when you expect it to.
By following the program flow this way, you can find the location where the instance should not be null, and why it isn't properly set.
Examples
Some common scenarios where the exception can be thrown:
Generic
ref1.ref2.ref3.memberIf ref1 or ref2 or ref3 is null, then you'll get a
NullReferenceException. If you want to solve the problem, then find out which one is null by rewriting the expression to its simpler equivalent:var r1 = ref1; var r2 = r1.ref2; var r3 = r2.ref3; r3.memberRead the rest at the sourceFrom Stack Overflow: asked by John Saunders, answered by John Saunders (CC BY-SA 4.0)
- Object variables that are uninitialized and hence point to nothing. In this case, if you access members of such objects, it causes a
Why can templates only be implemented in the header file?C++
Caveat: It is not necessary to put the implementation in the header file, see the alternative solution at the end of this answer.
Anyway, the reason your code is failing is that, when instantiating a template, the compiler creates a new class with the given template argument. For example:
template<typename T> struct Foo { T bar; void doSomething(T param) {/* do stuff using T */} }; // somewhere in a .cpp Foo<int> f;When reading this line, the compiler will create a new class (let's call it
FooInt), which is equivalent to the following:struct FooInt { int bar; void doSomething(int param) {/* do stuff using int */} };Consequently, the compiler needs to have access to the implementation of the methods, to instantiate them with the template argument (in this case
int). If these implementations were not in the header, they wouldn't be accessible, and therefore the compiler wouldn't be able to instantiate the template.A common solution to this is to write the template declaration in a header file, then implement the class in an implementation file (for example .tpp), and include this implementation file at the end of the header.
Foo.h
template <typename T> struct Foo { void doSomething(T param); }; #include "Foo.tpp"Foo.tpp
template <typename T> void Foo<T>::doSomething(T param) { //implementation }This way, implementation is still separated from declaration, but is accessible to the compiler.
Alternative solution
Another solution is to keep the implementation separated, and explicitly instantiate all the template instances you'll need:
Foo.h
// no implementation template <typename T> struct Foo { ... };Foo.cpp
// implementation of Foo's methods // explicit instantiations template class Foo<int>; template class Foo<float>; // You will only be able to use Foo with int or floatIf my explanation isn't clear enough, you can have a look at the C++ Super-FAQ on this subject.
From Stack Overflow: asked by MainID, answered by Luc Touraille (CC BY-SA 4.0)
Why not inherit from List<T>?C#
There are some good answers here. I would add to them the following points.
What is the correct C# way of representing a data structure, which, "logically" (that is to say, "to the human mind") is just a list of things with a few bells and whistles?
Ask any ten non-computer-programmer people who are familiar with the existence of football to fill in the blank:
A football team is a particular kind of _____
Did anyone say "list of football players with a few bells and whistles", or did they all say "sports team" or "club" or "organization"? Your notion that a football team is a particular kind of list of players is in your human mind and your human mind alone.
List<T>is a mechanism. Football team is a business object -- that is, an object that represents some concept that is in the business domain of the program. Don't mix those! A football team is a kind of team; it has a roster, a roster is a list of players. A roster is not a particular kind of list of players. A roster is a list of players. So make a property calledRosterthat is aList<Player>. And make itReadOnlyList<Player>while you're at it, unless you believe that everyone who knows about a football team gets to delete players from the roster.Is inheriting from
List<T>always unacceptable?Unacceptable to whom? Me? No.
When is it acceptable?
When you're building a mechanism that extends the
List<T>mechanism.What must a programmer consider, when deciding whether to inherit from
List<T>or not?Am I building a mechanism or a business object?
But that's a lot of code! What do I get for all that work?
You spent more time typing up your question that it would have taken you to write forwarding methods for the relevant members of
List<T>fifty times over. You're clearly not afraid of verbosity, and we are talking about a very small amount of code here; this is a few minutes work.UPDATE
I gave it some more thought and there is another reason to not model a football team as a list of players. In fact it might be a bad idea to model a football team as having a list of players too. The problem with a team as/having a list of players is that what you've got is a snapshot of the team at a moment in time. I don't know what your business case is for this class, but if I had a class that represented a football team I would want to ask it questions like "how many Seahawks players missed games due to injury between 2003 and 2013?" or "What Denver player who previously played for another team had the largest year-over-year increase in yards ran?" or "Did the Piggers go all the way this year?"
That is, a football team seems to me to be well modeled as a collection of historical facts such as when a player was recruited, injured, retired, etc. Obviously the current player roster is an important fact that should probably be front-and-center, but there may be other interesting things you want to do with this object that require a more historical perspective.
From Stack Overflow: asked by Superbest, answered by Eric Lippert (CC BY-SA 4.0)
What is the '-->' operator in C/C++?C++
-->is not an operator. It is in fact two separate operators,--and>.The code in the condition decrements
x, while returningx's original (not decremented) value, and then compares the original value with0using the>operator.To better understand, the statement could be written as follows:
while( (x--) > 0 )From Stack Overflow: asked by GManNickG, answered by Charles Salvia (CC BY-SA 4.0)
When should I use a struct rather than a class in C#?C#
The source referenced by the OP has some credibility ...but what about Microsoft - what is the stance on struct usage? I sought some extra learning from Microsoft, and here is what I found:
Consider defining a structure instead of a class if instances of the type are small and commonly short-lived or are commonly embedded in other objects.
Do not define a structure unless the type has all of the following characteristics:
- It logically represents a single value, similar to primitive types (integer, double, and so on).
- It has an instance size smaller than 16 bytes.
- It is immutable.
- It will not have to be boxed frequently.
Microsoft consistently violates those rules
Okay, #2 and #3 anyway. Our beloved dictionary has 2 internal structs:
[StructLayout(LayoutKind.Sequential)] // default for structs private struct Entry //<Tkey, TValue> { // View code at *Reference Source } [Serializable, StructLayout(LayoutKind.Sequential)] public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDisposable, IDictionaryEnumerator, IEnumerator { // View code at *Reference Source }The 'JonnyCantCode.com' source got 3 out of 4 - quite forgivable since #4 probably wouldn't be an issue. If you find yourself boxing a struct, rethink your architecture.
Let's look at why Microsoft would use these structs:
- Each struct,
EntryandEnumerator, represent single values. - Speed
Entryis never passed as a parameter outside of the Dictionary class. Further investigation shows that in order to satisfy implementation of IEnumerable, Dictionary uses theEnumeratorstruct which it copies every time an enumerator is requested ...makes sense.- Internal to the Dictionary class.
Enumeratoris public because Dictionary is enumerable and must have equal accessibility to the IEnumerator interface implementation - e.g. IEnumerator getter.
Update - In addition, realize that when a struct implements an interface - as Enumerator does - and is cast to that implemented type, the struct becomes a reference type and is moved to the heap. Internal to the Dictionary class, Enumerator is still a value type. However, as soon as a method calls
GetEnumerator(), a reference-typeIEnumeratoris returned.What we don't see here is any attempt or proof of requirement to keep structs immutable or maintaining an instance size of only 16 bytes or less:
- Nothing in the structs above is declared
readonly- not immutable - Size of these struct could be well over 16 bytes
Entryhas an undetermined lifetime (fromAdd(), toRemove(),Clear(), or garbage collection);
And ... 4. Both structs store TKey and TValue, which we all know are quite capable of being reference types (added bonus info)
Hashed keys notwithstanding, dictionaries are fast in part because instancing a struct is quicker than a reference type. Here, I have a
Dictionary<int, int>that stores 300,000 random integers with sequentially incremented keys.Capacity: 312874
MemSize: 2660827 bytes
Completed Resize: 5ms
Total time to fill: 889msCapacity: number of elements available before the internal array must be resized.
MemSize: determined by serializing the dictionary into a MemoryStream and getting a byte length (accurate enough for our purposes).
Completed Resize: the time it takes to resize the internal array from 150862 elements to 312874 elements. When you figure that each element is sequentially copied via
Array.CopyTo(), that ain't too shabby.Read the rest at the sourceFrom Stack Overflow: asked by Alex Baranosky, answered by IAbstract (CC BY-SA 3.0)
Why do you think you're a good fit for our company?Behavioural
Employers want to see that you have a genuine interest in working for them by asking questions like:
- what do you know about our company?
- why do you think you're a good fit for our company?
- why do you want to work for us?
To prepare for questions about the employer, you need to research the company. You should look at their website and 'about us' pages to find out more about their products, services and values.
Show what you've learned about the company throughout the interview.From National Careers Service: interview advice (Open Government Licence v3.0)
Similar jobs
- Custom Software EngineerAccenture, Bengaluru, Hyderabad +12, on-site2 days ago
- Murex Senior Developer (ETP Risk)MUFG Bank Boston Corporate & Tech Hub, Bengaluru, on-siteToday
- Software Development Engineer - IIIF5, Hyderabad, on-siteToday
- Senior Software EngineerMirantis, Remote in IndiaToday
More like this: Jobs in Ahmedabad (388) and Software engineer jobs in India (1,457)



