New OOTS products from CafePress
New OOTS t-shirts, ornaments, mugs, bags, and more
Page 4 of 12 FirstFirst 123456789101112 LastLast
Results 91 to 120 of 356

Thread: ProgrammersitP

  1. - Top - End - #91
    Titan 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.
    Last edited by Teddy; 2012-10-23 at 03:49 PM.
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  2. - Top - End - #92
    Barbarian in the Playground
     
    Alaris's Avatar

    Join Date
    Oct 2008

    Default Re: ProgrammersitP

    [*]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?

    [*]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.


    [*]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.

    [*]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.

    [*]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.

    [*]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.
    3DS Friend Code: 1907-9395-1731
    Pokemon X Info: Modern Pattern Vivillon & Flying-Type Friend Safari (w/ Farfetch'd & Swanna)

    Avatar: Thanks to asdflove for my avatar. ^_^

  3. - Top - End - #93
    Ogre 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.

    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...

    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; 2012-10-23 at 01:52 PM.

  4. - Top - End - #94
    Titan 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...
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  5. - Top - End - #95
    Barbarian in the Playground
    Join Date
    Dec 2010
    Location
    Ireland
    Gender
    Male

    Default Re: ProgrammersitP

    Spoiler'd for length.

    Spoiler
    Show
    Okay, I wasn't mixing up two things at once, I was mixing up three.

    • Having a database of my own useful methods/classes/etc for my personal use.
    • Having something to show other people(that have started the course we're doing from a complete beginners viewpoint and thus have difficulty understanding a lot of the logic and syntax, whereas I have a year of experience in computer applications) in my course if they're having a problem.
    • A collection of slippery/tricky little aspects of coding in java that would be on the OCJA exam, such as what happens when you use ++ in an if statement, or a if(boolean = true)(this is assigning) as opposed to if(boolean == true)(this is checking), or a comment with \\(wrong) as opposed to //(right)


    Quote Originally Posted by akma View Post
    Again, javadoc.
    A class written with javadoc documentation: http://docs.oracle.com/javase/7/docs...g/Package.html
    A package written with javadoc documentation: http://docs.oracle.com/javase/7/docs...e-summary.html
    The entire API supplied with java, with much javadoc documentation (bookmark this one): http://docs.oracle.com/javase/7/docs/api/
    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.


    Quote Originally Posted by Neftren View Post
    What I'm saying is that you shouldn't copy/paste at all. If it's a code snippet, it's short enough to retype, or regex/text-expand it. Typing it out will help you avoid mistakes (enter the logical fallacy of code found on the internet). If it's some sort of utility method (e.g. templated matrix multiply) that you use on a frequent basis, it should be documented and then compiled into a package.

    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.

    Quote Originally Posted by Neftren View Post
    Code that you use personally and code that you show other people shouldn't be any different. If you maintain a rigorous and neat programming style, your code should be easily understandable to anyone reading it. At that point, it's just a matter of "oh, here's my file, look at it and understand!"
    I clarified this up at the top a bit; this isn't code for people at my skill level or above, but rather to help explain the code, how it works, why it does what it does and such for other people learning java for the first time in the course who might be struggling to grasp it.

    I'd like to think of my code as quite neat and readable, and I already threaten apocalypse via armoured attack-weasels on people who don't indent/comment/do general neaty-ness things.

    Quote Originally Posted by Neftren View Post
    As for some comments on your code... I know a lot of instructors provide cheat sheets on exams. I don't know if yours does the same though. Anyways ...
    Well, our exams so far are snippets of code that are designed to be as sneaky, evil, and underhanded as possible, i.e. no-where near what good practical coding should ever look like.

    Quote Originally Posted by Neftren View Post
    You should probably avoid performing mathematical operations within conditional statements. Your first code sample will fail if the given number isn't 5. Granted you probably already knew that part.
    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.

    Quote Originally Posted by Neftren View Post
    I'm surprised you (or other people you're helping) found int []y[]; tricky. Well, maybe it's the format you wrote it in. This is more of a pet peeve of mine more than anything else (going back to the Star (Pointer) Wars. It makes much more sense to rewrite that fragment as int[] y[]; (note the spacing). That way, you keep the data type with the container. An integer[array] (of) y[array_size]. 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).
    It's more that I (and as far as I know, everyone else in the course) have always used int x[][];, and we would be asked questions like "Will int []x[]; compile?" in exams, when we've never seen an array intialised like that before.

    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?
    In of itself, it's not that useful, apart from the fact that I worked out the logic of the code myself(and I am damn proud of that! Stupid thing wrecked my brain for a while.). However, I can show this to other people to explain how sorting an array works.

    Another benefit is that I can alter this. For example, say I have a Card object that has a int value(is it a 5, 6, Ace, King, etc). I can copy this code, and change it to take in an Array of Cards, and use getValue to compare the values. In fairness, I could also have a method to take the values from an Array of Cards, and write that to an Array of ints called values, but either way is valid from what I can see, and having an extra alternative is never a a bad thing.

    Quote Originally Posted by Neftren View Post
    A tagging system in what? All modern operating systems can sort by file name and date. Or are you using some IDE?
    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.

    Quote Originally Posted by Neftren View Post
    Compiling via command line is pretty easy. You'll probably learn to use the GNU Compiler (gcc/g++). In Terminal (or shell of choice), you'll enter something along the lines of...
    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, and I used a class that handled all input from the user that a lecturer from college gave us. I'm happy enough using netbeans for the moment though, and our next teacher is going to go through compiling via command line further down the line, so I'll be happy to deal with that issue then.

  6. - Top - End - #96
    Orc in the Playground
     
    Gryffon's Avatar

    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.
    Last edited by Gryffon; 2012-10-24 at 08:38 AM.
    CEO of Evil Incorporated: "Subjugating humanity for a better tomorrow."


  7. - Top - End - #97
    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
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  8. - Top - End - #98
    Orc in the Playground
     
    Gryffon's Avatar

    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
    Last edited by Gryffon; 2012-10-24 at 12:05 PM.
    CEO of Evil Incorporated: "Subjugating humanity for a better tomorrow."


  9. - Top - End - #99
    Barbarian in the Playground
     
    BarbarianGuy

    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
    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.

    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.

  10. - Top - End - #100
    Titan in the Playground
     
    PairO'Dice Lost's Avatar

    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.
    Last edited by PairO'Dice Lost; 2012-10-24 at 05:30 PM.
    Better to DM in Baator than play in Celestia
    You can just call me Dice; that's how I roll.


    Spoiler: Sig of Holding
    Show

    Quote Originally Posted by abadguy View Post
    Darn you PoDL for making me care about a bunch of NPC Commoners!
    Quote Originally Posted by Chambers View Post
    I'm pretty sure turning Waterdeep into a sheet of glass wasn't the best win condition for that fight. We lived though!
    Quote Originally Posted by MaxiDuRaritry View Post
    Quote Originally Posted by PairO'DiceLost View Post
    <Snip>
    Where are my Like, Love, and Want to Have Your Manchildren (Totally Homo) buttons for this post?
    Won a cookie for this, won everything for this

  11. - Top - End - #101
    Barbarian in the Playground
     
    BarbarianGuy

    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!

  12. - Top - End - #102
    Ogre 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?

  13. - Top - End - #103
    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
    Show


    Note that variables could mean methods as well; I was just lazy drawing up this diagram.
    Last edited by Miscast_Mage; 2012-11-01 at 08:38 AM.

  14. - Top - End - #104
    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)
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  15. - Top - End - #105
    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
    Show

    Code:
    public class Student extends Person
    {
                private String whatever;
                private StudentStats studentStats;
    }
    where StudentStats is a completely seperate class? This is what I was thinking originally, but then figured that if I want to add a few more classes(which is what I'm planning on doing; this is just testing for another project that have a lot more classes extending Person), it might be more organised if I had the Stats(which also changes depending on what class it's going with) inside the Student/Teacher classes.


    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.

  16. - Top - End - #106
    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.
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  17. - Top - End - #107
    Colossus 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...

  18. - Top - End - #108
    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
    Show

    Code:
    abstract public Person()
    {
    	private String whateverString;
    	private int whateverInt;
    	private Stats stats;
    
    	abstract void greetings();
    }
    Code:
    abstract public Stats()
    {
    	private String something;
    	private String somethingElse;
    }
    Code:
    public TeachStats extends Stats
    {
    	private String somethingForTeacher;
    }
    Code:
    public StudentStats extends Stats
    {
    	private int somethingForStudent;
    }
    Code:
    public Student extends Person
    {
    	private StudentStats studentStats;
    
    	public void greetings()
    	{
    		System.out.println("Hi, I'm a student.");
    	}
    }
    Code:
    public Teacher extends Person
    {
    	private TeachStats teachStats;
    
    	public void greetings()
    	{
    		System.out.println("Hello, I am a teacher.");
    	}
    
    }


    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.
    Last edited by Miscast_Mage; 2012-11-02 at 04:23 AM.

  19. - Top - End - #109
    Bugbear in the Playground
     
    TSGames's Avatar

    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.
    TopSecret's First Ever Two Page Tabletop Contest
    If you have any questions, want to talk about the contest entries, or you just want to hang out with cool people, visit our forums.

  20. - Top - End - #110
    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.

  21. - Top - End - #111
    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.
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  22. - Top - End - #112
    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
    Show

    Code:
    public Person()
    {
    	protected Stats stat;
    	protected String whatever;
    
    	public Person(String whatever)
           {
    	          this.whatever = whatever;
    	          stat.setStats(); //a method in the Stats to class to assign data to the variables
           }
    }
    And I was getting a nullPointerException. What I need to do was intiliaze the stat object first:

    Code:
    public Person()
    {
    	protected Stats stat = new Stats();
    	protected String whatever;
    
    	public Person(String whatever)
            {
    	           this.whatever = whatever;
    	           stat.setStats(); //a method in the Stats to class to assign data to the variables
            }
    }
    I feel silly now.

  23. - Top - End - #113
    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.
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  24. - Top - End - #114
    Colossus 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!

  25. - Top - End - #115
    Ogre in the Playground
    Join Date
    Mar 2010
    Location
    Gridania, Eorzea
    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

  26. - Top - End - #116
    Titan 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".
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  27. - Top - End - #117
    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
    Show



  28. - Top - End - #118
    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).
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  29. - Top - End - #119
    Barbarian in the Playground
     
    BarbarianGuy

    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%

  30. - Top - End - #120
    Titan in the Playground
     
    PairO'Dice Lost's Avatar

    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.
    Last edited by PairO'Dice Lost; 2012-11-05 at 01:58 PM.
    Better to DM in Baator than play in Celestia
    You can just call me Dice; that's how I roll.


    Spoiler: Sig of Holding
    Show

    Quote Originally Posted by abadguy View Post
    Darn you PoDL for making me care about a bunch of NPC Commoners!
    Quote Originally Posted by Chambers View Post
    I'm pretty sure turning Waterdeep into a sheet of glass wasn't the best win condition for that fight. We lived though!
    Quote Originally Posted by MaxiDuRaritry View Post
    Quote Originally Posted by PairO'DiceLost View Post
    <Snip>
    Where are my Like, Love, and Want to Have Your Manchildren (Totally Homo) buttons for this post?
    Won a cookie for this, won everything for this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •