|
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 August 24 2013 05:31 Yoshi- wrote: That seems to be way too hard and is pretty much useless tbh, you should maybe focus on something that not that "impossible" I was thinking of writing each line to a file (dummy file?) that looks like this on startup:
#include <stdio.h> int main() { /* lines from scanf go here */ return 0; } and then after each line, I can have a decision on what to/ if to print something. Then run a shell script to compile and run the "dummy program", and run the output to the main program. Is it that much more difficult than it seems? BTW this would only be for linux.
EDIT: guess this was all basically said already... But for the usability part, it seems to me to be a slightly easier way to learn operations and pointers. Would this be helpful for someone just starting or coming back to C? or would this be a waste of time :D
|
Well, normally how I would assume such an REPL system, is that it works like the one at codeacademy: www.codecademy.com
e.g. you write something like 5+5;(without print or something like that) and it would give you the result, so dunno if you can actually catch this properly
|
I did this for Java back when I was learning how to program, so its certainly not impossible, though still really difficult. You're effectively writing a virtual machine (which is great practice!).
Here's a short list of problems I had, and you would likely run into:
Variables are tough. I used a map, in Java, and you would have to make your own map or something similar using C, which isn't too tough. Figuring out the data structure was the easy part, the parsing and evaluating is the difficult part, as you have to decide something is a variable. Luckily, C is loosely typed, so that part is easy. Implementing structures is particularly a pain.
Allocation is really, really hard. You will have to manage your own heap.
Functions. Hard. You will have to manage your own stack as well.
Program control is nearly impossible without writing your own virtual machine to decide which line to run next. You're already effectively doing this if you implement your own heap and stack and I/O, so adding on PC control ain't so bad comparatively.
Plus, you have to be able to parse and evaluate calculations. <---- I would start with this step, then add variables, then add arrays, then add if()/else+while/for.
This is all assuming you want your REPL to have memory, etc...
|
Hey, maybe you guys have a better solution for the following task than me:
Names in brackets are for explanatory reasons. I have a cpp std::map that maps a struct containing a std::string("first1") and an unsigned int("first2") to another unsigned int("second"). Now I have to find out for every entry if there is another entry(and how many) that has the same "first2" and also the same "second". Note that the map contains several thousand entries but only very few of them will share "first2" and "second", maybe even none. My idea would be to iterate over the std::map and create another map while doing it. This map would map a struct containing "first2" and "second" to "first1". I guess this is a fairly tolerable solution, but I already grumbled about the excessive use of std::maps(most of the code leading to this problem was not written by me) so using another one to solve the problem is a little problematic :D
Maybe one of you knows some awesome way to do this. Btw, everyting of the boost library can be used
|
On August 26 2013 19:00 KainiT wrote:Hey, maybe you guys have a better solution for the following task than me: Names in brackets are for explanatory reasons. I have a cpp std::map that maps a struct containing a std::string("first1") and an unsigned int("first2") to another unsigned int("second"). Now I have to find out for every entry if there is another entry(and how many) that has the same "first2" and also the same "second". Note that the map contains several thousand entries but only very few of them will share "first2" and "second", maybe even none. My idea would be to iterate over the std::map and create another map while doing it. This map would map a struct containing "first2" and "second" to "first1". I guess this is a fairly tolerable solution, but I already grumbled about the excessive use of std::maps(most of the code leading to this problem was not written by me) so using another one to solve the problem is a little problematic :D Maybe one of you knows some awesome way to do this. Btw, everyting of the boost library can be used  Since you want the answer for every string, you're going to need to use a dictionary of some sort. A map is good. You're only going to need two maps in total, and you're only going to need one iteration through the first map. A well implemented map will be able to do this in O(n) time. Insertion into your new map will require O(nlogn) if it's a BST which normal maps usually are, but O(n) if it's a hashmap.
|
Hey guys, I might be desperate for help =) I just received a programming assignment for Logical Programming, SWIPL Prolog. There is a LOT riding on this assignment for me, and I'm about to get started. Is there anyone here who happens to be familiar with Prolog? I understand that this is a fairly desperate bid, but I guess that's sort of what I am =)
|
Hello. Im trying to make program using C#, windows forms, ms server, entity framework. Here is a problem.. I have quite complicated data structure (List of dictionaries with another lists inside and so on..), user fills this structure by completing multiple forms and press submit in the end. At that time i need to take this structure and write it into database which spreads all this information into around 10 tables. If some errors happens (like foreign key problems) while inserting data, all previously written data must be deleted, in other words, all 10 tables must be filled correctly on none at all.
Currently i fill all data into entity model and call saveChanges() method ONCE, which puts data from model into DB afaik. Problem is that this makes dubugging almost impossible, because all crashes comes from calling saveChanges() and it's hard to say which part of filling my entity model is responsible for this error.
How should i deal with this? Im thinking about remaking it, so it would call saveChanges() by inserting small chunks of data into single tables and if, lets say it crashes on 10th table (10th saveChanges() call), some other code whould delete inserted data from another 9 already filled tables. What do you think about this idea? Or maybe there is some better way?
|
On August 27 2013 00:20 Utini wrote: Hello. Im trying to make program using C#, windows forms, ms server, entity framework. Here is a problem.. I have quite complicated data structure (List of dictionaries with another lists inside and so on..), user fills this structure by completing multiple forms and press submit in the end. At that time i need to take this structure and write it into database which spreads all this information into around 10 tables. If some errors happens (like foreign key problems) while inserting data, all previously written data must be deleted, in other words, all 10 tables must be filled correctly on none at all.
Currently i fill all data into entity model and call saveChanges() method ONCE, which puts data from model into DB afaik. Problem is that this makes dubugging almost impossible, because all crashes comes from calling saveChanges() and it's hard to say which part of filling my entity model is responsible for this error.
How should i deal with this? Im thinking about remaking it, so it would call saveChanges() by inserting small chunks of data into single tables and if, lets say it crashes on 10th table (10th saveChanges() call), some other code whould delete inserted data from another 9 already filled tables. What do you think about this idea? Or maybe there is some better way?
That is one way of doing it, but I think an easier way is to call a stored procedure and let it do all of that work for you. Handling FK errors is a lot easier on the SQL side of things. Also, if there could potentially be an error when inserting, it really your job to handle the validation of the information before you try to insert. So have a call that validates, and if that is successful, then insert it into the DB.
|
First of all, if you have a "quite complicated data structure" you might want to try and make it less complicated. This isn't really related to obtaining debugging information, but if you find your own code complicated, debugging will always be hard.
I'm currently working on a program with a somewhat similar setup (C#, WPF, SQLCE, ADO.NET). I too am inserting a large chunck of complex (but not all that complicated) data at once. The last time I worked on the database part of the program is a bit ago already though, and I'm not terribly experienced with databases yet. Anyways, as far as I can remember, there usually was a decent hint in the stack trace whenever SaveChanges failed. It pretty much always was either a duplicate key or me failing to correctly update the data model after changing the database. (my memory about that is a bit hazy already; I'm busy with finite state machines now)
|
On August 27 2013 00:20 Utini wrote: Hello. Im trying to make program using C#, windows forms, ms server, entity framework. Here is a problem.. I have quite complicated data structure (List of dictionaries with another lists inside and so on..), user fills this structure by completing multiple forms and press submit in the end. At that time i need to take this structure and write it into database which spreads all this information into around 10 tables. If some errors happens (like foreign key problems) while inserting data, all previously written data must be deleted, in other words, all 10 tables must be filled correctly on none at all.
Currently i fill all data into entity model and call saveChanges() method ONCE, which puts data from model into DB afaik. Problem is that this makes dubugging almost impossible, because all crashes comes from calling saveChanges() and it's hard to say which part of filling my entity model is responsible for this error.
How should i deal with this? Im thinking about remaking it, so it would call saveChanges() by inserting small chunks of data into single tables and if, lets say it crashes on 10th table (10th saveChanges() call), some other code whould delete inserted data from another 9 already filled tables. What do you think about this idea? Or maybe there is some better way? One way to make this easier would be to put in as much validation handling as you can. If you can predict when an error will happen before making any commits and inform the user, that will go a long way towards solving any problems caused by user error.
For debugging purposes, are you wrapping your entire data commit in a transaction? I would highly recommend it, as it will save you the effort of having to build code to go back and undo what was done. After all, what would happen when the undo code fails? A transaction will take care of that for you.
I'm guessing saveChanges() is one single function that performs all the save work. What I have done in the past in cases like this is create a status string that I change during the workload depending on what work I'm doing, and if there is an error, I return the status. Here's an example:
string updateMessage;
Try
// Workload One updateMessage = "Workload One"; group of work
// Workload Two updateMessage = "Workload Two"; group of work
// Workload Three updateMessage = "Workload Three"; group of work
Catch ex as exception Message.Show("An error occurred during " + updateMessage);
End Try Obviously what you do with the error will be different, but hopefully you get the idea. The nice part about this is although you can't control what an error message looks like (a divide by zero error will always look the same no matter where in your code it happens), you can customize the updateMessage to look however you want at any stage during the work, so it will always be easy to know exactly where the error occurred (ctrl+f, baby!).
Of course, if you change it so that you are wrapping your entire data commit in one transaction, and the errors you anticipate will always be database errors, you'll have to approach it a bit differently. I would recommend logging the error along with the SQL that caused the error, and providing some means of getting that from the user to you so you can debug it.
|
for (Object o:oList) { o.do(); if (!o.enabled) oList.iterator().remove(); }
Why is this throwing an IllegalStateException?
|
Hello , i'm currently re-writing an image processing program i created using vc++ and matlab in c# and trying to implement the object-oriented paradigms correctly . My previous implementation was my first real and big programming experience and after spending the summer reading Design Patterns , Code Complete and Object Roles and Responsibilites i realized how bad my code structure/design/implementation was and decided to go at it again whilst using what i hopefully learnt.
The thing is i just cant decide how to do things properly even after spending alot of time at stack overflow or just googling stuff. For example , i got some algorithms doing the same work on the images and thought of implementing the strategy pattern but then again i figured why complicate it and not just make a static class with each algorithm as a different method ( System.Math style ) .
Another problem is how to pass each algorithms settings to it while at the same time avoiding a huge parameter list . A Parameter Object just moves the parameter list from the algorithm to the structure constructor , a builder pattern seems abit too much for it because the object needs to be bound to a control that changes the settings values .
How does a novice actually make these decisions ? Even the simple creation of the settings control is driving me mad , do i give the settings object a .ToControl() method ( is it its Responsibility to make a view of itself or not? ) or do i pass the object as an argument to the SettingsControl constructor ( does the control need to know about the settings object implementation ? ).All in all i think i just mashed up all that knowledge without really understanding it im afraid . Thanks for any help/opinion/advice beforehand .
|
On August 27 2013 01:54 Warri wrote:for (Object o:oList) { o.do(); if (!o.enabled) oList.iterator().remove(); }
Why is this throwing an IllegalStateException? I'm not quite familiar with this language, but it might be because you're removing an object from a collection as you're enumerating through the collection.
|
On August 27 2013 02:35 enigmaticcam wrote:Show nested quote +On August 27 2013 01:54 Warri wrote:for (Object o:oList) { o.do(); if (!o.enabled) oList.iterator().remove(); }
Why is this throwing an IllegalStateException? I'm not quite familiar with this language, but it might be because you're removing an object from a collection as you're enumerating through the collection. If you try to remove the object direclty with oList.remove(o); you would get ConcurrentModificationException, which is exactly because of what you said. Removing by using the iterator is supposed to work apparently.
|
remove: Removes from the list the last element that was returned by next() or previous() IllegalStateException - if neither next nor previous have been called, or remove or add have been called after the last call to next or previous
Dump the foreach loop and do a normal one with the iterator
|
On August 27 2013 01:54 Warri wrote:for (Object o:oList) { o.do(); if (!o.enabled) oList.iterator().remove(); }
Why is this throwing an IllegalStateException? You need to call next() before you can do a remove(). But you will run into errors still: you're using two different iterators for the same collection (the for loop and the explicit iterator()) and the for loop will crash if you modify the collection. Instead use only the explicit iterator(), and loop using while(iterator.hasNext()).
|
On August 27 2013 02:28 tapuchi wrote:Hello , i'm currently re-writing an image processing program i created using vc++ and matlab in c# and trying to implement the object-oriented paradigms correctly . My previous implementation was my first real and big programming experience and after spending the summer reading Design Patterns , Code Complete and Object Roles and Responsibilites i realized how bad my code structure/design/implementation was  and decided to go at it again whilst using what i hopefully learnt. The thing is i just cant decide how to do things properly even after spending alot of time at stack overflow or just googling stuff. For example , i got some algorithms doing the same work on the images and thought of implementing the strategy pattern but then again i figured why complicate it and not just make a static class with each algorithm as a different method ( System.Math style ) . Another problem is how to pass each algorithms settings to it while at the same time avoiding a huge parameter list . A Parameter Object just moves the parameter list from the algorithm to the structure constructor , a builder pattern seems abit too much for it because the object needs to be bound to a control that changes the settings values . How does a novice actually make these decisions ? Even the simple creation of the settings control is driving me mad , do i give the settings object a .ToControl() method ( is it its Responsibility to make a view of itself or not? ) or do i pass the object as an argument to the SettingsControl constructor ( does the control need to know about the settings object implementation ? ).All in all i think i just mashed up all that knowledge without really understanding it im afraid . Thanks for any help/opinion/advice beforehand . I am making a lot of assumptions, since your description of the problem isn't very specific. It sounds like a situation where I would create an IAlgorithm interface which you can apply to the image (or the image can apply to itself) without knowing what it does or how it is done. Then each algorithm gets its own class. Since you seem to have a lot of settings for each algorithm (and those probably are different from algorithm to algorithm), I would probably use a fluent interface to apply those settings. Implementation like this:
class Algo { Algo SettingA(value) { ... return this; } } Usage like this:
algo.SettingA(value_a).SettingB(value_b); Applying settings like is very readable and it's much harder to mix up different settings of the same type. Of course you can and likely should group several closely related values into the same settings method.
The "is it its Responsibility to make a view of itself or not?" and "does the control need to know about the settings object implementation ?" sound like things that should be answered with a straight up no.
You might want to read about test driven development. It deals mainly with good class design. You don't have to actually apply TDD, but it should provide some insight if you have trouble designing systems.
Also: Try to avoid static anything.
On August 27 2013 01:54 Warri wrote:for (Object o:oList) { o.do(); if (!o.enabled) oList.iterator().remove(); }
Why is this throwing an IllegalStateException? Usually you are not meant to make changes to the collection in a foreach loop, which this seems to be. What language is this, anyways?
|
On August 24 2013 05:45 Mordanis wrote:Show nested quote +On August 24 2013 05:31 Yoshi- wrote: That seems to be way too hard and is pretty much useless tbh, you should maybe focus on something that not that "impossible" I was thinking of writing each line to a file (dummy file?) that looks like this on startup: #include <stdio.h> int main() { /* lines from scanf go here */ return 0; } and then after each line, I can have a decision on what to/ if to print something. Then run a shell script to compile and run the "dummy program", and run the output to the main program. Is it that much more difficult than it seems? BTW this would only be for linux. EDIT: guess this was all basically said already... But for the usability part, it seems to me to be a slightly easier way to learn operations and pointers. Would this be helpful for someone just starting or coming back to C? or would this be a waste of time :D
Scaling it down to a simple REPL for a command-line calculator, perhaps in reverse polish notation, i.e., something like:
$ ./rpn
> 3 4 + 7 > 1 2 + 3 * 9 > quit
Exercises most of the functionality you want without having to delve into the details of properly implementing an actual programming language (as RoyGBiv_13 describes).
|
On August 27 2013 03:20 gedatsu wrote:Show nested quote +On August 27 2013 01:54 Warri wrote:for (Object o:oList) { o.do(); if (!o.enabled) oList.iterator().remove(); }
Why is this throwing an IllegalStateException? You need to call next() before you can do a remove(). But you will run into errors still: you're using two different iterators for the same collection (the for loop and the explicit iterator()) and the for loop will crash if you modify the collection. Instead use only the explicit iterator(), and loop using while(iterator.hasNext()). thanks, using the iterator for the loop works.
On August 27 2013 03:22 spinesheath wrote: What language is this, anyways? Java
|
On August 27 2013 03:22 spinesheath wrote:Show nested quote +On August 27 2013 02:28 tapuchi wrote:Hello , i'm currently re-writing an image processing program i created using vc++ and matlab in c# and trying to implement the object-oriented paradigms correctly . My previous implementation was my first real and big programming experience and after spending the summer reading Design Patterns , Code Complete and Object Roles and Responsibilites i realized how bad my code structure/design/implementation was  and decided to go at it again whilst using what i hopefully learnt. The thing is i just cant decide how to do things properly even after spending alot of time at stack overflow or just googling stuff. For example , i got some algorithms doing the same work on the images and thought of implementing the strategy pattern but then again i figured why complicate it and not just make a static class with each algorithm as a different method ( System.Math style ) . Another problem is how to pass each algorithms settings to it while at the same time avoiding a huge parameter list . A Parameter Object just moves the parameter list from the algorithm to the structure constructor , a builder pattern seems abit too much for it because the object needs to be bound to a control that changes the settings values . How does a novice actually make these decisions ? Even the simple creation of the settings control is driving me mad , do i give the settings object a .ToControl() method ( is it its Responsibility to make a view of itself or not? ) or do i pass the object as an argument to the SettingsControl constructor ( does the control need to know about the settings object implementation ? ).All in all i think i just mashed up all that knowledge without really understanding it im afraid . Thanks for any help/opinion/advice beforehand . I am making a lot of assumptions, since your description of the problem isn't very specific. It sounds like a situation where I would create an IAlgorithm interface which you can apply to the image (or the image can apply to itself) without knowing what it does or how it is done. Then each algorithm gets its own class. Since you seem to have a lot of settings for each algorithm (and those probably are different from algorithm to algorithm), I would probably use a fluent interface to apply those settings. Implementation like this: class Algo { Algo SettingA(value) { ... return this; } } Usage like this: algo.SettingA(value_a).SettingB(value_b); Applying settings like is very readable and it's much harder to mix up different settings of the same type. Of course you can and likely should group several closely related values into the same settings method. The "is it its Responsibility to make a view of itself or not?" and "does the control need to know about the settings object implementation ?" sound like things that should be answered with a straight up no. You might want to read about test driven development. It deals mainly with good class design. You don't have to actually apply TDD, but it should provide some insight if you have trouble designing systems. Also: Try to avoid static anything. ?
C# has initialization lists, so the .SettingA() thing is usually (arguably) less readable.
Class X { public String A {get;set;} public Int32 B {get;set;} public Double C {get;set;} }
X x = new X() { A = "foo", B = 42, C = 3.1415926 }
I'm currently in the middle of a Planetside 2 platoon op so i don't have time to write a good solution for the problem in question but if noone else gives a satisfactory solution, i'll might remember to write it later.
|
|
|
|