|
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 December 30 2013 06:12 teamamerica wrote:Anyone have advice on good books/pointers on designing stuff? Writing in object orientated languages, one thing I struggle with is how to design my classes. Things like: should this be static function or instance. Should this be in constructor or passed into function. Should I pass an object and act on a copy, or mutate the object that was passed in. Also the same question about good references for how to set up relational database schema? e.g. surrogate keys vs natural keys. One thing I was just working on was... + Show Spoiler + One thing I just worked on had records which had either a "rast" or "patric" type annotation. Each annotation type provided different information i.e. different columns. So for each record I stored "annotation type" as an "enum", and had 2 tables {rast, patric} annotation. My question in this case is twofold: 1) better to have split it into 2 tables or used one larger table (annotation) and nulled out columns as appropriate 2) better to use enum to describe annotation type or a values table (e.g. annotation type column => annotation_types table => "rast" | "patric". 3) and this might be mysql specific. Some of the columns in the annotation table are rather large - 500char+. When to use varchar(500) or "TEXT". Say the column "length" is 500+ characters. I've seen before comments that TEXT and BLOB columns can make table operations that don't even effect these columns really expensive. Should I have stored "length" in a seperate table, and had a lookup table from the main record to it?
The data seemed pretty relational but it feels weird to columns with so much text into a database.
I'm looking through Effective Java which I find pretty interesting, and it kind of covers questions of the second instance, but not really questions of the first instance.
Object Oriented* not Object Orientated 
I haven't seen any Java books that are useful.
I've read a ton of books on OO and this is still my favorite http://www.amazon.com/Object-Design-Roles-Responsibilities-Collaborations/dp/0201379430
Generally avoid using class variables and methods if you can. The less you rely on state the better. Basically your program is a system of collaborating objects that work together to solve a problem. Think of it like an organisation, you have different people specialising in different tasks all working together.
Just incase you missed it, I just gave a guy a refactored tictactoe example with heavy object decomposition and functional decomposition. That's basically all you need to master for the first year, once you have that down you stop wasting time thinking about any of this stuff and the rest comes easy.
https://github.com/DanielShuey/Java-TicTacToe-Example/tree/master/src/tictactoe
|
^ the book's title reminds me of CRC (Class-responsibility-collaboration): wikipedia. Is that what it teaches?
|
On December 30 2013 07:54 darkness wrote:^ the book's title reminds me of CRC (Class-responsibility-collaboration): wikipedia. Is that what it teaches?
Class Responsibility Collaboration is probably an inspiration for Responsibility Driven Design.
CRC cards are really unnecessary though, I've found having brainstorming sessions for design to be a complete wank. 99% of the time you end up just wanting to completely change the design during implementation anyway.
Also the use of CRC cards in extreme programming is usually for writing stories rather than design, extreme programming spends basically 0 time on design, I think that wiki entry is a tad misguided.
Although CRC is probably a really broad and undefined term, where as RDD is a bit more defined and structured. You don't need to spend time brainstorming with RDD either, its just a mindset that you have, at least for me anyways.
|
On December 30 2013 05:30 wozzot wrote:Programming newbie, making a Rubik's Cube solver, feeling really dumb right now. I think I can manage to get the cube structure, the transformation subroutine, and solver algorithm going, but I don't know how the hell I should store the cubelet data, the data that tells me that the TL corner of the top face is connected to the TL of the left face and TR of the back face so that I can rotate them together and so on. Right now, I'm using this and using split to retrieve the face + side/corner pairs: my cubelets[6][9]; { cubelets[0][0] = ( ["1 0", "4 2"] ); cubelets[0][1] = "4 1"; cubelets[0][2] = ( ["4 0", "3 2"] ); cubelets[0][3] = "1 1"; cubelets[0][5] = "3 1"; cubelets[0][6] = ( ["1 2", "2 0"] ); cubelets[0][7] = "2 1"; cubelets[0][8] = ( ["2 2", "3 0"] );
cubelets[1][0] = ( ["0 0", "4 2"] ); cubelets[1][1] = "0 3"; cubelets[1][2] = ( ["0 6", "2 0"] ); cubelets[1][3] = "4 5"; cubelets[1][5] = "2 3"; cubelets[1][6] = ( ["4 8", "5 6"] ); cubelets[1][7] = "5 3"; cubelets[1][8] = ( ["2 6", "5 0"] );
cubelets[2][0] = ( ["0 6", "1 2"] ); cubelets[2][1] = "0 7"; cubelets[2][2] = ( ["0 8", "3 0"] ); cubelets[2][3] = "1 5"; cubelets[2][5] = "3 3"; cubelets[2][6] = ( ["1 8", "5 0"] ); cubelets[2][7] = "5 1"; cubelets[2][8] = ( ["3 6", "5 2"] );
...
But I'm pretty sure that this is either non-optimal or I might be approaching this problem completely the wrong way. Am I doing something wrong? Any advice on how to go about doing this? e: Only on Layer 1 and it's already about 250 lines of code, I'm definitely screwing something up but may as well keep on going
So if I understand it correctly, the first index in your array is an arbitrary side number of the cube and the second index is the squares of the side?
First of all, you could encode the current system of sides and squares into an integer - I'm thinking something like 28 - this would allow you to do a modulus operation to get the side and square. (Example would be: int side = encode / 10, int square = encode % 10)
Then you can save a list of those in a list which holds all the corners of the cube - so basically you would end up with a structure that's like this
List<List<Integer>> corners;
Then you can with ease do a simple for-loop over it and figure out which squares are connected to each other. This of course takes some time to iterate, but for now the important thing is to get it working, then you can start optimizing afterwards
|
In PHP things are all set up with lamp/wamp framework and if you want to make a login page you can do it with just a php script and an html form page that passes directly to that php file.
How do you make a login page with c# using the microsoft mvc framework? It's just so confusing.
I'm reading this stuff and they just give you buttons to click. There's so many layers of abstraction that I don't really see what's going on anymore. How does the html form page interact with the back end c# code to authenticate a user?
http://msdn.microsoft.com/en-us/library/879kf95c(v=vs.100).aspx
Can I make a login page that doesn't use membership? How does the c# aspx file link to the back end mssql database?
Nvm, fuck microsoft, there's a tutorial here: http://www.daniweb.com/web-development/aspnet/threads/6028/simple-asp.net-login-page-using-vb.net
I can try this.
|
On December 30 2013 23:52 obesechicken13 wrote:In PHP things are all set up with lamp/wamp framework and if you want to make a login page you can do it with just a php script and an html form page that passes directly to that php file. How do you make a login page with c# using the microsoft mvc framework? It's just so confusing. I'm reading this stuff and they just give you buttons to click. There's so many layers of abstraction that I don't really see what's going on anymore. How does the html form page interact with the back end c# code to authenticate a user? http://msdn.microsoft.com/en-us/library/879kf95c(v=vs.100).aspxCan I make a login page that doesn't use membership? You can make your own login system just fine, it basically works the same as in PHP. A cshtml page with the login form, and a controller to handle the authentication etc. The problem, of course, is to make it secure and good, which is what membership (to some extent) fixes for you. It's quite a complex thing, which is why there are so many layers of abstraction.
(If you want to learn more about the abstractions, try writing your own membership provider, I'm sure there are decent tutorials for it).
|
On December 30 2013 23:55 Tobberoth wrote:Show nested quote +On December 30 2013 23:52 obesechicken13 wrote:In PHP things are all set up with lamp/wamp framework and if you want to make a login page you can do it with just a php script and an html form page that passes directly to that php file. How do you make a login page with c# using the microsoft mvc framework? It's just so confusing. I'm reading this stuff and they just give you buttons to click. There's so many layers of abstraction that I don't really see what's going on anymore. How does the html form page interact with the back end c# code to authenticate a user? http://msdn.microsoft.com/en-us/library/879kf95c(v=vs.100).aspxCan I make a login page that doesn't use membership? You can make your own login system just fine, it basically works the same as in PHP. A cshtml page with the login form, and a controller to handle the authentication etc. The problem, of course, is to make it secure and good, which is what membership (to some extent) fixes for you. It's quite a complex thing, which is why there are so many layers of abstraction. (If you want to learn more about the abstractions, try writing your own membership provider, I'm sure there are decent tutorials for it). Ok that makes sense. Do the membership providers still use your mssql database? If so which tables do they use?
edit: nvm, it looks like you can specify a sql data store, but I still have to figure out how to set that up. Last time I tried to set up memberships I ran into error messages for a day.
|
Anyone have any experience implementing the Twitch API or Javascript commands?
|
I'm so lost right now so if someone could help me a little.
So the problem states that I have to print out the numbers from 1 to 100. Simple enough. But then it states that I need to print out their multiples on the same line up until the multiples are less than or equal to 500. For example, on line 99, it should print:
99, 198, 297, 396, 495
I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for (int i = 1; i <= 100; i++){ System.out.println(i); }
I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.
Not looking for the answer, just some help on introducing the while loop.
Should I initialize a new variable? How would I print out the multiples?
|
On December 31 2013 04:33 Housemd wrote:
I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for (int i = 1; i <= 100; i++){ System.out.println(i); }
I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.
Not looking for the answer, just some help on introducing the while loop.
Should I initialize a new variable? How would I print out the multiples?
Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i.
introduce a new variable x, state (while x <=500), print out x and increment it by i.
|
On December 31 2013 04:46 Cyx. wrote:Show nested quote +On December 31 2013 04:33 Housemd wrote:
I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for (int i = 1; i <= 100; i++){ System.out.println(i); }
I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.
Not looking for the answer, just some help on introducing the while loop.
Should I initialize a new variable? How would I print out the multiples? Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i. Show nested quote + introduce a new variable x, state (while x <=500), print out x and increment it by i.
Thanks for the help. Just a couple of questions. int x = 0; for (int i = 1; i <= 100; i++){ while (x <= 500) System.out.println(x+=i);
Now, when I print x, it gives me the numbers 1-501. I'm assuming there is something wrong with my while loop?
|
On December 31 2013 05:28 Housemd wrote:Show nested quote +On December 31 2013 04:46 Cyx. wrote:On December 31 2013 04:33 Housemd wrote:
I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for (int i = 1; i <= 100; i++){ System.out.println(i); }
I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.
Not looking for the answer, just some help on introducing the while loop.
Should I initialize a new variable? How would I print out the multiples? Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i. introduce a new variable x, state (while x <=500), print out x and increment it by i. Thanks for the help. Just a couple of questions. int x = 0; for (int i = 1; i <= 100; i++){ while (x <= 500) System.out.println(x+=i); Now, when I print x, it gives me the numbers 1-501. I'm assuming there is something wrong with my while loop?
Well, just consider what happens when x is 500.
Also, consider what happens when i increments to 2...what is x's value?
|
On December 31 2013 05:28 Housemd wrote:Show nested quote +On December 31 2013 04:46 Cyx. wrote:On December 31 2013 04:33 Housemd wrote:
I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for (int i = 1; i <= 100; i++){ System.out.println(i); }
I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.
Not looking for the answer, just some help on introducing the while loop.
Should I initialize a new variable? How would I print out the multiples? Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i. introduce a new variable x, state (while x <=500), print out x and increment it by i. Thanks for the help. Just a couple of questions. int x = 0; for (int i = 1; i <= 100; i++){ while (x <= 500) System.out.println(x+=i); Now, when I print x, it gives me the numbers 1-501. I'm assuming there is something wrong with my while loop?
You're making a pretty big assumption on what x+=i will return and your assumption is wrong.
|
Is lazy initialization always good to use or is there a point of "overuse"? Example code:
private File theFile; ... public File getFile() { if (theFile == null) { theFile = new File(PATH); } return theFile; }
|
No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns.
|
On December 31 2013 08:06 Blisse wrote: No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns. The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit.
Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so?
|
On December 31 2013 05:28 Housemd wrote:Show nested quote +On December 31 2013 04:46 Cyx. wrote:On December 31 2013 04:33 Housemd wrote:
I also have to use a while loop inside a for loop. I got the simple part down, which is printing out the numbers. I have: for (int i = 1; i <= 100; i++){ System.out.println(i); }
I've tried numerous ways to get the answer. For example, one attempt was to introduce a new variable x, increment it by one and state (while x <=500), print out i. Does not work.
Not looking for the answer, just some help on introducing the while loop.
Should I initialize a new variable? How would I print out the multiples? Yeah, you should probably be using a new variable ^^ Your approach seems basically right so far - the only thing you're doing wrong basically is incrementing by one inside your new while loop instead of just increasing it by i. introduce a new variable x, state (while x <=500), print out x and increment it by i. Thanks for the help. Just a couple of questions. int x = 0; for (int i = 1; i <= 100; i++){ while (x <= 500) System.out.println(x+=i); Now, when I print x, it gives me the numbers 1-501. I'm assuming there is something wrong with my while loop?
Nope, it's doing exactly what you're telling it too 
Once i = 2 (second time it goes through the outer loop), x is still <= 500, since you set it to 0 outside of the loops. If you want the while loop to run every time i increments, set x=0 within the for loop. You also may want to set x+=i before the println, then just print out x.
|
On December 31 2013 08:38 Tobberoth wrote:Show nested quote +On December 31 2013 08:06 Blisse wrote: No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns. The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit. Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so?
I'm not sure how files are handled by OS especially when they're big. But if they take more memory because of their larger size, then I can see a benefit if lazy initialization is used in this case.
|
On December 31 2013 08:38 Tobberoth wrote:Show nested quote +On December 31 2013 08:06 Blisse wrote: No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns. The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit. Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so?
On December 31 2013 08:06 Blisse wrote: No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns.
Applying programming paradigms are extremely important, design patterns are kinda important.
Pre-optimisation and over-engineering however is a bad thing. Some companies use a "computer architect" to come up with an over-engineered UML design before implementing it, that certainly is really stupid.
His example is a classic case of pre-optimisation, not 'applying a design pattern'. It also has nothing to do with a programming paradigm.
You should never ever neglect learning programming paradigms. Mastering programming paradigms will speed up productivity and make sure your code is nice and clean. It basically allows you to write clean code without even having to think about it. People in this thread who need help on cleaning up their code are usually suffering from not knowing the paradigm enough.
|
He's not pre-optimizing anything though. He's asking a question about applying a design pattern. We're saying to be careful of over-using programming paradigms/patterns in cases where they're not necessarily useful. Part of learning a paradigm is to actually learn when they're actually useful, and part of learning paradigms in general is understanding when to use them and when not to, and being wary of overusing them, which is what he originally asked about.
Anyways, it worked, because now he's asking questions about what situations where applying the pattern would be relevant. I think I could have gone into it directly though without the side tangent against overuse. I may have misunderstood the question the first time.
On December 31 2013 18:13 darkness wrote:Show nested quote +On December 31 2013 08:38 Tobberoth wrote:On December 31 2013 08:06 Blisse wrote: No point in applying programming paradigms unless you actually have a use for them. In this case, do you actually care about the performance gains of whether you initialize the object at start-up versus run-time, or is the lazy initialization driven by an I/O or possibly a time-sensitive event? If no, then no point in applying it, same with all other patterns. The classic "You'll never use it" anti-pattern. Focusing so hard to programming paradigms and design patterns that you spend more time planning code than writing it and therefor never getting any benefit. Write code, refactor it later. Why lazy initialize something unless you know there's a definite benefit to doing so? I'm not sure how files are handled by OS especially when they're big. But if they take more memory because of their larger size, then I can see a benefit if lazy initialization is used in this case.
Yes, you would see memory (maybe performance as you said) benefits because you're not holding a reference to the large File object.
But most of the time, that would never happen.
When working with files, the standard protocol is keeping the file path, and when you need to do work on it, open the file, do the work, then close the file object.
It is pretty bad practice to keep references to things like files. Mainly because you may forget to deallocate them and you'll have a memory leak, whereas `open, work, close` is very clear.
An example of lazy initialization:
Suppose you had an application that communicated with a server. Typically when the application starts up, you would setup most of your objects, and then begin communication. However, if the server communication is I/O driven, suppose, the user had to type in a password 1234 before anything would happen, then it may be nice to delay setting up until after the password is entered, because you don't necessarily need anything yet. And if the password is not entered or if the user quits, then you wouldn't have wasted time/resources setting up. If the password is entered, then you can now initialize your objects. Of course, this is a poorly engineered example, but hopefully you can see a use and a possible benefit.
On a side note, it is really weird to work coincidentally on 3 separate, dependant projects.
Project C (and in the future, D), are dependent on a common base B, which is dependent on another library, A, all of which I'm writing. Very strange. But it's entertaining being able to engineer all parts of the project and applying crazy design patterns all over the place because I'm bored.
Also, I saw a place in my code where a function had 8 lines of code and I remembered the argument a couple pages back here. Haha.
|
|
|
|
|
|