|
honey the codewitch wrote: IT WORKED ON THE FIRST TRY. sits back and waits for Murphy's law* to strike
* If it worked at the first time, you did it wrong
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I did eventually find a very minor bug in it, but I fixed it.
What's funny is while I was building the code generation based on a reference implementation I made, I found a bug in the reference implementation in the process.
Though that never would have happened if I hadn't wrapped the CodeDOM.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I am Invincible! (YouTube)
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Most madmen think they are
|
|
|
|
|
honey the codewitch wrote: It generates a whole lot of really complicated code
That's the gold in the message.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I Am Inevitable[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Quote: IT WORKED ON THE FIRST TRY. The very first program I ever wrote which was on 31st May 1975 worked first time - it feels great doesn't it?
Congratulations!
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
I've done it before but maybe never with something this complicated. =)
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I'm replacing a ruby on rails site with C#/mvc. For the most part it's a complete rewrite because of problems with the site being scrapped. There're occasional parts where some logic is worth a directish port though. One is scoring standardized tests.
I've got a test responses table full of columns like:
Section1Question1Answer CHAR(1),
Section1Question2Answer CHAR(1),
...
Section1Question5Answer CHAR(1),
Section2Question1Answer CHAR(1),
Section2Question2Answer CHAR(1),
...
Section13Question5Answer CHAR(1),
The ruby code is then able to access the data like:
for section in 1..SECTION_COUNT
for question in 1..QUESTION_COUNT
test_to_score["Section{section}Question{question}Answer"] #do stuff
end
end
In C# I'm stuck with accessing them 1 at a time
TestToScore.Section1Question1Answer
TestToScore.Section1Question2Answer
I'm not doing enough processing for load/unloading temp arrays to be worthwhile, and every time I've thought to myself that reflection would be a good way to solve a problem I've ended up regretting it. Redoing the DB to store a single answer/row instead of a test attempt/row would just change where the pain points are; and since the test will always be M sections of N questions each keeping the entire response together is a lot simpler.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
Reflection.
Or put a reference to the fields, or whatever, into an array... and iterate.
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Did you read what I wrote to the end? Every time I've done reflection it ends up becoming a footgun at some point in the future; and for what amounts to a single pass over the scores loading/unloading into arrays is just as verbose as accessing everything once directly.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
My first was "reflection" as well, but then I read what you wrote at the end
I don't think reflection could hurt here though.
It's just a small piece with a clear function.
It wouldn't be much different than how Ruby solves it, which is calling the member using a literal string.
It could go wrong if your naming convention changes or if someone added QuestionXSectionYAnswer (switching Question and Section), but that goes for the Ruby code as well.
|
|
|
|
|
Sander Rossel wrote: It wouldn't be much different than how Ruby solves it, which is calling the member using a literal string.
I know the feature in ruby works because its hashes all the way down (until you get to the pipe were the designers smoke it anyway); but the hackiness there is a core language feature not a gun that shoots bullets in multiple directions with every trigger pull only more dangerous.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
I see your point, but I'd still recommend reflection.
Although typing out this stuff once isn't such a big deal either.
writing a reflection solution probably costs you as much time as writing it out.
The only reason to use reflection is because it's more fun to write
|
|
|
|
|
I generated the 1 off code. Used a mix of typing and excel copydown to generate the numbers and then regexed the code I wanted out.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
|
Or start with an array?
Section1Answers VARCHAR(N)
Then just parse/count and iter. Less of a mess in the DB?
|
|
|
|
|
Maybe. Not sure what he's trying to accomplish. Maybe a table with question and answer columns?
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
Quote: Section1Question1Answer CHAR(1),
Why can't you do a table with:
SectionNumber int
QuestionNumber int
Answer char(1) ?
|
|
|
|
|
Way too much refactoring for the potential benefit; even before data migration and fighting with a CI system that chokes on anything it thinks might be a lossy DB change (a separate issue entirely).
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
Or you could go old school - DataTable!
table.Columns[$"Section{section}Question{question}Answer"]
|
|
|
|
|
If this thread does not end up in a lecture about the billionth other possibilities how you could have done it better in C#, this is not a coding forum anymore.
I love this kind of threads:
Q: "- Hey guys, I am using X to do Y, and I would need to know how I could do Z"
A1:"- Why are you using X to do Y ? W is much better".
A2:"- Wow, I would never use X that way. Plus Y is not recommended by [book you have never heard of, but obviously should have]. Maybe you should consider switching technologies"
...
A187273:"- No wonder that we have flat-earthers bitching about global warming criticizing vegans that do not believe in the moon landing if you do Y by using X".
|
|
|
|
|
Do not discount Reflection solely based on the fact that you weren't able to make good use of it previously. It has amazing powers but should not be your first choice, usually.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Before I submit this Tip thing, I wanted to know among people that have used the codeDom, if they'd prefer something like this?
var result = CD.Method(typeof(bool), "MoveNextInput");
var input = CD.FieldRef(CD.This, "_input");
var state = CD.FieldRef(CD.This, "_state");
var line = CD.FieldRef(CD.This, "_line");
var column = CD.FieldRef(CD.This, "_column");
var position = CD.FieldRef(CD.This, "_position");
var current = CD.PropRef(input,"Current");
result.Statements.AddRange(new CodeStatement[] {
CD.If(CD.Invoke(input,"MoveNext"),
CD.IfElse(CD.NotEq(state,CD.Literal(_BeforeBegin)), new CodeStatement[] {
CD.Let(position,CD.Add(position,CD.One)),
CD.IfElse(CD.Eq(CD.Literal('\n'),current),new CodeStatement[] {
CD.Let(column,CD.One),
CD.Let(line,CD.Add(line,CD.One))
},
CD.IfElse(CD.Eq(CD.Literal('\t'),current),new CodeStatement[]
{
CD.Let(column,CD.Add(column,CD.Literal(_TabWidth)))
},
CD.Let(column,CD.Add(column,CD.One))))
},
CD.IfElse(CD.Eq(CD.Literal('\n'),current),new CodeStatement[] {
CD.Let(column,CD.One),
CD.Let(line,CD.Add(line,CD.One))
},
CD.IfElse(CD.Eq(CD.Literal('\t'),current),new CodeStatement[] {
CD.Let(column,CD.Add(column,CD.Literal(_TabWidth-1)))
}))),
CD.Return(CD.True)),
CD.Let(state,CD.Literal(_InnerFinished)),
CD.Return(CD.False)
});
I know it looks like hell, but it's so much less verbose than using the raw object model
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
meh
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|