|
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.
|
|
|
|
|
Of the options provided so far, that gets my vote. And I'm too lazy to suggest my own.
|
|
|
|
|
#1
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
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.
|
|
|
|
|
trønderen wrote: that you couldn't afford it on a USD 1M budget
That is an interesting question.
I found it difficult to even find costs. Following might explain that.
The American Film Industry in the Early 1950s | Encyclopedia.com[^]
Look for the section that say the following
"In a period of marginal profits, the control of spending could be crucial to determining success or failure in a particular year."
That probably explains it. They wanted to get by as cheaply as possible.
Interesting that movie theaters by the numbers were going down in the 50s. Following chart at the end is interesting. You will need to zoom. Notice that attendance is down significantly even from WWII.
https://ecommons.udayton.edu/cgi/viewcontent.cgi?article=1023&context=pol_fac_pub[^]
|
|
|
|
|
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.
|
|
|
|
|
GKP1992 wrote: with JS are now avoidable when we use it a certain way.
Which of course works in a day zero startup with two programmers that have been working together for years.
With a 20 year old code base which has been worked on by more than 100 developers, each with their own preferences, it doesn't work out too well.
|
|
|
|
|
GKP1992 wrote: 7 years later I fully agree with him. Amen brother. IMO the biggest issue with JS is its popularity. You take any language on the planet and make it extremely popular and you're bound to have some people writing stupid code in it. That's not the fault of the language itself though; it's the fault of the "average" coder.
GKP1992 wrote: The callback hell can be avoided with the use of asynchronous programming. The whole reason callback hell even started (then went onto promise hell) was due to one of JavaScript's strengths. As you mentioned, most people just didn't know about JS's execution model and would rather insult than learn. But, because of the execution model, it's always been extremely hard to lock JS. Granted, people needed to learn how to deal with that or else they'd suffer race conditions, but peeps only had to take the time to learn the language. The same could be said of any language though. I'm not gonna learn Rust overnight.
GKP1992 wrote: 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. 100%. It's a language that's been evolving and will continue to evolve as it grows up, so to speak.
As it stands now, it's literally the fastest scripting language on the planet. It runs so fast it deserves its own category of scripting language. Sure, compared to C/C++ or Rust it's slower, but compared to Python, etc. none of them hold a candle to JS. And it has to be that way, it's the dynamic language of the Internet so a lot of time has been spent optimizing its execution engines.
Haters gonna hate though.
Jeremy Falcon
modified 12-Jun-24 23:12pm.
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|