Anyways, likely you do not want to have a raw csv file on the client side. Make some sort of data structure, read the file into that on the server, and then just use whatever your normal serialization is to pass it to the client. (I don't know what kind of setup you're using, on my team we use emulated protocol buffers - if this was my task at work, I'd be constructing a proto that holds the same data structure, parse it in on the server and then make sure any java code that handles that proto is properly emulated so it'll work on the client).
The Big Programming Thread - Page 389
| 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. | ||
|
phar
United States1080 Posts
Anyways, likely you do not want to have a raw csv file on the client side. Make some sort of data structure, read the file into that on the server, and then just use whatever your normal serialization is to pass it to the client. (I don't know what kind of setup you're using, on my team we use emulated protocol buffers - if this was my task at work, I'd be constructing a proto that holds the same data structure, parse it in on the server and then make sure any java code that handles that proto is properly emulated so it'll work on the client). | ||
|
Fawkes
Canada1935 Posts
So if I had options A, B, C, D and E...A and E were checked off, I was gonna put "A, E". I am just trying to figure out if there's anything I might regret if I try to query the table in the future. | ||
|
sluggaslamoo
Australia4494 Posts
On November 09 2013 08:29 Rotodyne wrote: Hey guys, over the last year I have been teaching myself a bunch of web programming stuff (php, javascript, html, css), but I still really just use a programming technique called "get shit done", in the short term this has been useful, but I usually just begin coding projects and figure it out as I go along. Specifically I know I need to learn OO programming. My question is if I should use PHP to learn OO, or should I use something else? I have heard that PHP isn't a good way to learn because objects were added as sort of an afterthought. But what do I know. The best way is not to learn a language but go read some books ![]() Read books on responsibility driven design and OOP. Writing OO in PHP gives me a headache though. Object Design by Wirfs-Brock & Mckean is one I'd recommend for starters. It is a small and concise book that will teach you the mindset required behind RRD, there's no code, just UML, but that's why its so good IMO. RRD is a fundamental of OO, you can know all the OOP in the world, but without RRD you will just write rubbish code. The most important thing is just how to write clean structured code in PHP as you don't have any fancy features. Fat Models, thin Controllers, break as many things down into small re-useable functions as you can (functional decomposition), etc. If you have any functions that are longer than 10 lines seriously have a look at them and see if you can't break them down. Most of my functions are 1-3 (ruby) lines long, this is due to functional programming though, I'd say for PHP they should float between 3 to 5 lines on average. On November 09 2013 08:43 misirlou wrote: Although not the best OOP language, PHP has the main features of OOP so you can start learning with what it's available there. If you do plan in "getting shit done" with PHP and other web languages, there's no real reason to go learn another language to learn OOP. AFAIK PHP has dynamic dispatching, abstraction, polymorphism and inheritance, so you're good to go. There's no polymorphism that I'm aware of, like other dynamic languages it has duck-typing instead. Every language has abstraction, as long as it can define functions it has abstraction. ![]() | ||
|
Javadocs
United States60 Posts
On November 11 2013 07:06 Fawkes wrote: As a design question, how would you guys go about putting this in a column in a sql db? If you had a form that had a question that said: check off as many that apply. The way I am thinking of putting it is just putting any checked off fields into the entry, but I can't seem to figure out if that is going to come back to haunt me or not... So if I had options A, B, C, D and E...A and E were checked off, I was gonna put "A, E". I am just trying to figure out if there's anything I might regret if I try to query the table in the future. A better solution would be to create a new table (if possible) with 2 columns, the user ID (or whatever links it back to the original table) and a choice column. CREATE TABLE ( userID int not null, --FOREIGN KEY probably questionChoice char(1) not null ) Then just insert a row for each choice (if selected), so if they chose A and E, then there are two rows inserted (and returned) for that user ID. That way, you don't have to parse a string, and have to deal with invalid strings. | ||
|
DeltaX
United States287 Posts
1. Have a column for each entry. This feels a bit messy and I would assume there is something that makes this bad, I just don't know it. 2. Store the options as a number with each bit representing one choice. IE, if they chose A and C, that is 101 aka 5 that you would store, then write some methods somewhere to encode/decode the options. This might be a bit complicated for whatever your application is, but i think it would work out well. I don't like the idea of doing it with strings. | ||
|
Orome
Switzerland11984 Posts
On November 11 2013 03:49 phar wrote: Your first not-hello-world style programming experience and you're thrown headfirst into GWT? That's brutal. GWT eats up and spits out engineers at my work. I personally did a few months of that ~2 years ago and then ran screaming for the hills, never to look back (to be fair mostly because I don't really enjoy FE). Anyways, likely you do not want to have a raw csv file on the client side. Make some sort of data structure, read the file into that on the server, and then just use whatever your normal serialization is to pass it to the client. (I don't know what kind of setup you're using, on my team we use emulated protocol buffers - if this was my task at work, I'd be constructing a proto that holds the same data structure, parse it in on the server and then make sure any java code that handles that proto is properly emulated so it'll work on the client). Yeah it's somewhat ridiculous, especially since there's absolutely no help on the coding side of things. I have a nagging suspicion I'm going too far with this and that there's some sort of intermediate working solution I could be implementing, but I have no idea what that might be. I think what I've been trying to do the past few hours is somewhat similar to what you're suggesting. Place the import code server-side so I can use Java IO, communicate with that method through a remote procedure call, have it return a data structure which then gets copied into the client-side data structure for further use. Problem being that I have absolutely no knowledge about servlets, the different GWT project files or anything, so it's extremely hard to avoid mistakes or debug in a way that isn't just randomly guessing what the fix might be. | ||
|
VyingsP
France174 Posts
On November 11 2013 07:31 Javadocs wrote: A better solution would be to create a new table (if possible) with 2 columns, the user ID (or whatever links it back to the original table) and a choice column. CREATE TABLE ( userID int not null, --FOREIGN KEY probably questionChoice char(1) not null ) Then just insert a row for each choice (if selected), so if they chose A and E, then there are two rows inserted (and returned) for that user ID. That way, you don't have to parse a string, and have to deal with invalid strings. Other possibility is to have both fields as foreign keys : userID and choiceID, and to create a new table with your options. This way you can use your choice table as the reference anywhere else it would be needed (might not be relevant in your case, just something to keep in mind if those options might be reused elsewhere). | ||
|
GeneralMrPiggy
Netherlands2 Posts
On November 11 2013 07:49 DeltaX wrote: I don't know that much about sql design, but some other options would be: 1. Have a column for each entry. This feels a bit messy and I would assume there is something that makes this bad, I just don't know it. 2. Store the options as a number with each bit representing one choice. IE, if they chose A and C, that is 101 aka 5 that you would store, then write some methods somewhere to encode/decode the options. This might be a bit complicated for whatever your application is, but i think it would work out well. I don't like the idea of doing it with strings. If it were a form with a fairly limited amount of options that are not going to change I would say option 1 is a fine option. The issue a lot of the time is when you want to change or add options. As for option 2. In my opinion it makes it unnecessarily difficult, instead I would go for the option as suggested by Javadocs to create a table holding a record for each user id / choice combination. This would give the same flexibility as having a bit for each option without having to do encoding and decoding of the options. | ||
|
ArchmageKruzer
64 Posts
| ||
|
bangsholt
Denmark138 Posts
![]() In that way, it actually doesn't matter if you *can* precompute or not, as long as you can get some sample data to work with. | ||
|
Fawkes
Canada1935 Posts
If we had a table where the fields are like (num_id, firstname, lastname), num_id is just an incrementing number based on entries in this table...what's a query I can use to get the biggest num_id so far used? Also can someone tell me what happens in this code block: while ($myrow = mysql_fetch_array($result)) { //does something with $myrow } $result is the result of a sql query. How does the condition for the loop work? Am I understanding it right that when it reaches past the last row, mysql_fetch_array returns false...so $myrow = false would fail the loop? I didn't know this would break the condition of the loop. I never actually tried anything like this before... | ||
|
Rotodyne
United States2263 Posts
On November 11 2013 07:30 sluggaslamoo wrote: The best way is not to learn a language but go read some books ![]() Read books on responsibility driven design and OOP. Writing OO in PHP gives me a headache though. Object Design by Wirfs-Brock & Mckean is one I'd recommend for starters. It is a small and concise book that will teach you the mindset required behind RRD, there's no code, just UML, but that's why its so good IMO. RRD is a fundamental of OO, you can know all the OOP in the world, but without RRD you will just write rubbish code. The most important thing is just how to write clean structured code in PHP as you don't have any fancy features. Fat Models, thin Controllers, break as many things down into small re-useable functions as you can (functional decomposition), etc. If you have any functions that are longer than 10 lines seriously have a look at them and see if you can't break them down. Most of my functions are 1-3 (ruby) lines long, this is due to functional programming though, I'd say for PHP they should float. Thanks a lot! I had started a book about PHP OOP but it wasn't really doing it for me. I'll try that one out for for sure. | ||
|
Zocat
Germany2229 Posts
On November 11 2013 11:18 ArchmageKruzer wrote: For science fair this year, one of my friends is trying to build a program to compare frequencies of chunks of various DNA codes (quite personally I don't really understand it myself, but it's basically you get ~ one million dna bases, and you pick out how many AGTGGACA are in there, rinse and repeat for a ton more chunks). So the obvious way is to just run a loop and compare the data, but that would take a long time as I understand it. Is there a more effective way to do this? (btw, I am really bad at coding. I am extremely good at logic stuff, but idk much syntax and terms and shit. i.e I'm in regular high school programming learning about java. we just got past karel, and are in the middle of if statements) please try not to use too much complicated syntax, or if you do, give me some sort of reference sheet so that I can look at it while I read you post. Ty! For high school stuff you should probably look at this: http://en.wikipedia.org/wiki/String_searching_algorithm and pick something which seems good for you. | ||
|
KaiserJohan
Sweden1808 Posts
On November 11 2013 11:47 Fawkes wrote: I know this is bad practice, but it's not my design and I rather not argue. If we had a table where the fields are like (num_id, firstname, lastname), num_id is just an incrementing number based on entries in this table...what's a query I can use to get the biggest num_id so far used? Also can someone tell me what happens in this code block: $result is the result of a sql query. How does the condition for the loop work? Am I understanding it right that when it reaches past the last row, mysql_fetch_array returns false...so $myrow = false would fail the loop? I didn't know this would break the condition of the loop. I never actually tried anything like this before... '$myrow' is assigned the result of 'mysql_fetch_array()' before '$myrow' is evaluated as the loop condition. ... while ($myrow = mysql_fetch_array($result)) => while ($myrow = false) => while (false) | ||
|
Shield
Bulgaria4824 Posts
If you have: Java: public class BlahBlah extends Thread or C++ class BlahBlah: public Thread(let's assume that's C++ STL class) or Objective-C class BlahBlah: NSThread(pretend you have such a class that comes from Apple) Do you need to show this inheritance on a class diagram if it's a class from standard library? I understand you need to do for a CustomClass2 that inherits CustomClass1 but what about the case above? | ||
|
spinesheath
Germany8679 Posts
| ||
|
Tobberoth
Sweden6375 Posts
On November 11 2013 23:08 darkness wrote: I'm going to ask again as it remained unanswered. If you have: Java: public class BlahBlah extends Thread or C++ class BlahBlah: public Thread(let's assume that's C++ STL class) or Objective-C class BlahBlah: NSThread(pretend you have such a class that comes from Apple) Do you need to show this inheritance on a class diagram if it's a class from standard library? I understand you need to do for a CustomClass2 that inherits CustomClass1 but what about the case above? I don't think it's customary. I mean, in C# for example, all classes inherit from Object, but you don't actually write out Object in the class diagram. I would just write BlahBlah : Thread as the name of the class to make it clear that it has functionality not shown in the class diagram, but I wouldn't actually include the Thread class. | ||
|
Yoshi-
Germany10227 Posts
On November 11 2013 07:30 sluggaslamoo wrote: If you have any functions that are longer than 10 lines seriously have a look at them and see if you can't break them down. Most of my functions are 1-3 (ruby) lines long, this is due to functional programming though, I'd say for PHP they should float between 3 to 5 lines on average. Yea that is bullshit I all up for splitting code into smaller part, but saying that you should average between 3 to 5 lines is just ridiculous | ||
|
ferdkuh
10 Posts
On November 11 2013 11:18 ArchmageKruzer wrote: For science fair this year, one of my friends is trying to build a program to compare frequencies of chunks of various DNA codes (quite personally I don't really understand it myself, but it's basically you get ~ one million dna bases, and you pick out how many AGTGGACA are in there, rinse and repeat for a ton more chunks). So the obvious way is to just run a loop and compare the data, but that would take a long time as I understand it. Is there a more effective way to do this? (btw, I am really bad at coding. I am extremely good at logic stuff, but idk much syntax and terms and shit. i.e I'm in regular high school programming learning about java. we just got past karel, and are in the middle of if statements) please try not to use too much complicated syntax, or if you do, give me some sort of reference sheet so that I can look at it while I read you post. Ty! I think a nice way to do this would be this using something similar to this: http://en.wikipedia.org/wiki/Suffix_tree You can find/count common sequences quite easy and fast and it is reasonably simple to implement. | ||
|
spinesheath
Germany8679 Posts
| ||
| ||
