The Big Programming Thread - Page 625
Forum Index > General Forum |
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. | ||
teamamerica
United States958 Posts
| ||
Neo7
United States922 Posts
| ||
teamamerica
United States958 Posts
On April 30 2015 11:36 Neo7 wrote: I'd throw the references into some template. Use a developer mode flag to determine whether to import the template file or reference the production js file based on what environment you're in. Hmm ya I must be missing something basic. So there's a few things. 1. Servlet app 2. Frontend is backbone js using requirejs. 3. App is built using ant. So the first thing that's tripping me up is - even just concatening all the files happens as one of the tasks before the war task. So trying to see how to get those files to be included into the war. Then need to see how to best minify the javascript without breaking stuff and renaming all the references. I'd prefer to do it all through ant just to keep the build simpler but not sure if that's worth it if this is much easier in something like Grunt. I'd rather not install node just to build stuff. | ||
Isualin
Turkey1903 Posts
| ||
Manit0u
Poland17196 Posts
What I have: A table where rows can have a one-to-one relation with other rows in the same table. What I need: Get all the rows that either don't have the relation, or if they do I want to only return one side of it. Where I'm at now:
What this gives me is all the rows without the relation. Now I need to get this other side of the relation (inverse side is the owning side) for those that have it, and it has to be included in all the id, value etc. in the results on equal terms as rows without relation. Help anyone? I've been churning this around so much that my brain boils and I don't know what I'm talking about any more. And I suck horribly at SQL. | ||
ZenithM
France15952 Posts
On April 30 2015 16:02 Isualin wrote: Microsoft reveals visual studio code It's own site doesn't load for me though. I am using eclipse for java, sublime for everything else right now but i might give it a try It should work now. I don't think VS Code can replace a dedicated IDE like Eclipse yet (for example, when I tried it, I didn't see any "project" notion of any sort), but I'm sure it's part of their strategy to bring the full VS to other platforms. I would see it more as a replacement for, please, don't burn me, emacs, vim, kate, gedit (lol), etc etc.. :D | ||
berated-
United States1134 Posts
On April 30 2015 18:51 Manit0u wrote: I need a bit of help with MySQL... What I have: A table where rows can have a one-to-one relation with other rows in the same table. What I need: Get all the rows that either don't have the relation, or if they do I want to only return one side of it. Where I'm at now:
What this gives me is all the rows without the relation. Now I need to get this other side of the relation (inverse side is the owning side) for those that have it, and it has to be included in all the id, value etc. in the results on equal terms as rows without relation. Help anyone? I've been churning this around so much that my brain boils and I don't know what I'm talking about any more. And I suck horribly at SQL. Use a union? I think thats what you want.. https://dev.mysql.com/doc/refman/5.0/en/union.html | ||
Acrofales
Spain17849 Posts
On April 30 2015 20:16 berated- wrote: Use a union? I think thats what you want.. https://dev.mysql.com/doc/refman/5.0/en/union.html Yeah. Union should do it. Write a second query to get your other results and UNION them:
I also don't really understand what was happening in your original query, so I think I fixed it. That said, this seems like a pretty bad way of modeling this relationship, because there is no way of enforcing the 1-1.0 relationship. Instead, remove the otherSide (it is unnecessary), and add a UNIQUE constraint on relation. I am not sure MySQL allows a foreign key to the same table. If it does, add that one in as well, and you are guaranteed your 1-1,0 relationship. | ||
berated-
United States1134 Posts
On April 30 2015 20:35 Acrofales wrote: Yeah. Union should do it. Write a second query to get your other results and UNION them:
I also don't really understand what was happening in your original query, so I think I fixed it. That said, this seems like a pretty bad way of modeling this relationship, because there is no way of enforcing the 1-1.0 relationship. Instead, remove the otherSide (it is unnecessary), and add a UNIQUE constraint on relation. I am not sure MySQL allows a foreign key to the same table. If it does, add that one in as well, and you are guaranteed your 1-1,0 relationship. I think you might have flipped the condition a.other side not b.other side. If b.relation being null means it didn't join, then I would think it would be in the join. either way thats why I didn't elaborate and just left it at use union | ||
Acrofales
Spain17849 Posts
On April 30 2015 21:19 berated- wrote: I think you might have flipped the condition a.other side not b.other side. If b.relation being null means it didn't join, then I would think it would be in the join. either way thats why I didn't elaborate and just left it at use union You're probably right. It should be WHERE b.otherSide IS NULL. What the LEFT OUTER JOIN (same as LEFT JOIN) query does is to join every row in a with every row in b that matches the ON criteria. If there is no ON criteria it is simply a Cartesian product (as in the original query given, which I think is wrong for that reason). If there is an ON criteria then, if there is a row in a that has no matching result in b, these are left blank (null). Now that I think about it, I am not sure why we are joining in the first query at all. Shouldn't:
work just fine? | ||
Manit0u
Poland17196 Posts
On April 30 2015 21:32 Acrofales wrote: You're probably right. It should be WHERE b.otherSide IS NULL. What the LEFT OUTER JOIN (same as LEFT JOIN) query does is to join every row in a with every row in b that matches the ON criteria. If there is no ON criteria it is simply a Cartesian product (as in the original query given, which I think is wrong for that reason). If there is an ON criteria then, if there is a row in a that has no matching result in b, these are left blank (null). Now that I think about it, I am not sure why we are joining in the first query at all. Shouldn't:
work just fine? Tried that, it threw exceptions in the DBAL about you needing explicit joins etc. Anyway, I've solved the issue by simply making 2 queries instead of 1 and then merging the results. And I know it's badly designed relationship but I'm fixing client's old system where table rows have 200+ columns of which 30 are various relations to itself and other things. Nightmare. | ||
Artesimo
Germany537 Posts
At the moment I am trying to search/organize itemlists from a small game a friend of mine is making at the moment and therefore gets constant changes. I want to be able to read in the file when I start my programm, then search for items of certain criteria. the list is from the following structure(with more columns but that shouldnt matter) (the entrys of each colums are all algined, for some reason I dont manage to display it properly in this post. I wantet to share my ideas/problems. I already have a working solution, but I feel like it doesnt satisfy me. Current status: + Show Spoiler + I am using regex to split the columns and then sort them into vectors, one vector for each columns and store them in a main vector. If I search now for a name/tag/min or maxvalue, it runs through the corresponding vector until it finds this vector and then checks the other vectors for the values thats in them, at last comparing it to the first vector where the name columns is stored including the empty rows. My thought was that since every item can have multiple tags/attributes but only has one name, it checks the name vector for previous/later/same row occurances of a name which then tells me that everything between the first and the last row in which a name occured must belong to the first found name, therefore displaying all the corresponding values. However, I feel like there must be a better way to do this. First of all: is there a better way to read in tables that are stored in a txt-file with c++ standard library? What would be a better way to seperate the values then a regexsearch? Whitespaces as delimiters for getline() wont work since the number of whitespaces varys. I assume that regex is compared to this small task overkill and not really an performant solution(even though I am just searching for multiple occurances of ' '). Storing vectors in vectors in vectors... this babushka-style seems pretty ugly. During my research I came across the term "linked lists", should I continue checking this out for this matter(I will check it out anyways later, but at the moment I just care about this task)? EDIT: Also, since I start to get really serious about programming, is there a styleguide/general compiliation of things I should whatch out for while coding, specificly in c++, thats actual used in the working world? I am planning to do my first internship after my third semester/maybe even after this one if I get lucky and I would really like to show off something thats actually usefull for the company so that I am not just some student that you have to babysit the first few weeks. | ||
netherh
United Kingdom333 Posts
| ||
Ropid
Germany3557 Posts
Like, you first think "the start of the file can have comments... let's check for that and throw those lines away". After you've done that, you'll be in the next section of the input file, and you'll also be in the next section of your program code where you'll use different regex etc. Something like this is called a "parser". You can just hack something together here without a system, but while you are motivated because you have an actual problem, you might want to look around a bit to see how this can be done generally. To write a parser, I believe there's nothing in the C++ standard library that will help you generate it. You could search around to see if you can find a simple parser library. You can also write the parser yourself, and I think you should do this manually at least once to see how it can be done. If you've never seen the syntax of a language drawn as a diagram, type "backus-naur grammar diagram" in Google's Image Search and look at what you find. You can understand those just by looking at it. You could draw something similar for your problem on paper. In the next step, you basically just stupidly translate every box you've drawn into a piece of code. The arrows in the diagram will turn into control structures like if/then/else and loops or recursion. That's what the parser libraries would do for you. You feed them with a description of your diagram and they'll generate the program's structure automatically. | ||
Artesimo
Germany537 Posts
On April 30 2015 23:26 netherh wrote: I'm not sure there's any "good" way to read in a file format like that. Can you persuade your friend to use xml or json or lua... some actual data description language? (It'll be easier for him in the long run too). Unfortunately he only codes in java since its the only thing he knows. He also does it as a hobby since his work isnt related to IT in any form (even though he still is better than me at coding... for now ![]() EDIT: Thanks ropid, I can assure you that I already solved the problem using regex before asking for help. I was just searching for optimization since it felt a little overkill since my iterator has to check on every word "does it has letters? yes? good. does a single space come afterwards and then more letters? must be a multiple-words name/attribute then. does it start with a number? good, get it, grab it all and split it up. oh, it is just spaces? just ignore the findings and put a blank in the names-vector for that line". Sometimes I have problems understanding what is "hard" for a machine and whats not^^. EDIT2: I figured a linked list is what I propably want and most likely would be the "most professional" thing to store this. I am going to use vector first until someone advices me otherwise. In addition, here is a chart of what I am planing to do: ![]() | ||
Ropid
Germany3557 Posts
EDIT: Also, you are right in thinking that this is hard for the machine. It has to test and branch at every single step while eating through the input stream of characters, and every branch can make it wipe out all the work it had already prepared for the following instructions. It's one of the things that can slow it down a lot. | ||
netherh
United Kingdom333 Posts
On April 30 2015 23:33 Artesimo wrote: Unfortunately he only codes in java since its the only thing he knows. He also does it as a hobby since his work isnt related to IT in any form (even though he still is better than me at coding... for now ![]() Well, I'm sure there are Java libraries for reading xml / json. The correct container generally depends on your interface needs, and then on your usage pattern. Vectors have fast iteration (contiguous memory), but slow insertion / deletion (except from the end). Lists have fast insertion / deletion, but slower iteration. (In practice vectors may still be faster where the container has few items). Other container types exist for other purposes / usage patterns: e.g. Queues, Deques, Priority Queues, Maps, Multimaps, Unordered Maps, Sets, Multisets, Unordered Sets. EDIT: I'm not quite sure what your diagram is supposed to represent, but I'd be inclined to structure things like this:
| ||
Artesimo
Germany537 Posts
On May 01 2015 00:25 netherh wrote: Well, I'm sure there are Java libraries for reading xml / json. The correct container generally depends on your interface needs, and then on your usage pattern. Vectors have fast iteration (contiguous memory), but slow insertion / deletion (except from the end). Lists have fast insertion / deletion, but slower iteration. (In practice vectors may still be faster where the container has few items). Other container types exist for other purposes / usage patterns: e.g. Queues, Deques, Priority Queues, Maps, Multimaps, Unordered Maps, Sets, Multisets, Unordered Sets. EDIT: I'm not quite sure what your diagram is supposed to represent, but I'd be inclined to structure things like this:
Haha, as usual... you solution is so much simpler than what my crude brain thought about, thanks alot. | ||
Millitron
United States2611 Posts
On April 30 2015 23:33 Artesimo wrote: Unfortunately he only codes in java since its the only thing he knows. He also does it as a hobby since his work isnt related to IT in any form (even though he still is better than me at coding... for now ![]() EDIT: Thanks ropid, I can assure you that I already solved the problem using regex before asking for help. I was just searching for optimization since it felt a little overkill since my iterator has to check on every word "does it has letters? yes? good. does a single space come afterwards and then more letters? must be a multiple-words name/attribute then. does it start with a number? good, get it, grab it all and split it up. oh, it is just spaces? just ignore the findings and put a blank in the names-vector for that line". Sometimes I have problems understanding what is "hard" for a machine and whats not^^. EDIT2: I figured a linked list is what I propably want and most likely would be the "most professional" thing to store this. I am going to use vector first until someone advices me otherwise. In addition, here is a chart of what I am planing to do: ![]() If you're using Java, check out the String Tokenizer class. It makes parsing so much easier. It reads much more like you or I do, and not character-by-character. If you also have to stick with putting your data in .txt's, I recommend designing the file with the Name Value Pair paradigm in mind. Basically you'll have a bunch of lines of the form " [item] x = [value] y". Its pretty simple to parse, and can be extended to do some pretty powerful stuff. | ||
spinesheath
Germany8679 Posts
On April 30 2015 06:51 darkness wrote: Java is a really good language with really good syntax for beginners. As soon as you want to have more control, Java becomes terrible. No deterministic destructor (finalize is unreliable), no deterministic memory deallocation, no pass by reference unless you pass an object. C# solves that by having 'ref' and 'out' though. In a way, C# seems like better or more advanced Java. None of these are things I'd name as positive aspects of C#. Stay away from ref and out if possible. Don't hesitate to introduce a small class instead. Don't use C# or Java in settings where you would need deterministic object lifetime. | ||
| ||