This week's book giveaway is in the iOS forum.
We're giving away four copies of Classic Computer Science Problems in Swift and have David Kopec on-line!
See this thread for details.
Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!

Liutauras Vilda

+ Follow
since Nov 12, 2014
Liutauras likes ...
software developer, moderator at coderanch, a father, husband and nintendo switch owner
London, United Kingdom
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Liutauras Vilda

Pete Letkeman wrote:Have you tried sky diving and did you enjoy it?

I did, and did I enjoy? Well, it was interesting to try, but probably no more jumps ahead. My Dad did his military service in Afganistan, he used to be a paratrooper, and what he says about the sky diving, is that second jump is the most scary, so I'm very reluctant to try again.

I also did try bungee jumping from the crane (75 meters high) - that was way more scary.

3 hours ago
Please feel free to disregard this topic, I'm experimenting more in order to have more implementation details to consider, so maybe the answer will become apparent.

I think I was too early to try to make decision + created all that mess with naming which didn't help either.
20 hours ago
So the initially posted version 2 would look now with improved naming like:

And the version 3 would look like:

Sorry once again for the created confusion.

20 hours ago

Junilu Lacar wrote:Sorry, Liutauras, but the names are supposed to help the reader understand the idea being represented in the code.

Good grief, I was really that terrible in representing my question.

How about now?
21 hours ago

Liutauras Vilda wrote:If to pass just parsed JsonObject and later extract attributes in the same way as in Version1, then again, Version2 looks somewhat more complicated to me with not much benefit.

Over here I had in mind this, and this is probably what Stephan suggested in his initial reply

Reading all replies once again...
21 hours ago
Probably I also need to consider the difference between the versions, that:

Version1 extracts the attribute/-s upon the need, while Version2 would extract them during Json string parsing if I decided to construct object with extracted and ready to use all attributes which are passed to a constructor.
21 hours ago
Well, even as for an example I should have better reflect data types and better mimic actual cases. My apologies.

The parameter which is named as textToParse is actually a JSON string, which gets parsed into a JsonObject. Later on this object is meant to be used to extract various attribute-value pairs.

So the revised versions to reflect better actual scenario would look like:

The thing is liked about the Version1 is, that regardless of how JSON object will grow in a future, the change is just the matter of adding extra getter.

In case of Version2, there would be a need to modify private constructor, add extra field, add getter if the arguments would be passed after they get extracted. If to pass just parsed JsonObject and later extract attributes in the same way as in Version1, then again, Version2 looks somewhat more complicated to me with not much benefit.

I hope now I was a bit clearer. However, please ignore variables naming as well as lack of validation - I just took these out of my head to visualise idea.
21 hours ago
Hello, a small dilemma, which version do you prefer? Why? Know any situations where one has advantages/disadvantages over the other?

Mock simplified examples:

The use of each.



Thank you for insights.
1 day ago

Junilu Lacar wrote:If instead I just simply convert the null reference into some default value, the mistake will be masked.

About this thing I was thinking yesterday in a bed. Actually it was mentioned here almost exactly what I wanted to write this morning (time zones may differ).

As an addition I came up in my mind with word "metadata". null does not carry any metadata, so indeed, one can't figure out whether it was intentionally passed or in fact was a programming mistake passing a null as argument. I'd say it applies same passing to constructors or methods. Probably at most what you can give is 50/50 if you need to define some odds whether program "works" correctly or not. Didn't use word "behaves", because it does exactly what the programmer tells program to do, so it does behave correctly - and that is the most unfortunate thing in my opinion, you no longer can be certain about the correctness of your program.
5 days ago

original code wrote:

I won't tell anything useful, but want to point out, what is mostly confusing about this code is to me as a user.

If project is null, it takes the parameter variable (copy of originally passed argument reference which appear to be null), initializes it, and later assigns it to member field project and right after, itself goes out of scope.

So, what we end up with is, that originally passed, as argument project, still remains as null at the caller level... oh, will stop right here.

If I'd need to stick with these semantics code, much clearer for my brains to parse it would be such version:

Subtle difference, but leaves less questions in my head which would have been, such as: what is the project passed as argument is referring to now? (it would be still null as Java is "pass by value", but might be confusing to some readers).
5 days ago

Enissay Dave wrote:Does grade matter ?  Since it's not included in your certificate, I guess the one shouldn't spend a lot of time in preparation... What do you think ?

Sounds like you need a paper, not the knowledge. Unfortunately, but many students think the same way also about the university degrees. I prefer knowledge if you ask me - so it does matter!
Hi Nexas, a warm welcome!
1 week ago

Jeanne Boyarsky wrote:When you get the book, you'll see it recommends this site .

So you say at the end of the day Nik had no other available options as just to end up here?
1 week ago