|
this_guy_tho.jpg[^]
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
I'm creating a data bank of MCQ (Multi Choice Questions) and their answers so that an app can be built around it. Regarding the actual storage format, I have two ideas:
- An array of objects with keys (
q for question, a for choice-a, etc.). - An array of arrays.
The first one is obviously more readable. Here is a brief sample of what I have so far:
{
"data": [
{
"q": "What kind of language is Python?",
"a": "Compiled",
"b": "Interpreted",
"c": "Parsed",
"d": "Elaborated",
"r": "b"
},
{
"q": "Who invented Python?",
"a": "Rasmus Lerdorf",
"b": "Guido Van Rossum",
"c": "Bill Gates",
"d": "Linus Torvalds",
"r": "b"
}
]
}
The app will read the q key to print the question, then present the four options (a, b, c and d). And the last key (r) will store the right answer. This is very much readable when viewed as a JSON file also. However, what I am thinking is that once the data-bank grows in size into hundreds/thousands of QA, a lot of space will be wasted by those keys (q,a,b,etc.) isn't it? In this case, an array like this is more efficient from storage perspective:
{
"data": [
[
"What kind of language is Python?",
"Compiled",
"Interpreted",
"Parsed",
"Elaborated",
1
],
[
"Who invented Python?",
"Rasmus Lerdorf",
"Guido Van Rossum",
"Bill Gates",
"Linus Torvalds",
1
]
]
}
In this case, each array will have 6 items viz. the question, four choices and finally the index of the correct choice (1==Interpreted, etc.).
Which of these two formats is better? Feel free to suggest any third format which is even better than these two.
|
|
|
|
|
I like the 1st better.
The 2nd, for me anyway, would be harder to keep track of square brackets.
If you can't find time to do it right the first time, how are you going to find time to do it again?
PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com
Latest Article: EventAggregator
|
|
|
|
|
|
First, the question should probably be asked in "Design&Architecture[^]" forum.
Second, my preference would be for something like:
{
"data": [
{ "q": "question",
"a": ["answer1", "answer2",...],
"ok": 1
},
...
]
}
---
Edit: My suggestion allows you to have a variable number of answers to each question. Not sure if it's important or not for your application.
Mircea
|
|
|
|
|
Neither. Unless your married to the idea of encoding the indexing, I'd go with something like this personally based on the info given:
{
data: [
{
"question": "What kind of language is Python?",
"answers:": [
{ "answer": "Compiled", "correct": false },
{ "answer": "Interpreted", "correct": true },
{ "answer": "Parsed", "correct": false },
{ "answer": "Elaborated", "correct": true }
]
},
{
"question": "Who invented Python?",
"answers": [
{ "answer": "Rasmus Lerdorf", "correct": true },
{ "answer": "Guido Van Rossum", "correct": false },
{ "answer": "Bill Gates", "correct": false },
{ "answer": "Linus Torvalds", "correct": false }
]
}
]
}
Handles questions with multiple correct answers, and both questions and answers are easily expandable without breaking backwards compatibility. The biggest issue with your options is that the moment the requirements change (and requirements /always/ change) the format is going to get mangled in a non-backwards-compatible way. Your current format cleverly avoids objects/properties to save space by treating the head and tail of each array uniquely. What happens when requirements dictate that relationship can no longer hold? For example, questions with multiple correct answers. Cleverness is an avoidable dependency, so unless space is that critical of an issue I would tend to go with the more flexible option that gives me less headaches down the road.
|
|
|
|
|
I read the thread in The Insider News tracking off to the novel 'When Worlds Collide', and looked up the 1951 movie adaptation at IMDb, curious to see if they had made the movie in color or B/W. The movie is in color - but the 1954 ad poster reproduced in Wikipedia, as well as all the photos from the movie shown at IMDb is is in black and white.
Why is that? Was is really that much more expensive in 1951 / 1954 to make color photo prints and color ad posters that you couldn't afford it on a USD 1M budget (note that this is 1 mill 1951 USD!)? Or is there some other plausible explanation?
According to IMDb, the movie won an Oscar for Best Special Effects. The trailer (available at IMDb) suggests that the Oscar was well deserved, especially for a movie released 73 years ago!
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
trønderen wrote: the 1954 ad poster reproduced in Wikipedia, as well as all the photos from the movie shown at IMDb is is in black and white. That's odd - the Wiki Page I found has a colour poster: When Worlds Collide (1951 film) - Wikipedia[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Scroll down to the Production heading. To the right is a B/W Drive In poster.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
Perhaps the OP has a black and white monitor... His profile pic is black and white, too.
Will Rogers never met me.
|
|
|
|
|
I remember it well! Great movie! And yes, the cost of color printing was quite high compared to black and white. Since most people didn't have color TVs until the early 1970s, we were quite used to seeing things in black and white.
Will Rogers never met me.
|
|
|
|
|
Well, George Pal was involved so the Special Effects award shouldn't have been too much of a surprise.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
I’m begging you for the benefit of everyone, don’t be STUPID.
|
|
|
|
|
See title
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|
|
This is almost exactly the same question I asked here in the Lounge about 7 years ago. I was struggling with something and it wasn't working as I expected it to and hence the frustration.
@JeremyFalcon gave a really good response to that question and 7 years later I fully agree with him.
Most of the hate JS gets is from people who are new to it, and probably have an expectation of how it would/should work. When it does not (and not always due to a straight forward reason) it gets frustrating.
Historically JS has been riddled with issues. It still is. But over the years most of the major issues with JS are now avoidable when we use it a certain way.
For example, the global namespace pollution has been a major issue causing countless production bugs which can be avoided with the use of JS modules or IFFEs.
The callback hell can be avoided with the use of asynchronous programming.
As people get more experienced with JS they become more accepting of it's quirks and manage to avoid it's pitfalls while being able to produce robust production ready code.
|
|
|
|
|
I think part of it is lingering feelings from way, way back when when every browser had their own implementations of certain features which meant that building any sort of platform that was going to work cross-browser was a major headache.
I remember adopting MooTools because it offered cross-browser AJAX support, then obviously jQuery when it came along with it's own solutions. These days most JS functions are normalised (ie. the fetch API) but there's a lot of salt in the wounds that can't be cleaned so easily.
|
|
|
|
|
I'm learning it just now, new job needs it. My biggest gripe is lack of typing of variables. I would like to know what kind of value, object, etc I can pass into a function.
Okay, I do like that they are called functions rather than methods. Cut my teeth on C and then Delphi (which had both functions and procedures) but it rankled me for the 10+ years I worked in Java that I had to say method.
Javascript does have something akin to function pointers, which is a nice throwback to C.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
I’m begging you for the benefit of everyone, don’t be STUPID.
|
|
|
|
|
MarkTJohnson wrote: My biggest gripe is lack of typing of variables.
Typescript to the rescue ![Smile | :)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Erm ... JS has both methods and functions - the former operate on object data (as per C#) the later are procedural and don't (as per C)
The difference in name is important because it tells you what you can do with a bit of code - that's why Java insists on method to differentiate it from the more primitive function you were used to in C.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: that's why Java insists on
Tut tut!
Java ≠ JavaScript.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Quote: ... it rankled me for the 10+ years I worked in Java that I had to say method.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Like I said, learning. Haven't gotten to that stuff yet.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
I’m begging you for the benefit of everyone, don’t be STUPID.
|
|
|
|
|
OriginalGriff wrote: to differentiate it
One thing I disliked about Pascal is that it has Function and Procedure distinguished by keyword -- I prefer that C and its ilk don't, and have no keywords for those concepts.
I can understand why SQL does things more differentlier, and that's OK.
|
|
|
|
|
PIEBALDconsult wrote: differentlier
Word of the day.
|
|
|
|
|
JavaScript is fine - I used in in various incarnations and Typescript definitely helps write cleaner code.
I heard Bob Martin point out that the evolution of programming languages is an evolution in constraining what you can do, each programming language constraining you in a different manner.
JavaScript is perhaps a bit of a exception in that it's fairly loose with its constraints which is why something like TypeScript makes sense as it brings static typing with it.
I still get caught out occasionally with the asynchronous nature of JavaScript but other than that I think it's fine when used well.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Javascript is great!..but I've been using it for 24+ years, so I'm used to it. Combined with CSS and AJAX, and there's not a lot you can't do.
My gripe is that after all this time, it's still a PITA to debug in Visual Studio. (probly cause I use master pages)
I still rely on the tried and true alert(whatami); debugging method.
"Go forth into the source" - Neal Morse
"Hope is contagious"
|
|
|
|
|