|
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. |
Our system has huge customers so it's going to be many users using this and it my question is how you know that you don't write huge bottlenecks in your code?
by many users you mean concurrent access to data? If so, you should take extra care on thread synchronism so you dont end up with an inconsistent database.
keep an eye on these little things: - nested loops (for inside for inside for is unnacceptable) - use threads to deal with long data processing so you dont have your user interface locked waiting for the process to finalize - use MVC in your projects since it will make everything easier to maintain
Another specific program I wrote yet I questioned the effectiveness of my code is this example: My java program receive a path to a file and you are to copy it onto another directory but you need to make sure it don't override anything so it should get an incremental number. So how do you determine the next number in an efficient way? the directory looks like this: yourfile1, yourfile2, yourfile7, yourfile3, yourfile5, other file, other file, other file.
you could use a file to store the last index. When you first run the program in the day it would load the data from the file and keep it on memory for the rest of the execution, updating it only on memory. When the execution is finished you store the new value back to the file.
It might need some failure tolerance system so when your program crashes for some reason, before closing it entirely the index file would be updated, otherwise you might end up with a not updated file that could possibly wrongly overwrite a file.
|
That method ends up with holes in the numbering
Say you have yourfile1, yourfile2, and yourfile3. Now, you delete yourfile2. Either your next file should become yourfile2 or yourfile4. If the latter, that means yourfile2 would never be used again, which in turn also means you're also keeping an index for every single file ever saved, which strikes me as horribly inefficient.
Seems to me you'd want something that's checking the existing files for what to name it, rather than trying to store an index for every single thing.
|
why horribly inefficient?
performance wise adding an index to a file name is much faster than verifying the existence of such file since you avoid IO operations.
he doesnt mean to use an index file to reference all the files in the directory, but an index on the name of the files. The index is meant to differentiate file versions I believe.
|
i've been learning haskell, seems like a fun lazy language to play around with after all this strict type languages i've been coding in
|
On July 10 2011 06:05 Patriot.dlk wrote: I have a question regarding writing effective code using java? I often come up with solutions I like but I can't really grasp if I did a good solution or not.
My education in informatics had about 10 weeks of java.
Now I'm a developer since about 6 weeks and man I have a blast. So far it's been java only. My department develops this ERP system and I have mostly been doing adaptations and integrations that customers bought. Basically handle input/output to our ERP and other systems. But this Friday my scrummaster approached me asking if I would mind being assigned doing a new feature. It's about logic regarding if it's a swedish holliday or not and if so determining the closest work day. Basically I will have to use mathematical algorithms works out the next occurrence.
This will be implemented in this big ERP through a jsf layer. Our system has huge customers so it's going to be many users using this and it my question is how you know that you don't write huge bottlenecks in your code?
Another specific program I wrote yet I questioned the effectiveness of my code is this example: My java program receive a path to a file and you are to copy it onto another directory but you need to make sure it don't override anything so it should get an incremental number. So how do you determine the next number in an efficient way? the directory looks like this: yourfile1, yourfile2, yourfile7, yourfile3, yourfile5, other file, other file, other file. Best is to always think about. Can I generate the outputs beforehand and use some simple look-up instead of the whole computation ? Can I store some extra variables somewhere to speed up my algorithm, can this be cached ? Is it being invoked as a separate process everytime or does the runtime persist in memory ? Can it be done in parallel ?
Both your problems can be solved with the above. Generate the days beforehand and store the next number somewhere.
You can never be sure if you are not creating a bottle neck. In the end you just have to go with the best solution you can come up with and then do the performance test when you finish with the prototype.
|
Hello I've been doing PHP for three years by my self and C# for two years at school. I love to program but it's very hard sometimes and I find it some way difficult understanding purposes of classes. Methods/functions is fully understandable for me, they are great and make me save a lot of code and can return values, etc etc.
Classes, what I've heard from my teacher and been reading in my big thick book is that classes are used to be used by instances of other object to the class, and that the class is like a design for the object. Although I don't am fully sure what the purpose is I can still use them in code, but not in bigger programs. I feel that I would love some explanations and not only from my teacher, because she is explaining it not very well for me, personalty. So thanks if anyone could tell me more about classes and what they are for really, and how they works.
Big thanks and sorry for my bad language of English.
|
On July 10 2011 08:13 Moxi wrote: Hello I've been doing PHP for three years by my self and C# for two years at school. I love to program but it's very hard sometimes and I find it some way difficult understanding purposes of classes. Methods/functions is fully understandable for me, they are great and make me save a lot of code and can return values, etc etc.
Classes, what I've heard from my teacher and been reading in my big thick book is that classes are used to be used by instances of other object to the class, and that the class is like a design for the object. Although I don't am fully sure what the purpose is I can still use them in code, but not in bigger programs. I feel that I would love some explanations and not only from my teacher, because she is explaining it not very well for me, personalty. So thanks if anyone could tell me more about classes and what they are for really, and how they works.
Big thanks and sorry for my bad language of English.
Classes are the embodiment of Object Oriented (OO) programming. I don't fully know how C classes work, but have programmed in Ruby and now Java, both of which are OO languages. If you want first hand experience with classes and OO programming, pick up Ruby for a few weeks, or Java if you want to get more involved. But the basic point of a class is as follows:
From "The Book Of Ruby"
"A ‘class’ is the blueprint for an object. It defines the data an object contains and the way it behaves. Many different objects can be cre-ated from a single class. So you might have one Cat class but three cat objects: tiddles, cuddles and flossy. A method is like a function or sub-routine that is defined inside the class."
A class is, in Java, essentially a special variable type. You have ints, chars, longs, etc. and you also have more complex classes, for example a class called Dog. The dog class has "fields", its own variables, for example a String name. Classes also have methods, like speak() which would print "Woof" to the screen. So how would one use the Dog class? Create a dog object. Just like you would create an int i or a char c, create a Dog myDog. Then you can set its name or make it speak. You can create many different dogs off of the same class: myDog, yourDog, hisDog, and they all have different fields (i.e. different names). So how is this used practically? Think games: you create a class Unit, with fields for hp, mana, experience, et cetera, then create objects based off of the class.
Java example of the Dog class:
package mainPkg;
public class Dog{ String name = ""; //Create a field for storing the dog's name public void setName(String aName){ //define a method for the dog class name = aName; //set the "name" variable of the dog to "aName" } public void sayName(){ //define another method for the dog class System.out.println(name); //print the variable "name" to the screen } //This is the end of the actual Dog class. The rest simply creates 2 dogs, //sets their names, then prints their names. public static void main(String[] args){ //method run when program starts. Dog myDog = new Dog(); //create a Dog and store it in myDog Dog yourDog = new Dog(); //create another Dog myDog.setName("Fido"); //call the setName() method of myDog; yourDog.setName("Zeke"); //call the setName() method of yourDog; //At this point, the "name" field of myDog is equal to "Fido" //and the "name" field of yourDog is equal to "Zeke". //have each dog print its name field to the screen myDog.sayName(); yourDog.sayName(); } }
|
He answered above, but in case you still don't get it:
Moxi, classes are just a way of making code more understandable. Anything you can program with classes, you could also program without them. Their purpose is only to make coding easier/more understandable.
There are tons of simple examples like a Student class that holds information about a student such as name, grade, etc. You can make functions in the student class that can only be called on an instance of the student class, which is a student object. So you have the student class, which you make an object of(also called instance of student class), and then you can call functions on that object that you've defined for the student class.
But of course you could just use some other form of data structure to keep track of the information in a different way. The class essentially abstracts what goes on at a lower level and behind the scenes. I can't really relate it to C# but as I'm sure you know C# uses tons of what you would call 'classes' just like Java does. All they do is make coding simpler, or more abstract, for the coder.
|
Classes are used in Object Oriented (OO) languages because they provide an easier way to code and manage your systems projects.
In OO your systems are developed through the relationship of objects, so when you want to change some aspect of your system you can change the model of your class and it will be applied to all the instances of that said class (which are their objects).
|
I may add, if you completely don't understand OO programming, it's basically a really easy way to understand programs by making them work like real objects. You set traits of things and make them do stuff. Literally. For example, in Minecraft, you create a "Block" object, set its location with a "Location" object, and set its type with a "Material" object. A trigger when a player moves gives you a "Player" object, with coordinates, name, inventory, etc. It is a much easier way for a human being to understand a complex program.
|
http://pastebin.com/LgrUGjFU
Keep receiving an error on my char ch = choice.charAt(0); line
I think it has something to do with me usint integers maybe? Only reason I think it could be that is that I used this same line in previous program which didnt use integers....Either way though not sure how to change it / how to fix it. Thanks for the help
|
When posting to troubleshoot like this it would be helpful if you included the actual error message :p. Anyways, variable choice is not defined anywhere in your code so I guess thats why you get that error. You probably want to do something like this before your error line (not sure about the scanner next() call, might have to use some other. Read up the API):
String choice = input.next();
|
|
Slightly off topic but still related. What programming environment tools does everyone here use and would recommend?
ie. What IDE do you use for X language? What CVS do you use? What project management/bug/issue/storycard system do you use? What tools for functional and unit testing do you use? What continuous integration or automatic deployment do you use?
I'm curious but also looking at improving my current workflow so I'm open to all suggestion. I'm currently looking at using the following for a small team: Jira w/ Agile plugin for storycards/issues/bugs Mercurial w/ bitbucket for CVS Jenkins OR Bamboo for CI, I'll have to trial both to see what fits.
|
Ruby related question.
What's the adoption of Ruby 1.9.2 in the general populace? I'm trying to learn Ruby and 1.9.2 is a pain in the ass to set up right. Most of the current all-in-one installation are still bundling with 1.8 so I'm thinking of just ditching it and go with 1.8 as this is only for learning purposes.
|
On July 10 2011 11:53 ibutoss wrote: Slightly off topic but still related. What programming environment tools does everyone here use and would recommend?
ie. What IDE do you use for X language? Most coding I do is in either C++ or Python; I use Emacs for both. I do miss Visual Studio though, particularly for C++.
What CVS do you use? I use Git for my personal projects, and Subversion for my research group's projects.
A while ago the group switched from CVS. I used to be of the opinion that CVS->Subversion gets you about 95% of the benefit that you'd get from CVS->Git, but I now put it closer to about 60-70%. Git really is substantially better IMO.
(There are other VCSs that are of similar quality, most notably Mercurial; I haven't used it much, but there are personal preference reasons that I am pretty sure I like Git's model more.)
What project management/bug/issue/storycard system do you use? Trac. What it's missing though out-of-the-box is dependencies ("bug 23 blocks bug 34").
What tools for functional and unit testing do you use? Functional tests are sort of hand-rolled. For unit testing I've recently started using the Google Test library. I have some.. desired improvements, but overall it's pretty good.
What continuous integration or automatic deployment do you use? Buildbot, assuming that fits your definition of CI. It's got one big missing feature for our particular case (the ability to cobble together a single build from multiple repositories), but other than that it's one slick piece of software.
|
|
On July 10 2011 12:35 haduken wrote: Ruby related question.
What's the adoption of Ruby 1.9.2 in the general populace? I'm trying to learn Ruby and 1.9.2 is a pain in the ass to set up right. Most of the current all-in-one installation are still bundling with 1.8 so I'm thinking of just ditching it and go with 1.8 as this is only for learning purposes. I haven't used Ruby in a while, but I think 1.9.x is out on most linux package systems for stable, which probably means a good deal of those systems have it. Any particular reason why you need to use on of all-in-one installations? Its not that hard to install it yourself (and if you're on windows, there are Ruby installers available for everything up to 1.9.2 anyway)
On July 10 2011 13:43 EvanED wrote:Show nested quote +On July 10 2011 11:53 ibutoss wrote: Slightly off topic but still related. What programming environment tools does everyone here use and would recommend?
i.e. What CVS do you use? I use Git for my personal projects, and Subversion for my research group's projects. A while ago the group switched from CVS. I used to be of the opinion that CVS->Subversion gets you about 95% of the benefit that you'd get from CVS->Git, but I now put it closer to about 60-70%. Git really is substantially better IMO. (There are other VCSs that are of similar quality, most notably Mercurial; I haven't used it much, but there are personal preference reasons that I am pretty sure I like Git's model more.) Git is awesome, can't recommend it enough. I use TFS at work, and while the integration with Visual Studio is nice, I just like Git's setup a helluva lot better. SVN and SVN-derivative version control results in a lot of situations where developers don't check in their code because they don't want to have stuff affect other developers until its 100% complete. With Git and having a repository locally for each developer, you avoid those problems and people are allowed to freely manage their own code and place checkpoints they can always roll back to, without affecting the other developers. Its definitely confusing to understand that when you move to it from SVN, but its oh so worth it.
|
On July 10 2011 11:53 ibutoss wrote: Slightly off topic but still related. What programming environment tools does everyone here use and would recommend?
ie. What IDE do you use for X language? What CVS do you use? What project management/bug/issue/storycard system do you use? What tools for functional and unit testing do you use? What continuous integration or automatic deployment do you use?
I'm curious but also looking at improving my current workflow so I'm open to all suggestion. I'm currently looking at using the following for a small team: Jira w/ Agile plugin for storycards/issues/bugs Mercurial w/ bitbucket for CVS Jenkins OR Bamboo for CI, I'll have to trial both to see what fits.
I use the whole Rational suite for every aspect of the above except unit testing (you can guess who is my employer). For unit test just simple old JUnit and we have been playing a little bit with BDD frameworks (JBehave mainly) which does look promising.
|
I use Eclipse for Java (mainly because I started learning Java when I got an Android powered phone. Go figure). I'm pretty fond of it, does what I want it to easily. My biggest complaint is that it is a java app, so if I fuck up a program and need to kill the process, I play Russian roulette with which of the 2 javaw.exe is my program and which is the IDE.
|
|
|
|