Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

skims thread
So, anyone here skilled in python/C#/C++/x86 ASM and wanting to help with AE and MvC3 modding tools? Cosmetic and Non-cosmetic?
Could use a few more eyes and hands :stuck_out_tongue:

AE I can understand, with the PC release, but marvel modding tools?

Wow, the old semicolon at the end of a loop. I canā€™t tell you how many times Iā€™ve done that in java. Sometimes Iā€™ll miss it and then come back and catch it, that tends to give me a good laugh.

Currently learning recursion through java. Second quarter of college programming classes.

Syntax errors really arenā€™t what gives me trouble, yet. I usually get my project//lab//whatever working pretty quickly, but I when I look over my code I always feel that there is a better way to do what Iā€™m doing in far less lines of code.

There usually is a way to do it with less lines of code, but it just reduces readability sometimes. Itā€™s a hard trade off, do you want it to process faster (and even this is not necessarily true, since the compiler optimizes stuff anyway) or do you want it to be readable.

Like for instance, which of these makes more sense at a glance?



bool isEven(int num)
{
  if((num % 2) == 0)
    return true;
  else
    return false;
}


or this



bool isEven(int num)
{
   return ((num % 2) == 0);
}


The first just clicks, the second you have to pause to think about, even though it produces the same result. Itā€™s 1 line versus 4, but is that trade off worth it? You wonā€™t be able to properly answer this until youā€™re dumped into somebody elses million line code project, trying to figure out what the hell people were thinking

Some people LOVE cutting down on vertical space for reasons I will never truly understand.

I think you guys took him too literally.

I think he meant, ā€˜how can I make the machine do it more efficiently?ā€™

Once you get analysis of algorithms, hardware knowledge, and specific programming language knowledge, youā€™re going to be close enough, especially given the time constraints of your job or class work for most things.

The problem is always figuring out how to efficiently implement what you need to automate given the time constraints.

And furthermore, explaining it to another person who may or may not be an engineer.

I want to learn a language, but I donā€™t have anything in mind. I donā€™t have any projects or goals in particular. I canā€™t say that I want to particularly make anything. I just want to learn a language that I can apply to a variety of situations.

My only criteria is that it isnā€™t an ugly language when written. Iā€™d prefer a language that isnā€™t compiled, but if the best option is, Iā€™ll take it.

For some reason, Iā€™m thinking about trying my hand at Perl.

do C++ everything is super easy after that!

Might be my fault in not being clear enough. Itā€™s not so much about length as it is finding a ā€œbetterā€ way to do it. I mean my programs all work, I guess thatā€™s all that matters for now.

Iā€™ll give an example. This project is due Monday. Its goal is to generate 3 random numbers(between 1-100), order them, and run it 100 times.

my code

Spoiler

public static void displaySortedNumbers(int numOne, int numTwo,  int numThree)
    {
        int first = 0;
        int second = 0; //I end up printing these variables out as the sorted numbers in this method
        int third = 0;
        if(numOne > numTwo && numOne > numThree) //Check if numOne is highest
        {
            first = numOne;
            if(numTwo > numThree) // Sets 2nd and 3rd highest numbers
            {
                third = numThree;
                second = numTwo;
            }
            else
            {
                second = numThree;
                third = numTwo;
            }

        }
        else if(numTwo > numThree && numTwo > numOne) //numTwo is highest
        {
            first = numTwo;
            if(numOne > numThree) // Finds 2nd and 3rd highest numbers
            {
                third = numThree;
                second = numOne;
            }
            else
            {
                second = numThree;
                third = numOne;
            }

        }
        else if(numThree > numTwo && numThree > numOne) //numThree
        {
            first = numThree;
            if(numTwo > numOne)  //Finds 2nd and 3rd highest numbers
            {
                third = numOne;
                second = numTwo;
            }
            else
            {
                second = numOne;
                third = numTwo;
            }

        }
        System.out.println("Sorted they are: " + first + "  " + second + "  " + third);
    }

    public static void main(String[] args)
    {

        //Loop to call on displaySortedNumbers method 100 times
        for(int run = 0; run < 100; run++)
        {
            int numOne = (int)((Math.random() * 100) +1 );
            int numTwo = (int)((Math.random() * 100) + 1); // Makes random number between 1 - 100
            int numThree = (int)((Math.random() * 100) + 1);

            System.out.println("The three random numers are: " + numOne + "  " + numTwo + "  " + numThree);
            displaySortedNumbers(numOne, numTwo, numThree); //Call method to print sorted numbers.
            System.out.println(run + "\r");  //Keeping count to assure 100 runs before exiting program.  Plan on deleting before turning in
        }

    }

}


The thing that I think I could change is the three different if statements. Any input would be appreciated

you could do a linked list and then insertion sort the random numbers into it. That would cut the 3 if statements each with two if statements in them to a single loop. Unless you arenā€™t allowed to use those(of course you COULD write your own linked list!). Or you could just throw them in an array and sort afterwards.

Cool thread. :tup:

After years of experience, youā€™ll be able to figure out better ways of doing things.

I would like to know if there are any good resources for learning HTML5 yet? I havenā€™t done any web programming for a long time, and HTML5 is going to be big as far as gaming is concerned (Iā€™m a student video game developer). In the meantime, I have a book for HTML4, so I guess I could re-read that as a refresher.

Doing something like the linked list mentioned above is a good tactic definitely. It really would be the proper way to do it. I would even say just doing an array and a bubble sort, merge sort, quick sort, etc are all better ways to actually do sorts. But since youā€™re only dealing with 3 numbers, technically itā€™s more inefficient to just do it the ā€œproperā€ way versus the quick and dirty way. 2 if checks and you know what the result is, versus 3 checks for a bubble sort.

Thanks for the input guys. Iā€™m just gonna hand in project as is (we havenā€™t covered linked lists, arrays ect., I need to read ahead lol.) Iā€™ll keep my ears an eyes open for what you guys mentioned though, thanks again.

Its mostly for fun in the first place.
Some of us can run modded versions of games on consoles. In fact, I just added 360 support to all of my AE tools recently

This is one of the problems with early CS projects, at least one of the issues Iā€™ve had with it. Generating three numbers and then sorting them is not a particularly useful thing, I mean youā€™d likely need a lot more than just three. The fact that using a couple if statements to sort is faster is a little silly to me, I mean yeah sure that is the reality of this particular problem but it seems very misleading for program design down the road.

It would just would make more sense (to me) to have the incoming param be number of random integers to be sorted and a seed for the size of the randomness. Then import the Random class in and have a sort method. It can just be a frustrating way to learn if you know what I mean.

You have to learn to walk before you can run, so you have to have a basic handle on if statements before you move onto more complicated stuff. It doesnā€™t matter if youā€™re not writing anything useful ā€“ just like when youā€™re learning to read, youā€™re not reading anything important ā€“ what it does is build up the foundation so that you can learn the really important stuff later on.

It was always described to me as tools in a toolbox; every technique we learn in our classes is another tool for our toolbox. If all you have is a hammer, every problem you solve is going to get fixed with that hammer. But later on you might acquire a screwdriver, and suddenly certain problems become solvable with that. Early projects teach you these fundamental tools - in this case, the if/else logic - which is important. Just because youā€™re not jumping into variable size arrays, doing a quick sort with only 2 bytes of extra memory to play with doesnā€™t mean early CS projects are pointless no more than telling a toddler reading ā€œElmos Dayā€ is pointless when compared to ā€œWar and Peaceā€

Do any of you guys have any experience writing for the android in eclipse? Iā€™ve been working on a project and when I run the debugger (which currently seems really convoluted to me right now) It says Iā€™m missing lots of source files. Weird thing is, I tried those writing those intro programs before I started on this assignment. My professor honestly runs this class more like a lecture than a lab, so right now google is really the best teacher atm. The assignment basically we are making an app on an idea we submitted and going through all the development steps to get it done and hopefully make a beta by the time the semester ends. Though my idea might come to bite me in the ass atm.

I have experience with eclipse, just not necessarily with Android development. Been too lazy to get started : (

Itā€™s probably just some missing libraries on your project related to android