2/28/2013 - Update on Thumb
12/31/2012 - There's a New Comic
12/12/2012 - The "Lost" Holiday Ornament (and Child's Play)
11/26/2012 - Leftover OOTS Swag on Sale (+Thumb Report)
Frequently Asked Questions (FAQ)

Order of the Stick 889 Get Real
Erfworld 163 The End of Book One
Erfworld Now at Erfworld.com!
RSS Feeds: OOTS

The Duke's Wolf, Part Four by Amber E. Scott
The Duke's Wolf, Part Three by Amber E. Scott
The Duke's Wolf, Part Two by Amber E. Scott

The New World, Part 9: Barbarians by Rich Burlew
The New World, Part 8: Gnomes by Rich Burlew
The New World, Part 7: Names and Cultures by Rich Burlew
Looking for the Gaming Articles?

 



Welcome back! Be sure you have read and understand the Forum Rules.


Go Back   Giant in the Playground Forums > Discussion > Friendly Banter
Register FAQ Members List Mark Forums Read End

Friendly Banter Hellos, goodbyes, and other casual conversation goes here. Especially if it doesn't fit better into one of the other forums.

Reply
 
Thread Tools
Old 10-23-2012, 01:03 PM   Top  -  End  -  #91
Teddy
Troll in the Playground
 
 
Join Date: Mar 2009
Location: 
Sweden
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by Neftren View Post
Similarly, in C/C++, int* i makes much more sense than int *i, as you would read it as an integer pointer. If in doubt, refer to your style guide (most companies or managed code bases typically have one somewhere).
Ahh, that one. On our first lecture on pointers in our C class, our lecturer completely failed to grasp how putting the pointer in front of the name could be confusing, even when I pointed out to him that...
Code:
int *x = y;
...and...
Code:
int *x;
*x = y;
...do two completely different things.

Myself, I used to write as you do before I (privately) found out how...
Code:
int* x, y;
...will declare y as an int, and not a pointer to an int. Now I just refuse to write the star together with anything in variable declarations. After all, I wouldn't do it with const, so why do it with *?

Quote:
Originally Posted by Neftren View Post
Also, for the last code example, Bubble Sort (and similar O(n2) algorithms)...? Why do you consider this useful?
Yeah, and especially when a better sorting algorithm (QuickSort) already can be found in the Arrays library. I mean, you could just write Arrays.sort(array), where array is the array you wish to sort, and you'd be done.
__________________
Engineer Teddy by me. We're refitting this steam locomotive in the spirit of Steampunk, but we need your help designing it: Enter_the_design_competition_today!
(And yes, my avatar is according to scale.)

Banner by Vrythas:
Spoiler

Last edited by Teddy : 10-23-2012 at 03:49 PM.
Teddy is online now   Reply With Quote
Old 10-23-2012, 01:32 PM   Top  -  End  -  #92
Alaris
Barbarian in the Playground
 
 
Join Date: Oct 2008
Default Re: ProgrammersitP

Quote:
[*]Where are you and what are you doing in terms of programming? Employment, education or in your spare time?
Early on in learning my programming. Looking for employment, but when I'm not, I'm trying to learn programming. At the end of the day, I might be able to make some money out of it, so why not learn it, right?

Quote:
[*]What language or languages are you using primarily at the moment? What's your favourite, and why?
Well, only learning one right now. That's Python. Technically fiddling with the sub-module of Pygame (as a crutch). Overall, the language is pretty straightforward... I've looked at C++ (or C+) and it gave me a headache really quick.


Quote:
[*]Where do you hope to go with your programming? Any plans for the future, or just waiting to see if anything of interest comes along?
Ideally? Full-time career as a programmer. My dad did it before me, so did my brother. And while some forms give me a headache, it's pretty cool what you can do with programming.

Quote:
[*]Any projects, personal or otherwise, you're in the middle of? Anything you're really focused on?
Umm... mostly just learning the language. Within the pygame module, I'm trying to learn to make a physics engine of some kind, but boy is that getting me stuck.

Quote:
[*]What environment do you work/prefer to work in? Netbeans/Eclipse/Command line and a text editor?
Standard IDLE for Python (if I'm right in what you mean). Debated trying others, but I don't want to get into complicated things honestly.

Quote:
[*]Any problems that are driving you mad? A piece of code not compiling right, or being off by one, or one little syntax error in a sea of code? Not quite grasping the logic of a particular piece of code?
Just that I have absolutely no clue where to start with a Physics engine. I've grasped basic python, and basic Pygame, but there are like... 0 Tutorials for Python 3.2 on it. So I'm stumbling blindly, and it's VERY time consuming.
__________________

Click above to watch my Let's Play of Dead Space! Episode 4 is out! (UPDATED ON: May 14, 2013)

NOTE: I am not interested in watching MLP: FiM. I would appreciate it if others would not try to convert me. I've had enough RL friends try to do that. Thank you.
Avatar: Thanks to asdflove for my avatar. ^_^
Alaris is online now   Reply With Quote
Old 10-23-2012, 01:42 PM   Top  -  End  -  #93
Neftren
Troll in the Playground
 
 
Join Date: Nov 2006
Default Re: ProgrammersitP

Quote:
Originally Posted by Teddy View Post
Myself, I used to write as you do before I (privately) found out how...
Code:
int* x, y;
...will declare y as an int, and not a pointer to an int. Now I just refuse to write the star together with anything in variable declarations. After all, I wouldn't do it with const, so why use it with *?
Ahh, yes, the precedence bit. I typically avoid declaring multiple variables on one line, so I don't really have that problem. To each their own I suppose.

Const is just one of those annoying keywords where I don't think anyone can really agree on what to do. I think most people prefer placing const before the type declaration, though off the top of my head, const should always be placed in such a way so as to modify the type to its immediate left (int const). I think this breaks on older compilers though. I haven't really tested it rigorously.

Quote:
Umm... mostly just learning the language. Within the pygame module, I'm trying to learn to make a physics engine of some kind, but boy is that getting me stuck.
Pygame isn't really designed to handle complex physics. The most I've ever gotten it to do is simple mechanics (e.g. handling kinematic equations, force application, etc.). You're not going to be able to get it to do anything in 3D or handle shadows/shaders/cloth simulation, at least, not with any sort of reasonable execution speed. Maybe if you hooked it into PyOpenCL or something to handle computations, but...

Quote:
Just that I have absolutely no clue where to start with a Physics engine. I've grasped basic python, and basic Pygame, but there are like... 0 Tutorials for Python 3.2 on it. So I'm stumbling blindly, and it's VERY time consuming.
I don't think the Pygame implementation for Python 3 is finished yet. At least, it wasn't last I checked. Most of the syntax between Pygame on 2.7 vs. 3.2 should be the same. If you're dead set on starting with a physics engine... you'll probably want to put together a calculations package containing the basic kinematic equations. As an aside, you'll have to tweak the numbers a bit to get the right feel (e.g. increasing gravity while falling, decreasing while jumping, to get that Mario feel).

Do you have some sort of goal, other than "I want to build a physics engine"?
__________________

Last edited by Neftren : 10-23-2012 at 01:52 PM.
Neftren is offline   Reply With Quote
Old 10-23-2012, 04:12 PM   Top  -  End  -  #94
Teddy
Troll in the Playground
 
 
Join Date: Mar 2009
Location: 
Sweden
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by Neftren View Post
Ahh, yes, the precedence bit. I typically avoid declaring multiple variables on one line, so I don't really have that problem. To each their own I suppose.
Yeah, when it comes to pointers, I usually do as well, but I felt like being prepared for when I want to do it one line.

Quote:
Originally Posted by Neftren View Post
Const is just one of those annoying keywords where I don't think anyone can really agree on what to do. I think most people prefer placing const before the type declaration, though off the top of my head, const should always be placed in such a way so as to modify the type to its immediate left (int const). I think this breaks on older compilers though. I haven't really tested it rigorously.
Yes, that seems about right, even though const int works as well. The unholy combination of const and pointers really messed up one of our lectures for a while. Our lecturer (a replacement that day, so it's kind of understandable) wrote the pointer stars together with the variable name rather than with the type (or stand-alone, for that matter), which meant that he couldn't figure out where to put the const keyword when trying to declare a constant pointer to a variable value. Since I by then had learned about how pointer stars acted in multiple declarations on a single line, I could figure out how to do it (by placing the const after the star) and make the example work.

It also annoys me slightly how both const and (especially) * are read from right to left. the utterly brilliant declaration char * * const * const x (auto-generated example taken from this site) gives you a constant pointer to a constant pointer to a pointer to a char. When I first saw it myself earlier today, I failed to grasp why the const keywords affected the pointers in that order, before I realised how it reads them right to left. Simple when you know it, but hard to realise on your own...
__________________
Engineer Teddy by me. We're refitting this steam locomotive in the spirit of Steampunk, but we need your help designing it: Enter_the_design_competition_today!
(And yes, my avatar is according to scale.)

Banner by Vrythas:
Spoiler
Teddy is online now   Reply With Quote
Old 10-24-2012, 07:47 AM   Top  -  End  -  #95
Miscast_Mage
Barbarian in the Playground
 
 
Join Date: Dec 2010
Location: 
Ireland
Gender: Male
Default Re: ProgrammersitP

Spoiler'd for length.

Spoiler
Miscast_Mage is offline   Reply With Quote
Old 10-24-2012, 08:38 AM   Top  -  End  -  #96
Gryffon
Orc in the Playground
 
 
Join Date: Jan 2010
Location: 
Myrtle Beach, SC
Gender: Male
Default Re: ProgrammersitP

So, coming a little late to the party, but here is a little about me:

I work in the Engineering group at my job, but my duties are mostly related to release management, so as my direct duties I deal mainly with things like Ant and Ivy. For my background I have a BS in Computer Science, and I did a little bit of graduate work(of which I'd like to do more). Most of programming is currently of the hobby variety, though I'd love to do more of it as my actual job. I've been employed for the same company for 10 years, but only worked in the engineering group for 6 of them. Did a little QA, then a little bit of bug fixing, then moved into more of a support role, leading to my being part of release management during a merger.

I've used a lot of languages for different purposes. C/C++ was the language my school used for teaching, and it's in place in a fair amount of our projects at work. I've done Java and JSP. I've scripted in Perl, PHP, awk, and Python. For school, I've done Prolog and Lisp(Lisp is fun). I mucked around in C# a little as well for an opensource project. My current favorite and what I use for home projects is Python. It's just kind of fun. It's fairly straight forward, but has a lot of power and versatility.

I have a couple of goals. I'd either like to focus on programming more as a profession than I currently do, or I'd like to become a professor and teach. I'd also like to continue my graduate studies. My interest lay in the realm of AI and specifically Natural Language Processing. Given the opportunity, I'd probably do some studies in Linguistics as well.

I have a couple of projects that I work on from time to time, but nothing serious.

I usually use eclipse when I'm working with Python, at work, I'll either use vi or jedit for quick changes/merge conflict resolution.
__________________
CEO of Evil Incorporated: "Subjugating humanity for a better tomorrow."


Last edited by Gryffon : 10-24-2012 at 08:38 AM.
Gryffon is online now   Reply With Quote
Old 10-24-2012, 11:54 AM   Top  -  End  -  #97
akma
Barbarian in the Playground
 
Join Date: Jul 2007
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by Miscast_Mage View Post
Unfortunately, while that may be what I'm asking for, it's completely beyond my level of comprehension at the moment; I'm barely understand any of it or how to utilize it.
It`s not easy to learn from it, but it`s a very good refrence tool if you already know about the things you want to use, just not remmember how exactly ("This class has a method to preform that thing I want to be done... but how is it called?").

Quote:
Originally Posted by Miscast_Mage View Post
Well, the thing is, I have found that there occasionally methods that I would want to re-use, that I know they would fit perfectly in this new situation. It could be quite a large method, or several methods, but I would know that what I expect to put in and get out is the exact same as the previous code. Not frequent enough to warrant making a package(though that is quite a good idea; that shall be a task for another day), but large enough that re-typing it out when I know what it does and that it works in the circumstance is just redundant work.
A package is just a bunch of classes bundled togather. One of the core packages comes with two classes and one enum (java.lang.math), it doesn`t have to be big to be part of a package.

Quote:
Originally Posted by Miscast_Mage View Post
This is more to prove the kind of questions we get, i.e. what will this snippet of code output? In this case, just "Hello.", because of pre and post incrementing, and the fact that using ++ or -- in the if parameter still increments/decrements for outside the if statement, regardless of whether or not the if statement proves true or not. Unless I'm mistaking something here, and am just ending up with egg on my face.
I have a confession: I don`t know the diffrence between using ++ before a number and after it.
I looked at it, I got confused, I decided to never use it. I could get the same results without dealing with this.

Quote:
Originally Posted by Miscast_Mage View Post
Netbeans. I have my projects named YYYY/MM/DD/NAME so I can at least search by date. Also, is it possible to add search tags(similar to those for images) to folders/files, for things like, say Has2DArrays, ExampleOnMethods, Assignment, etc? I know what you mean by searching by date created/size/name/etc, but I mean to search for programs that come back with the following tags, and such.
You can have a file with a realy long name, that in it`s title it would contain all this date, inside the folder.
Or another, single file that contains data on all the projects, but you would have to update it frequently.

Quote:
Originally Posted by Miscast_Mage View Post
Funny enough, I started learning using java, so I'm quite happy with that environment. The only issue I have is that I don't know how to access methods from another class in one class
Short answer:
import somePackage.*; (before the first { )
Then, write ClassName.MethodName(arguments)
And here is the long answer: http://docs.oracle.com/javase/tutori...age/index.html
akma is offline   Reply With Quote
Old 10-24-2012, 12:04 PM   Top  -  End  -  #98
Gryffon
Orc in the Playground
 
 
Join Date: Jan 2010
Location: 
Myrtle Beach, SC
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by akma View Post
I have a confession: I don`t know the diffrence between using ++ before a number and after it.
I looked at it, I got confused, I decided to never use it. I could get the same results without dealing with this.
++<num> increments it before it evaluates the value, <num>++ increments after.

Code:
val = 2
print ++val // 3
print val++ // 3
print val // 4
__________________
CEO of Evil Incorporated: "Subjugating humanity for a better tomorrow."


Last edited by Gryffon : 10-24-2012 at 12:05 PM.
Gryffon is online now   Reply With Quote
Old 10-24-2012, 04:57 PM   Top  -  End  -  #99
Balain
Orc in the Playground
 
OrcBarbarianGuy
 
Join Date: Feb 2010
Location: 
Calgary
Gender: Male
Default Re: ProgrammersitP

I need some help reading a text file in python3.

We are given a text file that looks like this
Quote:
ID , LAST, FIRST, Lecture, Tutorial, A1, A2, A3, A4, A5
######, NAME, NAME, L##, T##, 9.0,5.0,2.5,7.0,10
######,NAME, NAME, L##, T##,0.0, 1.0,10,0.0,3.5
with hundreds of entries

I have a function to read the file a line at a time and split each line into a list.

Quote:
def main_list(fname="grades.txt"):
import locale

fin = open(fname,mode='rt' buffering=1, newline='\n', encoding=locale.getpreferrencoding())

lst=[]

for line in fin:
lst.append(fin.readline().split(','))

fin.close()

return lst
Earlier attempts didn't have the buffering and newline character and encoding for the open call.

it appears to be creating the list I want, a list with each entry is a list of strings. However it seems to only be reading every other line of the file.
Balain is offline   Reply With Quote
Old 10-24-2012, 05:30 PM   Top  -  End  -  #100
PairO'Dice Lost
Firbolg in the Playground
 
 
Join Date: Dec 2008
Location: 
Malsheem, Nessus
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by Balain View Post
it appears to be creating the list I want, a list with each entry is a list of strings. However it seems to only be reading every other line of the file.
The problem here is the for loop syntax. When you say "for line in fin," you're iterating through fin's file and returning the lines one at a time as line...and then in the body of the loop you're telling it to readline() to get a line again, so you're throwing away every other line.

Just change the body of the loop to "lst.append(line.split(','))" and that should fix it.
__________________
Better to DM in Baator than play in Celestia
You can just call me Dice; that's how I roll.

Sig of Holding
Spoiler

Last edited by PairO'Dice Lost : 10-24-2012 at 05:30 PM.
PairO'Dice Lost is online now   Reply With Quote
Old 10-24-2012, 05:45 PM   Top  -  End  -  #101
Balain
Orc in the Playground
 
OrcBarbarianGuy
 
Join Date: Feb 2010
Location: 
Calgary
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by PairO'Dice Lost View Post
.....Just change the body of the loop to "lst.append(line.split(','))" and that should fix it.
I can't believe I didn't see that. Thank you very much!
Balain is offline   Reply With Quote
Old 10-26-2012, 09:12 PM   Top  -  End  -  #102
Neftren
Troll in the Playground
 
 
Join Date: Nov 2006
Default Re: ProgrammersitP

So I started on a re-code of my previous attempt of a blogging platform on Google App Engine. So far so good. I've managed to get adding/editing posts working properly, and I've integrated Twitter Bootstrap, the Bootstrap-WYSIHTML5 plugin, and the Google-Code-Prettify plugin. Everything is saved/retrieved dynamically from the datastore and rendered using the Jinja2 templating engine.

I think my next step is to add RSS/Atom support, but I'm finding it rather difficult to actually put that together. Does anyone here have experience with writing xml feeds?
__________________
Neftren is offline   Reply With Quote
Old 11-01-2012, 08:09 AM   Top  -  End  -  #103
Miscast_Mage
Barbarian in the Playground
 
 
Join Date: Dec 2010
Location: 
Ireland
Gender: Male
Default Re: ProgrammersitP

So, working in Java, and trying to figure out combining inner/outer classes with using an abstract class.

Say I've got an abstract class, Person, which extends to two classes, Teacher and Student.

I want each to have an inner class, Stats, but stats is slightly different for either of them(say their difference is Student has marks, Teacher has wages);

Would having Stats as an abstract class, and then having a Stats for Teacher and a Stats for Student work here? Would I have the abstract class Stats inside the abstract class Person as well?

Would it be a case of Teacher extends Person, then inside Teacher, TeachStats extends Stats?

Edit: I should probably clarify, when I say "Stats for Student", I mean "Stats for StudentStats extends Stats". Sorry if that caused any confusion.

Spoiler
__________________
If I'm talking about coding or programming, assume I'm talking about Java unless I say otherwise.
(◕ ‿‿ ◕)

Last edited by Miscast_Mage : 11-01-2012 at 08:38 AM.
Miscast_Mage is offline   Reply With Quote
Old 11-01-2012, 11:30 AM   Top  -  End  -  #104
akma
Barbarian in the Playground
 
Join Date: Jul 2007
Gender: Male
Default Re: ProgrammersitP

I don`t see why you want to use an inner class at all. You could create a regular class/interface named Stats, and just have a reference to it. In Student and Teacher it`s use is completly diffrent.

Anyways, you could have the Stats object contain an int value.
You could have a getMarks() method in Student, and getWage() method in Teacher, both returning that int value.

Is it completly neccesery for you to use inner classes for some reason? (if so, remmember not to make the inner class private)
akma is offline   Reply With Quote
Old 11-01-2012, 12:33 PM   Top  -  End  -  #105
Miscast_Mage
Barbarian in the Playground
 
 
Join Date: Dec 2010
Location: 
Ireland
Gender: Male
Default Re: ProgrammersitP

Well okay, if I don't have to have it as an inner class, how would I implement it? Would I just have Stats, StudentStats and TeacherStats as seperate classes, and just have in, say, Student:

Spoiler


Having the stats object just as it is, and having the getMarks/getWages be the only difference might work; I'll have to look into that. The only problem is I'm only going through this project so I can understand the logic of it and apply it to a larger project. I'll see about about getting precise details on what I want this project to do later; I've been studying the last two and half hours and my brain is starting to melt, so apologies if I'm mixing things up or being incomprehensible.
__________________
If I'm talking about coding or programming, assume I'm talking about Java unless I say otherwise.
(◕ ‿‿ ◕)
Miscast_Mage is offline   Reply With Quote
Old 11-01-2012, 02:26 PM   Top  -  End  -  #106
akma
Barbarian in the Playground
 
Join Date: Jul 2007
Gender: Male
Default Re: ProgrammersitP

I`m thinking more of:
public class Person {
protected Stats stats; // so it would be inherited
}

public class Student {
stats = new StudentStats();
}
or otherwise make sure it would be StudentStats.

The field that will be returned by getWage()/getMarks() doesn`t have to be inherited, but I do strongly suggest that all values would be returned from a method inherited from the class Person.
akma is offline   Reply With Quote
Old 11-01-2012, 04:07 PM   Top  -  End  -  #107
factotum
Titan in the Playground
 
BlackDragon
 
Join Date: Feb 2007
Location: 
Manchester, UK
Gender: Male
Default Re: ProgrammersitP

I'm not sure why you need a separate class for those stats at all. I thought the whole point of abstract classes were that you put the basic details of the type in there, and then got more detailed with the derived classes? So, Wages is a particular way in which the Teacher class extends the basic Person one. I might be thinking of this too much from a C++ viewpoint, mind you, since I'm not overly familiar with Java...
factotum is offline   Reply With Quote
Old 11-02-2012, 04:19 AM   Top  -  End  -  #108
Miscast_Mage
Barbarian in the Playground
 
 
Join Date: Dec 2010
Location: 
Ireland
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by factotum View Post
I'm not sure why you need a separate class for those stats at all. I thought the whole point of abstract classes were that you put the basic details of the type in there, and then got more detailed with the derived classes? So, Wages is a particular way in which the Teacher class extends the basic Person one. I might be thinking of this too much from a C++ viewpoint, mind you, since I'm not overly familiar with Java...
It probably isn't needed for this example, but I just want to see the logic of how they work and how to use them properly; I'm trying to learn this for another project where the Person class, if I didn't use an inner class, would have quite a lot of variables. I can imagine it would work the same, the problem would be that I would have is that it would be quite messy.

However, I think there's been a bit of a misunderstanding here, to my fault. I don't think inner classes are what I was planning to do, but I got muddled up with terminology there. My code probably makes more sense like this:
Spoiler


That is, of course, assuming that this even works; I'm starting to think I may be out of my depth here(Yet another project that'll have to go on the backburner untill I get the proper skills and experience for it. Sigh.), but I do still want to try and understand the logic of this.

Also, just as an aside; does anyone have any handy UML tutorials/notation pages that they'd recommend? Just googling for some now, but it's always nice to have one that's recommended.

Edit:

Quote:
Originally Posted by akma View Post
*snip*
Just out of curiousity, why would I use protected as opposed to private? Would using private cause issues with inheritance? I've only ever used private/public before, but then, I've never worked with classes like this before, so c'est la vie.
__________________
If I'm talking about coding or programming, assume I'm talking about Java unless I say otherwise.
(◕ ‿‿ ◕)

Last edited by Miscast_Mage : 11-02-2012 at 04:23 AM.
Miscast_Mage is offline   Reply With Quote
Old 11-02-2012, 04:36 AM   Top  -  End  -  #109
Skami Pilno
Bugbear in the Playground
 
 
Join Date: May 2005
Location: 
control+apple+alt+8
Default Re: ProgrammersitP

Quote:
Originally Posted by Miscast_Mage View Post

Just out of curiousity, why would I use protected as opposed to private? Would using private cause issues with inheritance? I've only ever used private/public before, but then, I've never worked with classes like this before, so c'est la vie.
Yes, private causes issues with inheritance. Check here for a decent explanation of the difference between private, protected, and public. A protected method gives subclasses an opportunity to take advantage of the method, or to allow its children to overwrite the method, which cannot be done with a private method. Public/private only coding is OK as long as you A)don't have a lot of inheritance, and B)follow good coding style and have get/set methods for your variables.
__________________
SUBMIT your searches
TO
GOOGLE.
Skami Pilno is offline   Reply With Quote
Old 11-02-2012, 05:13 AM   Top  -  End  -  #110
Miscast_Mage
Barbarian in the Playground
 
 
Join Date: Dec 2010
Location: 
Ireland
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by Skami Pilno View Post
Yes, private causes issues with inheritance. Check here for a decent explanation of the difference between private, protected, and public. A protected method gives subclasses an opportunity to take advantage of the method, or to allow its children to overwrite the method, which cannot be done with a private method. Public/private only coding is OK as long as you A)don't have a lot of inheritance, and B)follow good coding style and have get/set methods for your variables.
Ah, I see now. I would have the variables marked as private and use getters/setters to access them. That can get quite fiddly though; having the variables as protected seems like it'll make things much easier in that regards, thanks for that.
__________________
If I'm talking about coding or programming, assume I'm talking about Java unless I say otherwise.
(◕ ‿‿ ◕)
Miscast_Mage is offline   Reply With Quote
Old 11-02-2012, 05:34 AM   Top  -  End  -  #111
akma
Barbarian in the Playground
 
Join Date: Jul 2007
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by Miscast_Mage View Post
Just out of curiousity, why would I use protected as opposed to private? Would using private cause issues with inheritance? I've only ever used private/public before, but then, I've never worked with classes like this before, so c'est la vie.
private variables, private methods and private inner classes cannot be accsessed by subclasses.
You could have a protected/public method named get, which returns a Stats object, which could then be used to get the wanted data.

My philosephy on accsess modifiers
(Note: This is the opposite of the approach encouraged by the tutorials I have read)
Generally speaking, I believe variables should be as public as possible. If the variable can contain any value, limiting the access to it only make you write unnessecery get and set methods. If you have a reason to limit the access to a variable (if it must not contain certain values, for exemple), then limit it as neccessery (probably making it private).

With methods, I write all of them as public or private. The private ones are utility methods used by the public methods, and are not usefull outside of the class.
akma is offline   Reply With Quote
Old 11-02-2012, 06:32 AM   Top  -  End  -  #112
Miscast_Mage
Barbarian in the Playground
 
 
Join Date: Dec 2010
Location: 
Ireland
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by akma View Post
private variables, private methods and private inner classes cannot be accsessed by subclasses.
You could have a protected/public method named get, which returns a Stats object, which could then be used to get the wanted data.
Yeah, that's what I was doing before; using getters/setters to access private variables and methods(haven't really gotten into private inner methods yet, which I've realised aren't even what I want to do here.). Having things as protected though just seems like a lot less hassle and headaches than having to use getters to access them.

Quote:
Originally Posted by akma View Post
My philosephy on accsess modifiers
(Note: This is the opposite of the approach encouraged by the tutorials I have read)
Generally speaking, I believe variables should be as public as possible. If the variable can contain any value, limiting the access to it only make you write unnessecery get and set methods. If you have a reason to limit the access to a variable (if it must not contain certain values, for exemple), then limit it as neccessery (probably making it private).

With methods, I write all of them as public or private. The private ones are utility methods used by the public methods, and are not usefull outside of the class.
The only problem with having access modifiers as public as possible, is that does it not get inefficient the larger the code gets due to local/global scope? I got the impression that having a variable on a scope larger that it has to be inefficient and bad practice; does it actually cost more processing power to run that code, or is it just a case of different practices?

Also, I've encountered this problem three times in the last three days and I keep forgetting it:

Spoiler
__________________
If I'm talking about coding or programming, assume I'm talking about Java unless I say otherwise.
(◕ ‿‿ ◕)
Miscast_Mage is offline   Reply With Quote
Old 11-02-2012, 07:44 AM   Top  -  End  -  #113
akma
Barbarian in the Playground
 
Join Date: Jul 2007
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by Miscast_Mage View Post
The only problem with having access modifiers as public as possible, is that does it not get inefficient the larger the code gets due to local/global scope? I got the impression that having a variable on a scope larger that it has to be inefficient and bad practice; does it actually cost more processing power to run that code, or is it just a case of different practices?
I have never seen that claim.
I don`t think this is true. The variable would exist anyways, even if you couldn`t access it - int would "cost" 32 bits even if you could access it anywhere.
I also think you are mixing concepts, and static variables are like global variables in other leanguages, and instance variables are like local variables in other leanguages.
Maybe I`m wrong.

The arguments I remmember to make things as private as possible is to make it less clear how operations are preformed and to make it less error prone by wrong values being inserted (which is not always relevent).

I guess it`s more of a matter of personal taste - the thing that matters the most is if the code you write does the things it`s supposed to do.
akma is offline   Reply With Quote
Old 11-02-2012, 10:57 AM   Top  -  End  -  #114
factotum
Titan in the Playground
 
BlackDragon
 
Join Date: Feb 2007
Location: 
Manchester, UK
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by akma View Post
I guess it`s more of a matter of personal taste - the thing that matters the most is if the code you write does the things it`s supposed to do.
Readability and maintainability are at least as important as that, IMHO. It would be perfectly possible to write code that does what it's supposed to, but is so tangled and labyrinthine that *you* can't even remember what it does when you look at it a few months later, much less someone who's been hired to maintain the program after you've left!
factotum is offline   Reply With Quote
Old 11-02-2012, 12:39 PM   Top  -  End  -  #115
Wookieetank
Barbarian in the Playground
 
 
Join Date: Mar 2010
Location: 
Kashyyyk
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by factotum View Post
Readability and maintainability are at least as important as that, IMHO. It would be perfectly possible to write code that does what it's supposed to, but is so tangled and labyrinthine that *you* can't even remember what it does when you look at it a few months later, much less someone who's been hired to maintain the program after you've left!
Unless of course you're participating in: http://en.wikipedia.org/wiki/Obfuscated_C
Wookieetank is online now   Reply With Quote
Old 11-02-2012, 04:28 PM   Top  -  End  -  #116
Teddy
Troll in the Playground
 
 
Join Date: Mar 2009
Location: 
Sweden
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by Wookieetank View Post
Unless of course you're participating in: http://en.wikipedia.org/wiki/Obfuscated_C
Heh, I actually thought about that contest a week or so ago, but couldn't come up with a good way of posting it without it seem all too much out of context. It's a neat concept, isn't?

Also, on the topic of writing good code, as one of our lecturers use to say: "It's ten times as hard to debug code than it is to write it, so if you write the most complicated code you could ever make, it consequently will be impossible for you to debug".
__________________
Engineer Teddy by me. We're refitting this steam locomotive in the spirit of Steampunk, but we need your help designing it: Enter_the_design_competition_today!
(And yes, my avatar is according to scale.)

Banner by Vrythas:
Spoiler
Teddy is online now   Reply With Quote
Old 11-05-2012, 10:08 AM   Top  -  End  -  #117
Miscast_Mage
Barbarian in the Playground
 
 
Join Date: Dec 2010
Location: 
Ireland
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by akma View Post
I have never seen that claim.
I don`t think this is true. The variable would exist anyways, even if you couldn`t access it - int would "cost" 32 bits even if you could access it anywhere.
I also think you are mixing concepts, and static variables are like global variables in other leanguages, and instance variables are like local variables in other leanguages.
Maybe I`m wrong.

The arguments I remmember to make things as private as possible is to make it less clear how operations are preformed and to make it less error prone by wrong values being inserted (which is not always relevent).

I guess it`s more of a matter of personal taste - the thing that matters the most is if the code you write does the things it`s supposed to do.
Ah, I must have been mistaken then; I thought I remembered my lecturer saying that it was inefficient before, but I must have been mis-remembering. My apologies.

Quote:
Originally Posted by factotum View Post
Readability and maintainability are at least as important as that, IMHO. It would be perfectly possible to write code that does what it's supposed to, but is so tangled and labyrinthine that *you* can't even remember what it does when you look at it a few months later, much less someone who's been hired to maintain the program after you've left!
Funny thing, a friend of mine in college created a simple OS, and when he went back to it a few months later, he went "I can't remember what any of this does. " "Well that's because you don't have any comments.". So it just goes to show, comments are definitely something you want to keep in mind.

Also, I think I've got the diagram I had above sorted out now; hopefully this makes sense as a graphical representation:
Spoiler
__________________
If I'm talking about coding or programming, assume I'm talking about Java unless I say otherwise.
(◕ ‿‿ ◕)
Miscast_Mage is offline   Reply With Quote
Old 11-05-2012, 11:31 AM   Top  -  End  -  #118
akma
Barbarian in the Playground
 
Join Date: Jul 2007
Gender: Male
Default Re: ProgrammersitP

Quote:
Originally Posted by factotum View Post
Readability and maintainability are at least as important as that, IMHO.
I personally disaggree, but can`t seem to be able to detail any further (I`m usually better at debating).
But don`t worry, I don`t neglect this things while proggramming.

Quote:
Originally Posted by Miscast_Mage View Post
So it just goes to show, comments are definitely something you want to keep in mind.
Generally my comments tend to be in the style of "Not debugged" and lists of methods to do (which I tend to neglect after I do the hardest, most intresting and most important methods of a class).
akma is offline   Reply With Quote
Old 11-05-2012, 12:52 PM   Top  -  End  -  #119
Balain
Orc in the Playground
 
OrcBarbarianGuy
 
Join Date: Feb 2010
Location: 
Calgary
Gender: Male
Default Re: ProgrammersitP

Reading on posts about comments, in my opinion style(comments,readable, etc) is very important. This should be taken with a grain of salt cause most of my programming is personal, although I did write a little code here and there at work to make some of my jobs easier when I was working.

When I was younger the order was more than likely 1. Program works, 2. Program is efficient, 3. style

Then I started working and the order was more like. 1.program works, 2. program is done on time, 3. program is efficient, 4. style

as I worked more in oil and gas industry and now that I'm back in school it's more like 1. program is finished on time, 2. program works and style, 4. program is efficient. It seems to work for me cause I get 100% on my assignments....Except one I got 98%
Balain is offline   Reply With Quote
Old 11-05-2012, 01:57 PM   Top  -  End  -  #120
PairO'Dice Lost
Firbolg in the Playground
 
 
Join Date: Dec 2008
Location: 
Malsheem, Nessus
Gender: Male
Default Re: ProgrammersitP

If you ever intend to work in the software industry, get in the habit of commenting well, commenting thoroughly, and commenting often.

I'm currently working on a project involving an unholy synthesis of Java, C++, and third party C libraries comprised of over 200,000 lines of code all written by one person, who probably shouldn't have been allowed near our codebase in the first place. The code is so unintuitive and over-complicated that he was the only one who understood it all, he retired two weeks ago, and he didn't leave a single comment in any of the files. And now the new guy (yours truly) gets to try to rewrite that cluster**** to make it usable when we have a new release in less than a month.

Even if you're just coding for fun, you will run into a situation where you see code without comments and hate the person who wrote the code, whether it's someone who wrote libraries or code samples on the internet or yourself-of-two-months-ago who thought yourself-right-now wouldn't need comments to remember how that one kludge worked. Comment, comment, comment.
__________________
Better to DM in Baator than play in Celestia
You can just call me Dice; that's how I roll.

Sig of Holding
Spoiler

Last edited by PairO'Dice Lost : 11-05-2012 at 01:58 PM.
PairO'Dice Lost is online now   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -5. The time now is 02:02 PM.



Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Usage of this site, including but not limited to making or editing a post or private message or the creation of an account, constitutes acceptance of the Forum Rules.