|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On November 22 2012 10:09 Craton wrote:I'm having issues with deserializing some json with C#. Suppose this is a snippet of the json I'm being sent (repeated many times, but nothing else other than id/name): [ { "id":0, "name":"N/A" }, { "id":1, "name":"Annie" }, { "id":2, "name":"Olaf" } ] If the top level was named, I'd do something like [DataContract] public class ChampList { [DataMember(Name = "SOMENAME")] public ElophantChamp[] ElophantChamps { get; set; } }
[DataContract] public class ElophantChamp { [DataMember(Name = "id")] public int ID { get; set; }
[DataMember(Name = "name")] public string Name { get; set; }
} and then deserialize it by calling this: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse();
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ChampList)); object objResponse = jsonSerializer.ReadObject(response.GetResponseStream()); ChampList jsonResults = objResponse as ChampList; But in the case where there is no top level container object and I can't have blank datamember name, what do I do? I just get a null value if I leave the DataMember unnamed (i.e. leave it as [DataMember])
Why do you need ChampList? Just deserialize straight into List<ElophantChamp> . It's better to use List instead of Arrays so you get all the features of IList and Linq.
|
Couldn't figure out a way to do that.
[Edit] I got help elsewhere.
The only change needed was:
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ElophantChamp[])); object objResponse = jsonSerializer.ReadObject(response.GetResponseStream()); ElophantChamp[] jsonResults = objResponse as ElophantChamp[];
Basically all that was needed was to use the underlying class (ElophantChamp) and then declare the type used in the serializer as an array of that underlying class.
Thank you to ninjamyst for attempting to help.
|
Hi TL programmers.
I have a big project in mind and I didn't know who I should turn to to ask questions about "where to start". Here is a short intro of me.
I am a 22 years old man that finish CEGEP in web programming / design (CEGEP is between university and high school). I just started university in computer engineer. I have a good project in mind however I need a low level language to achieve my goal.
After some research, I found out that C++ was the way to go. So I took a 10h tutorial on Lynda.com but that didn't really help me. It was more about what are types, how to declare a functions, and what a statement is. So i kept reading tutorials doing quiz here and there. The more I get into C++ the more loss i get. I feel like there is so much to know at the same time. So many way to acheive an objective and I'm never sure about what is the most effective way to handle my problem.
So basically i need some help about either a great book or so clever example to help me master all the native method that C++ offers.
|
On November 22 2012 14:53 Craton wrote: I wouldn't have to grumble over non-answers if they were actual answers.
It took three posts just to force an angry reply out of you that what I'm using MIGHT not be able to do what I want. Instead, you got up on your "look at how great this thing I prefer is, change all your code to suit my personal preference" why? "because I personally feel the thing you're using is shit, but I'm not going to bother actually trying to help you"
If you don't want people getting "uppity," then provide actual answers. Exponentially so when I came out and explicitly said all I want to know is what I have to tweak and then got the exact same kind of non-answer. I said nothing about my personal opinion. I specifically said that the library was shit, and recommended you use Json.NET. I think you'd find it easier and more accurate to simply click the 'Quote' link above my post next time instead of completely misquoting me and misrepresenting what my post said.
Its not anyone's fault here but your own that you continually make horrible development choices, and you shouldn't be so pissy when someone points them out. You should notice that out of all the people that ask questions in here, you're the only one who consistently gets responded to with the sorts of answers you're bitching about (and you're also certainly the only one who bitches about people helping you in their free time when they could be off not assisting morons). You should think about that for a bit, and realize that you're the problem here, not anyone who has tried to help you. I would appreciate it if you would stop visiting this thread.
|
It's your own lack of comprehension that's getting you so angsty. You're welcome to leave at any time.
You told me to change all my code to support something else. I told you no, that I merely needed assistance finding what EXTREMELY MINOR mistake I had and have no interest in changing everything to support a new library at the last minute. That you think this is a "horrible development choice" is hilarious in and of itself, especially since you know absolutely jack shit about the size or scope of this project, but you assumed with tinted lenses nonetheless. At no point did you ever try to answer my actual question nor provide any backing whatsoever to your claims of how "bad" what this library is.
Someone else then came not 10 minutes later and repeated the exact same call to use a THIRD library, when I'd already expressly said that's not my question nor something I want, which is what I replied to. It's extraordinarily frustrating to have people continually ignore your actual question and respond with information you've said you don't want. But you were already off making assumptions and beginning your tirade.
You then got up on your high horse and went to ego-town and have continued to do so.
Despite all your ramblings and claims of how terrible this library is and how it can't even do what I want, it took not 5 seconds to make the adjustment I needed (read: what I had asked for multiple times). If I was looking for a "better" library or way to rewrite something, I would ask. My project is an extremely small personal one used only by myself and one other person; I have absolutely no need to rewrite swaths of code for trivial performance gains. Perhaps next time you should consider getting less inflamed over having a non-answer refused and spare us your childish ad hominems.
|
On November 22 2012 15:08 Datz2Ez wrote: Hi TL programmers.
I have a big project in mind and I didn't know who I should turn to to ask questions about "where to start". Here is a short intro of me.
I am a 22 years old man that finish CEGEP in web programming / design (CEGEP is between university and high school). I just started university in computer engineer. I have a good project in mind however I need a low level language to achieve my goal.
After some research, I found out that C++ was the way to go. So I took a 10h tutorial on Lynda.com but that didn't really help me. It was more about what are types, how to declare a functions, and what a statement is. So i kept reading tutorials doing quiz here and there. The more I get into C++ the more loss i get. I feel like there is so much to know at the same time. So many way to acheive an objective and I'm never sure about what is the most effective way to handle my problem.
So basically i need some help about either a great book or so clever example to help me master all the native method that C++ offers. http://www.amazon.com/Primer-5th-Edition-Stanley-Lippman/dp/0321714113/ref=sr_1_5?ie=UTF8&qid=1353566261&sr=8-5&keywords=C++
Best book out right now IMO. Using it right now and I'm learning really fast and thoroughly. Blasting through it and I'm learning the more advanced stuff right now.
It's even updated for the latest C++11 stuff. Just brilliant.
|
Remind me on Monday and I'll be able to get the name of another good book.
|
Learning to assume that other people are right and working back through their logic instead of assuming that I'm right and trying to go from there has been the most valuable thing I've learned so far working in software development. Time and time again it has gotten me to quicker, cleaner, and easier to extend solutions, simply by taking the effort to figure out exactly why what someone was recommending is a good idea (or if it turns out to be a shitty idea, making absolutely sure it is). Even if that means re-writing something I just spent 60+ hours on. Really does suck when it comes down to that, but it's almost always just my fault for not fully figuring out the design and not enough talking with other people before I dove into coding.
The sooner you start coding, the longer it takes to write a program that works. (- Nell Dale)
Which is an excellent segue to:
On November 22 2012 15:08 Datz2Ez wrote:Hi TL programmers. + Show Spoiler [rest of post] +I have a big project in mind and I didn't know who I should turn to to ask questions about "where to start". Here is a short intro of me.
I am a 22 years old man that finish CEGEP in web programming / design (CEGEP is between university and high school). I just started university in computer engineer. I have a good project in mind however I need a low level language to achieve my goal.
After some research, I found out that C++ was the way to go. So I took a 10h tutorial on Lynda.com but that didn't really help me. It was more about what are types, how to declare a functions, and what a statement is. So i kept reading tutorials doing quiz here and there. The more I get into C++ the more loss i get. I feel like there is so much to know at the same time. So many way to acheive an objective and I'm never sure about what is the most effective way to handle my problem.
So basically i need some help about either a great book or so clever example to help me master all the native method that C++ offers. Do you have lots of previous programming experience, and just need a solid c++ reference? If so there's a few links in the OP of this thread that could probably help you. If you need a text, something like this is probably a good buy:
http://www.amazon.com/dp/0201700735
If you've never really used C or C++ at all, something like Learn <X> the Hard Way may help you out more than a straight text: http://c.learncodethehardway.org/book/ or maybe this, if you know the basics already: http://www.amazon.com/dp/0763771562
In the end, the only way you're going to learn C++ is by writing a crap ton of C++.
|
On November 22 2012 15:47 phar wrote: Learning to assume that other people are right and working back through their logic instead of assuming that I'm right and trying to go from there has been the most valuable thing I've learned so far working in software development. Time and time again it has gotten me to quicker, cleaner, and easier to extend solutions, simply by taking the effort to figure out exactly why what someone was recommending is a good idea (or if it turns out to be a shitty idea, making absolutely sure it is). Even if that means re-writing something I just spent 60+ hours on. Really does suck when it comes down to that, but it's almost always just my fault for not fully figuring out the design and not enough talking with other people before I dove into coding. I agree. As an example, I've rewritten my current program twice for the sake of learning and improving and have plans to do it again in the future. I think new developers find that just about everyone has spent time writing and rewriting large amounts of code, if not entire programs from scratch just for the sake of figuring things out and getting better.
I would definitely never assume others are right, though. That's always a disaster waiting to happen. You should take what anyone says with a many grains of salt and do more research on it.
Connecting to the earlier conversation, though, I'll point out that using one library vs another doesn't really teach you much, even though it can take significant amounts of time to recode. I certainly agree that it's worth being familiar with the different solutions, just budget your time on areas where you actually need improvements (be it for performance, maintainability, shoring up ignorance, etc.)
|
Stroustrup's book is really outdated right now I think. Covers only C++98 which means you're learning some obsolete/deprecated things, missing important features. New edition in feb. though.
|
On November 22 2012 16:10 Fyodor wrote: Stroustrup's book is really outdated right now I think. Covers only C++98 which means you're learning some obsolete/deprecated things, missing important features. New edition in feb. though.
The C++ Programming Language, 4th Edition is about to be released, which would be the quasi-official C++11 reference.
Programming: Principles and Practice Using C++ will probably be updated after the reference book is released. If you are looking for official recommendations then you could look at http://isocpp.org/ which is a fairly new website by the standards body.
|
On November 22 2012 16:09 Craton wrote:Show nested quote +On November 22 2012 15:47 phar wrote: Learning to assume that other people are right and working back through their logic instead of assuming that I'm right and trying to go from there has been the most valuable thing I've learned so far working in software development. Time and time again it has gotten me to quicker, cleaner, and easier to extend solutions, simply by taking the effort to figure out exactly why what someone was recommending is a good idea (or if it turns out to be a shitty idea, making absolutely sure it is). Even if that means re-writing something I just spent 60+ hours on. Really does suck when it comes down to that, but it's almost always just my fault for not fully figuring out the design and not enough talking with other people before I dove into coding. I agree. As an example, I've rewritten my current program twice for the sake of learning and improving and have plans to do it again in the future. I think new developers find that just about everyone has spent time writing and rewriting large amounts of code, if not entire programs from scratch just for the sake of figuring things out and getting better. I would definitely never assume others are right, though. That's always a disaster waiting to happen. You should take what anyone says with a many grains of salt and do more research on it. Connecting to the earlier conversation, though, I'll point out that using one library vs another doesn't really teach you much, even though it can take significant amounts of time to recode. I certainly agree that it's worth being familiar with the different solutions, just budget your time on areas where you actually need improvements (be it for performance, maintainability, shoring up ignorance, etc.) You certainly *don't* get it, or you wouldn't have ever responded in the way you did. Its quite clear from all of your posts here that you would rather have crappy code that inexplicably works than something clean, succinct, and maintainable. Learning and improving isn't about continually rewriting the same piece of code over and over again, its about giving a fuck and looking for ways you can improve it while you're doing it. Its about being completely willing to get halfway through a project and say, "Hey, this part really sucks. I'm gonna throw that out and write something better."
You shouldn't assume people are 100% right, but you should learn to find value in things people tell you instead of just floccinaucinihilipilificating them away. You're acting like an arrogant, entitled prick in this thread, as if you own everyone else's time and efforts. No one owes you shit. The fact that your previous fix took you "five seconds" just means that you value your five seconds higher than everyone else's five minutes, because you decided to ask here and waste our time before trying out a simple fix. Doesn't that seem a tad entitled to you?
I never told you to rewrite your entire application, I told you to use a different serializer library. Your application code shouldn't be coupled to that anyway, and it would have seriously been a matter of adding a new import and replacing the already non-working deserialization code with the Json.NET equivalents. If you had actually considered my suggestion, you might have realized that, but of course your time is worth infinitely more than mine so you just dismissed it out of hand.
Now, I'll ask you again, please leave this thread and never come back. You provide no value here. No one should want to take your suggestions or advice because you clearly take no pride in your craft, and don't seek to improve it; and when you ask questions? Well we've all seen how that turns out.
|
Zurich15307 Posts
Hey guys, maybe you can give me some ideas how to approach this:
I have a black box backend system that dynamically generates HTML forms. As far as I can tell it's J2EE with Struts 1. I have access to the JSP files, but I am asked to change as little as possible.
The generated forms have an auto-save functionality (all in Javascript) that basically just invokes a struts action to save the form in regular intervals. The change they want is to only trigger the auto-save when there has actually been a change since the last auto-save.
Ideally I would do this all in newly introduced Javascript, with only a few lines changed in the existing auto-save Javascript functionality.
My current approach is to dynamically add event listeners to all generated form elements. They would change a global variable on the change event. The autosave function would check if that variable has been changed before submitting.
Does this sound good? I vaguely remember that "change" doesn't capture all changes for all form elements. I might be wrong (or maybe it's only in IE?). Does it fire for changes on the value that are done by Javascript and not user interaction? Also needs IE < 9 compatibility so I am aware I need to write some of the code twice.
|
On November 22 2012 18:38 zatic wrote: My current approach is to dynamically add event listeners to all generated form elements. They would change a global variable on the change event. The autosave function would check if that variable has been changed before submitting.
Does this sound good? I vaguely remember that "change" doesn't capture all changes for all form elements. I might be wrong (or maybe it's only in IE?). Does it fire for changes on the value that are done by Javascript and not user interaction? Also needs IE < 9 compatibility so I am aware I need to write some of the code twice.
Will you be able to use 3rd party libraries like jquery? This would solve you compatibility problems. Also with it's selectors it will be quite easy to install your event-handler on all relevant elements. See: - http://api.jquery.com/change/ - http://api.jquery.com/category/selectors/
Depending on your specification "change" might be the right solution. Change is only fired on text-input-elements, when they lose focus. So if you need to save "unfinished" text-elements, change might not be what you are looking for.
|
On November 22 2012 18:38 zatic wrote: Hey guys, maybe you can give me some ideas how to approach this:
I have a black box backend system that dynamically generates HTML forms. As far as I can tell it's J2EE with Struts 1. I have access to the JSP files, but I am asked to change as little as possible.
The generated forms have an auto-save functionality (all in Javascript) that basically just invokes a struts action to save the form in regular intervals. The change they want is to only trigger the auto-save when there has actually been a change since the last auto-save.
Ideally I would do this all in newly introduced Javascript, with only a few lines changed in the existing auto-save Javascript functionality.
My current approach is to dynamically add event listeners to all generated form elements. They would change a global variable on the change event. The autosave function would check if that variable has been changed before submitting.
Does this sound good? I vaguely remember that "change" doesn't capture all changes for all form elements. I might be wrong (or maybe it's only in IE?). Does it fire for changes on the value that are done by Javascript and not user interaction? Also needs IE < 9 compatibility so I am aware I need to write some of the code twice. Would you be allowed to use jQuery? Because from my experience, jQuery tends to standardize actions like that, so it's possible that the jQuery "change" event includes more actions than the "default" one.
|
On November 22 2012 18:38 zatic wrote: Hey guys, maybe you can give me some ideas how to approach this:
I have a black box backend system that dynamically generates HTML forms. As far as I can tell it's J2EE with Struts 1. I have access to the JSP files, but I am asked to change as little as possible.
The generated forms have an auto-save functionality (all in Javascript) that basically just invokes a struts action to save the form in regular intervals. The change they want is to only trigger the auto-save when there has actually been a change since the last auto-save.
Ideally I would do this all in newly introduced Javascript, with only a few lines changed in the existing auto-save Javascript functionality.
My current approach is to dynamically add event listeners to all generated form elements. They would change a global variable on the change event. The autosave function would check if that variable has been changed before submitting.
Does this sound good? I vaguely remember that "change" doesn't capture all changes for all form elements. I might be wrong (or maybe it's only in IE?). Does it fire for changes on the value that are done by Javascript and not user interaction? Also needs IE < 9 compatibility so I am aware I need to write some of the code twice. Change will fire only on user-made changes, not stuff done through JavaScript (if you want them to fire from JavaScript changes, you have to trigger the event yourself). You shouldn't need to add an event handler on every form element, a single event handler at the form level should work fine since all the events on the inputs will bubble up. Also keep in mind that a change event on a text box will only fire *after* the textbox has lost focus. So this can cause some problems if they can manually submit the form and you want to auto-save, because their submission will happen as you try to send the auto-save data and most browsers will cancel the AJAX request.
jQuery might make the compatibility for IE<9 easier, but other than that I think it would be straightforward without it.
|
@zatic
It's hard to know exactly what handlers would be necessary without knowing what sorts of "changes" are possible, and when exactly your global variable needs to be set (IE, if I'm in the process of typing in a field, should the text I'm typing be auto-saved?).
My instinct says that you should be able to use a single event handler bound to the keydown (assuming your forms contain text fields and you want to save in-progress changes) and change events. Like tec27 wrote, you shouldn't need to bind the handlers to every form field, just to the form itself, unless you have event handlers already in place that prevent the event from bubbling up.
Edit to add: You're out of luck as far as I know in terms of an event that will fire when content is changed via javascript. You'll either have to fire the events from the functions that make the changes or just set your global variable in those functions.
There is one idea that would let you do everything in a single function: Create a polling function that runs on load and every X ms therafter. It stores the values of every field in the form (conceivably you could just store formObj.innerHTML if it's not obscenely large) and if the values have changed, it sets your global variable.
|
Zurich15307 Posts
Thanks guys. "Change" should be enough, I won't need to keep entered but unfinished text elements before they change focus.
AmericanUmlaut: Yeah what I am afraid is that their UI uses tons of Javascript already and might do some of the changes to form elements programmatically. I'll know more when I am onsite.
The polling thing might actually run into performance issues as the forms that are generated are huge (take several hours to complete).
|
You shouldn't need to poll. The change event should do everything you need.
|
On November 22 2012 16:09 Craton wrote:I would definitely never assume others are right, though. That's always a disaster waiting to happen. You should take what anyone says with a many grains of salt and do more research on it. Yea, I meant assume other people at my work are right, not in some random online forum. At work I'm surrounded by people who are significantly better than me at programming and smarter in general, so it's a pretty safe bet. Even if they do end up being wrong, I stand by what I initially said. It works more often than not to start from their position and go from there, working through the logic.
|
|
|
|