Results 211 to 240 of 356
Thread: ProgrammersitP
-
2013-01-25, 02:16 PM (ISO 8601)
- Join Date
- Nov 2006
Re: ProgrammersitP
You might want to initially consider the GUI as an interface between users and the command line interface. So rather than scripting a button to perform some action, script the button to call the command line script with some parameters to perform said action. Then when you go to build your GUI, you can go back and change things.
Another way of looking at this is the Model-View-Controller.
My problem is trying to find the right combo of language and GUI framework. And I guess the former should take precedence over the latter, so these are the main four I've been looking at:
- Python: I have a working knowledge of it already, but there seems to be a surprising lack of coherent documentation. I understand that programming is jargon-y by nature, but it feels almost as if the people who write the documentation go out of their way to be exclusive of beginners. Plus there's the whole 2.7/3.x divide that makes the right documentation even harder to find. And a lot of the GUI frameworks for Python seem to be dead projects (e.g. Pygame?).
- C++: I've heard this is a really good language to know all-around, but I've also heard that it's much more confusing than Python, and much harder to read. And I don't really understand its strengths and weaknesses compared to, say, Python. But it seems to be infinitely better documented.
- C#: Windows-only, I think? So I'd rather use something else.
- Java: I'm trying to avoid Java, since I've been told that it's going the way of the dinosaur (perhaps even more quickly due to the recent security problems).
I don't think there's an engine for the type of game I'm writing (sort of stat-based strategy, strongly text-based), so I'm looking for a framework for now.
Ideally I'd like something cross-platform. I don't need anything complicated as far as GUI—text, buttons, forms, photos, and that's it. But I have no idea what sort of technical features I'm supposed to be looking for in a framework.
TL;DR version: For programming a simple(ish) game, is it worth learning a language other than Python in order to have better documentation and GUI frameworks? And what framework should I use?
ETA: And I've tried TKinter for Python, and it seemed pretty awful. And I've heard people say it's awful compared to a lot of frameworks.Avatar by araveugnitsuga | Play by Post (Guide) | Steam
Homebrewers' Extended Signatures
Hey Look, a Summer Reading List!
-
2013-01-26, 01:09 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
I'm in a programming debate with one of my friends. (About Java)
Are public variables fine, or should you provide accessors/mutators? Defend your position.Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-01-26, 02:48 PM (ISO 8601)
- Join Date
- Dec 2008
- Location
- Malsheem, Nessus
- Gender
Re: ProgrammersitP
Depends entirely on the scope and intended use of your project. The product my team is developing at work has several hundred thousand lines in several dozen files, and it interacts with more than four other products developed by different teams. It's not in Java, but it still has global variables accessible by outside functions, and in that context using public variables that could be modified from anywhere would be an absolute nightmare for debugging and workflow tracing.
I've also written many programs for my own use, which are narrowly-scoped and fairly small; I've given them to plenty of people to use, but I'm the only one who's ever going to work on them. In that context, writing up accessors and mutators for all the variables I need to use in multiple files is a waste of time and effort, since I wouldn't really gain any of the benefits of encapsulation.
Most of the time, the problems caused by public variables arise when someone thinks they're working on the latter kind of project but either it is the former kind or it was the former kind and grew into the latter kind over time. As long as you use accessors and mutators when they're really needed, using public variables the rest of the time is fine.
-
2013-01-26, 03:58 PM (ISO 8601)
- Join Date
- Jul 2007
- Gender
Re: ProgrammersitP
I have the philosophy that variables should be as public as possible. If the variable can hold any value, and I`m sure it would be the same with subclasses, I make it public (changing it directly couldn`t harm the code, so why write unnescery getter and setter methods?).
If I want to preform some other actions whenever the value is changed, or if certain values would cause issues (null for Object refrence, in some cases) I make the variable protected.
If, for some reason, I want to make sure that even subclasses would be restricted in their ability to modify the variable, I make it private.Madly In Science, an RPG in which you play mad scientists, you can get it for free.
Spoiler: Some other things.
-
2013-01-27, 01:43 PM (ISO 8601)
- Join Date
- Feb 2010
- Location
- UK
- Gender
Re: ProgrammersitP
A common school of thought is to keep a variable private unless it you have situation:
Code:class Foo { private: Bar x; public: Bar getX() const {return x;} void setX(Bar val) {x = val;} };
However, I have found that I've been in this situation and I've wanted to replace x* with something else (whenever I used it it was being converted into different units which weren't human friendly) so I changed it to get() and set() functions which would do the conversion for me because this conversion was happening thousands of times per frame and became a real bottleneck.
This made me wish I'd kept x private and just used get()/set() functions for it because I could have just changed the class definition. As it was I had to go and change the many references to it by hand. :-(
*It wasn't actually called x. I forget what exactly it was.
-
2013-01-27, 02:08 PM (ISO 8601)
- Join Date
- Mar 2009
- Location
- Sweden
- Gender
Re: ProgrammersitP
The official Java Code Convention discourages public class or instance variables unless there's a good reason for it. Writing basic getters and setters is no great effort to start with anyway.
Clouddreamer Teddy by me, high above the world, far beyond its matters...
Spoiler: Banner by Vrythas
-
2013-01-27, 03:30 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
I looked it up and saw this:
One example of appropriate public instance variables is the case where the class is essentially a data structure, with no behavior. In other words, if you would have used a struct instead of a class (if Java supported struct), then it's appropriate to make the class's instance variables public.Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-01-27, 04:43 PM (ISO 8601)
- Join Date
- Mar 2009
- Location
- Sweden
- Gender
Re: ProgrammersitP
Well, if you know for sure that you never will want to add or change functionality, and no one else other than you is going to have to maintain or interface your code, well, then I suppose it's okay. But as I said, writing getters and setters is a non-effort, and can generally be done automatically in more advanced IDEs.
Clouddreamer Teddy by me, high above the world, far beyond its matters...
Spoiler: Banner by Vrythas
-
2013-01-27, 04:50 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
Yeah... I'm still using BlueJ (although I am using getters and setters).
Does anyone have a recommendation for a more advanced IDE that still has that map of all your classes and dependencies? That part of the interface is the only real reason I'm still using BlueJ; I don't want to give it upAvatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-01-28, 08:03 PM (ISO 8601)
- Join Date
- Oct 2009
Re: ProgrammersitP
I´m going to sound like a broken record but
IntelliJ, it even has it in a pretty nice matrix structure
http://www.jetbrains.com/idea/featur..._analysis.html
or the normal uml class diagram
http://www.jetbrains.com/idea/featur...s_diagram.htmlLast edited by Emmerask; 2013-01-28 at 09:09 PM.
-
2013-01-29, 05:28 AM (ISO 8601)
- Join Date
- Jul 2007
- Gender
Re: ProgrammersitP
I`d like to note that some classes in the offical Java API break this convention.
Exemples:
Last edited by akma; 2013-01-29 at 05:32 AM.
Madly In Science, an RPG in which you play mad scientists, you can get it for free.
Spoiler: Some other things.
-
2013-01-29, 01:58 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
Oh wow, it does.
java.awt.Polygon, lines 253-260:
Code:if (x < bounds.x) { bounds.width = bounds.width + (bounds.x - x); bounds.x = x; } else { bounds.width = Math.max(bounds.width, x - bounds.x); // bounds.x = bounds.x; }
Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-01-29, 07:22 PM (ISO 8601)
- Join Date
- Jun 2007
- Location
- Switzerland
- Gender
Re: ProgrammersitP
Just wondering if any of you has had (or has) access to an Intel Xeon Phi card? I would love to run a benchmark problem before I receive it in the office.
We should be getting one in the office mid-february to run our massive optimisations of energy assets on. I am very excited! Hardware has really advanced massively in the last few years with the advent of graphic card number crunchers, sadly the problem we have was not one that translated to the graphic card easily, whereas the Xeon phi is just a 60 core, 240 thread monster that I expect will give us excellent numbers...
So do any of you do highly parallel programming, optimization problems or large workloads? OpenMP, MPI or others parallelization techniques?
-
2013-02-02, 02:48 AM (ISO 8601)
- Join Date
- Mar 2009
Re: ProgrammersitP
I need some help with a program for school that I'm derping on. Miscrosoft Visual Basic 2010
Spoiler
I'm supposed to fix the error, but I can't remember/think of how.Last edited by Mystic Muse; 2013-02-02 at 02:50 AM.
-
2013-02-02, 07:56 AM (ISO 8601)
- Join Date
- Oct 2009
Re: ProgrammersitP
You can´t make a label to a string, a label object is a lot more then the string it displays, it will most likely (not a vb expert^^) have stuff like textcolor, backgroundcolor, other format stuff, enabled disabled bool etc in it.
what you can do however is
lblEnding.Text = decEnding.ToString("2")
ie setting the text of the label to the stringLast edited by Emmerask; 2013-02-02 at 08:07 AM.
-
2013-02-02, 12:40 PM (ISO 8601)
- Join Date
- Mar 2009
Re: ProgrammersitP
Thanks a bunch.
I'll be sure to remember this thread when I'm having trouble with homework in the future.
-
2013-02-02, 01:38 PM (ISO 8601)
- Join Date
- Nov 2006
Re: ProgrammersitP
I do a lot of OpenCL programming. Haven't had a chance to use one of the Intel cards though. We were more interested in scaling across multiple GPUs, and I'd much rather submit jobs to the supercomputer for MPI work.
Let me know how it goes though! My mentor was looking into buying a rig of Teslas, so...Avatar by araveugnitsuga | Play by Post (Guide) | Steam
Homebrewers' Extended Signatures
Hey Look, a Summer Reading List!
-
2013-02-02, 06:02 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
Is this bad practice?
Code:public class SomeClass { private OtherClass o = new OtherClass(); public void someMethod() { System.out.println(o.var); } private class OtherClass { private int var = 3; } }
Last edited by Razanir; 2013-02-02 at 06:02 PM.
Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-02-02, 08:13 PM (ISO 8601)
- Join Date
- Jun 2007
- Location
- Switzerland
- Gender
Re: ProgrammersitP
Well it simply shouldn't work. The OtherClass.var being private means it cannot be accessed from the outside, not even to be read. In java, it should either be public, protected or without modifier (see here).
Oops, sorry, forgot about the rules of Nested classes in java. Carry on, it would work. Since it's a nested class, the outer class has access to the inner private variables.
A class instantiating another is not bad practice, but I would recommend to instantiate the OtherClass inside the SomeClass constructor (which you didn't have here in this example).Last edited by Ashtar; 2013-02-02 at 08:19 PM.
-
2013-02-02, 08:26 PM (ISO 8601)
- Join Date
- May 2009
Re: ProgrammersitP
What're some examples of when using nested classes would be good? Looking at Ashtar's link, I can't really imagine when you would use one instead of incorporating that code into the main class.
-
2013-02-02, 08:55 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-02-03, 05:00 AM (ISO 8601)
- Join Date
- Mar 2009
- Location
- Sweden
- Gender
Re: ProgrammersitP
Not as far as I know. Since the nestled class is private, you don't have to be afraid that someone will use the direct access to modify the value illegitimately.
Sometimes you need a class for a task inside another class, but which holds no use outside said class (concider a list element in a specific type of list. Even if you make other lists, you may want to give them a different intern representation).
Other times, you may have a class so strongly linked to the first class that even if you make it public, you may want to nestle it inside the first class to make the relationship obvious (consider an Exception for a specific type of behaviour of the first class. Even if you might want to raise said exception outside the first class, making the relationship obvious is a good way to prevent misuse).Last edited by Teddy; 2013-02-03 at 05:04 AM.
Clouddreamer Teddy by me, high above the world, far beyond its matters...
Spoiler: Banner by Vrythas
-
2013-02-08, 01:15 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
printf and NumberFormat. Both work just fine for formatting numbers for output. How would I go about it if I wanted some dollar amounts in accounting format
Code:NumberFormat.getCurrencyFormat(): $1.00 $10.00 $100.00 Accounting format: $ 1.00 $ 10.00 $100.00
Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-02-08, 07:49 PM (ISO 8601)
- Join Date
- Feb 2010
- Location
- UK
- Gender
Re: ProgrammersitP
For printf() you'd use the width and precision modifier: "%[width].[precision]f" for a float. Precision is the number of decimal places and width is the number of characters it takes up (including decimal point), so your second example would be:
Code:printf("$%6.2f",val);
Code:cout << "$" << setiosflags(ios::fixed) << right << setwidth(6) << setprecision(2) << val;
Last edited by Capt Spanner; 2013-02-08 at 07:49 PM.
-
2013-02-08, 10:16 PM (ISO 8601)
- Join Date
- Oct 2011
- Location
- The last place you look
- Gender
Re: ProgrammersitP
Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.
I am a 10/14/11/15/12/14 LG Clr 2
-
2013-02-09, 10:15 AM (ISO 8601)
- Join Date
- Jul 2007
- Location
- Airstrip One
Re: ProgrammersitP
Fortunately, Java does implement a number of printf functions, including one in PrintStream, and helpfully they use a format syntax drawn from C. If you want to store the string internally, you can use the String.format function instead. There are other ways of doing it, but those two both work.
Example code using your data and the format string from Capt Spanner:
SpoilerCode:class FormatDemo { public static void main(String[] args) { String format = "$%6.2f%n"; // The addition of a %n to the format string just adds a line // break at the end. // Using printf() System.out.printf(format, (float) 1); System.out.printf(format, (float) 10); System.out.printf(format, (float) 100); // The values need to be cast because otherwise an exception // is thrown - Integers are not floating points but neither // is the precision field valid when formatting integers. System.out.println(); // Using String.format() String val1 = String.format(format, (float) 1); String val2 = String.format(format, (float) 10); String val3 = String.format(format, (float) 100); System.out.print(val1); System.out.print(val2); System.out.print(val3); } }
Code:$ 1.00 $ 10.00 $100.00 $ 1.00 $ 10.00 $100.00
-
2013-02-11, 03:24 AM (ISO 8601)
- Join Date
- Mar 2009
Re: ProgrammersitP
Okay, I need some help again. (Microsoft Visual Basic)
Spoiler
Here's what the base program looks like. I need to modify it so that the program can calculate a sales commission based on the number entered, using the (As the book calls it) If/ElseIf/Elf form of the Ef then else statement.
Monthly salesCommission Rate0-19,999.994%20,000-29,999.995%30,000-39,999.996%40,000-49,999.997%50,000 or more9%Less than 00%
Spoiler
There's what the program itself looks like, if that'll help at all.
EDIT: I specifically have to enter in 22,000 and get back the commission accurate to 2 decimal places.Last edited by Mystic Muse; 2013-02-11 at 04:51 AM.
-
2013-02-11, 07:26 AM (ISO 8601)
- Join Date
- Feb 2007
- Location
- Manchester, UK
- Gender
Re: ProgrammersitP
You'd have to do something like assigning the values from the text box to a numeric variables (say, MonthlySales), then do your calculation:
If MonthlySales < 0 Then Commission = 0
Else If MonthlySales >= 0 And MonthlySales <= 19999999 Then Commission = MonthlySales * 0.04
.
.
.
Else Commission = MonthlySales * 0.09
End If
(The bit in the middle left as an exercise for the reader). Have to say that I wouldn't use an If...Then construct for this anyway, because it's going to be a pain to maintain if any of the brackets or percentages change, but if that's what the book is telling you to do that's the way to go about it.
-
2013-02-11, 12:51 PM (ISO 8601)
- Join Date
- Oct 2009
Re: ProgrammersitP
You could also just start with the highest and work down to lowest, this way you only have to check against one statement ie:
if MonthlySales >= 50000 Then Commission = MonthlySales * 0.09
else if MonthlySales >= 40000 Then Commission = MonthlySales * 0.07
.
.
.
else if MonthlySales >= 0 Then Commission = MonthlySales * 0.04
at least if vb treats else if the same as java which I´m fairly certain it will
ie leave the rest of the else ifs alone after finding the first correct one...after all why call it ELSE if otherwise
/edit oh and don´t forget to check the user entry in the MonthlySales Field, either check it after the user typed or make the textfield only accept numeric values and points.Last edited by Emmerask; 2013-02-11 at 02:12 PM.
-
2013-02-11, 01:52 PM (ISO 8601)
- Join Date
- Nov 2006
Re: ProgrammersitP
Does anyone here have any skill with C systems programming? I've been trying to read file permissions of all files in a directory, but everything comes up [----------] (i.e. 000) when I lstat() and bitwise & to check the flag.
Avatar by araveugnitsuga | Play by Post (Guide) | Steam
Homebrewers' Extended Signatures
Hey Look, a Summer Reading List!