Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

09-03-2015 , 04:07 PM
I'm just going to say that most professors i've encountered, spend very little time in an IDE or using the features that an IDE can give. I think that I know the reason why but that isn't really necessary to explain.

There are many elite levels that a person unlocks, in all aspects of programming when they spend considerate time using it or trying to use it.

The biggest benefit an IDE gives me, has to be the keybinding shortcuts to do 'Anything' without having to use the mouse at all.

Navigating through the multiple tabs of files i have open, without using the mouse or clicking is killer time save. Navigating to and back from methods or classes is huge boost to my mental abilities; keeping track of code is easy, when it is all instant by a keypress or two. Creating new file in specific directory or package, being able to setup IDE with live reload where it refreshes my browser on code change wow. Using the ability to edit server code and not have to relaunch the server is godlike.

Refactoring to make code more elegant with better naming convention is super.
Shortcut for auto generated code, such as classes, methods, enums + more.

Instant methods lookup with shortcut and dash doc integration.

Built in database management tool. Terminal built in and debug console too.
Syntax highlighting for imported dependencies beautiful and spell checker with ability to add your own words.

Different launch settings saved for creating individual tests to run on startup that are saved right there. Millions of cool plugins for doing cool stuff like having someone else be able to see what you're doing or changing the IDE.

The list is endless, lots of people are missing out on the benefits of the above plus more that I still am learning about as well.
People are cheating themselves by refusing to switch to an IDE, when they have a powerful laptop or desktop to develop on.
They should treat their time more valuable than pissing it away.

I believe that some people really think that they are not capable of the memorization involved to do the above at an instant speed. You are completely wrong for thinking that way and are limiting yourself below someone else that is just like you but is doing all of the above plus more.
All it takes is taking one thing from the above and practicing it all day for maybe a month or less to be instant; doing it without thinking about it.

There are those rare people that are beyond the need of an IDE because their memory is astronomical and they just benefit from simple navigation that is included in vim or emacs but they are missing out on stuff by ignorance.

The above is basic stuff to most people in my opinion but not to the new programmers.

Last edited by iosys; 09-03-2015 at 04:13 PM.
Programming homework and newbie help thread Quote
09-03-2015 , 04:24 PM
Quote:
Originally Posted by dummy101
Thanks for the link gaming_mouse, I'll look into implementing bcrypt.

I would still like to know why my 32-byte hash returns as a different 11-byte hash after being stored and retrieved from a database.

Any ideas?
i can't tell from that info. you might try base64 encoding it before storing it, though.

also, first rule of crypto is never roll your own crypto. so don't implement bcrypt. find a standard library in your language of choice and use that.
Programming homework and newbie help thread Quote
09-04-2015 , 12:57 AM
Quote:
Originally Posted by dummy101
Hey guys, Im having a problem storing a hashed password on a mySQL database.

Im using SHA-256 and storing a 32-byte hash in a column of type CHAR(64) but when I retrieving the same hash using the following code, it returns a different 11-byte hash.

ResultSet rs;
rs = st.executeQuery("SELECT * FROM customer_accounts WHERE nickname='" + nickname + "'");
rs.next();
byte[] h = rs.getBytes("passhash");

out.println("HashAfter: " + Arrays.toString(h) + " SaltAfter: " + Arrays.toString(s));

Any ideas what I could be doing wrong here? Thanks
1 problem was I was storing the hash as binary in a CHAR column. Now it returns the hash 32 bytes long but it is still different.

HashBefore: [86, 14, 122, 44, 61, -48, -56, -52, -55, 100, -41, -57, -76, -43, -36, 58, -104, -29, -119, -80, 122, -82, 106, -47, -11, 25, -26, 108, 28, 4, 68, 125]

HashAfter: [91, 66, 64, 53, 101, 97, 49, 53, 54, 97, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Programming homework and newbie help thread Quote
09-04-2015 , 05:57 AM
Quote:
Originally Posted by dummy101
1 problem was I was storing the hash as binary in a CHAR column. Now it returns the hash 32 bytes long but it is still different.

HashBefore: [86, 14, 122, 44, 61, -48, -56, -52, -55, 100, -41, -57, -76, -43, -36, 58, -104, -29, -119, -80, 122, -82, 106, -47, -11, 25, -26, 108, 28, 4, 68, 125]

HashAfter: [91, 66, 64, 53, 101, 97, 49, 53, 54, 97, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Just a guess on my part but a char is a signed 8 bit value. So all bits being set is -1 and not 255. For an unsigned char all bits set is 255.
Programming homework and newbie help thread Quote
09-04-2015 , 10:48 AM
iosys,
not sure if your comment was directed at me but I never said IDE's weren't useful. Personally I use IntelliJ at work for Java and wouldn't want to be without it's advanced features, although I have barely scratched the surface.

I'm just saying there's more than one way to skin a cat and teaching beginners the bare-bones basics first might be helpful for their development and clarify their understanding. When someone has no idea how software is developed it can be a revelation to realize that all you need is notepad and a small console program to transform your thoughts into something that runs on a computer and does actual useful stuff. I might be wrong though.

Last edited by Wolfram; 09-04-2015 at 11:06 AM. Reason: I'm not recommending notepad as a code editor :)
Programming homework and newbie help thread Quote
09-05-2015 , 06:53 PM
A thought occurred regarding some algorithm sites' obsession with string manipulation.

If you're writing server-side Java are calls to your main method passed as String arg arrays always?

Could that be why there's such a focus on string manipulation in algorithms?

Just trying to make a connection between the real world and what's taught on the web.
Programming homework and newbie help thread Quote
09-06-2015 , 02:59 AM
Quote:
Originally Posted by Wolfram
teaching beginners the bare-bones basics first might be helpful for their development and clarify their understanding. When someone has no idea how software is developed it can be a revelation to realize that all you need is notepad and a small console program to transform your thoughts into something that runs on a computer and does actual useful stuff.
100% agree
Programming homework and newbie help thread Quote
09-06-2015 , 11:10 AM
I'm taking an MIT OCW course and I failed to read the problem set thoroughly:

Quote:
To keep things from getting too complicated, we will add the restriction that a shift can begin only at the start of a word.
The assignment was to create a program that uses brute force+dictionary to decrypt keys of the form:

[(a,b), (c,d)...]

The second letter in each ordered pair is a Caesar shift and the first letter is the start position for the application of the key. I spent a few hours just trying to make the algorithm work for arbitrary start locations before realizing that I had made the problem much harder than the spec. If I wasn't such a newb, I'm sure I could implement the harder spec, but I keep breaking my algorithm when I try to add back-tracking in conjunction with recursion.
Programming homework and newbie help thread Quote
09-06-2015 , 08:12 PM
Quote:
Originally Posted by iosys
There are those rare people that are beyond the need of an IDE because their memory is astronomical and they just benefit from simple navigation that is included in vim or emacs but they are missing out on stuff by ignorance.
To be fair, everything you listed about IDE's is available in emacs. The difference is that the IDE is domain-specific to the language. Of course, you will get better integration with VS -> .Net and Eclipse -> Java, but that's because those tools were built and optimized to the deep idiosyncrasies of the runtimes they are on. I will say though that VS is a terrible code editor by default and no, I haven't used resharper.

Also, I know that you didn't mean it this way, but not using a mouse is hardly exclusive to IDEs. In fact, most tutorials I've seen that use an IDE has been 99% mouse clicks, but that could be because the teacher is going slow for the new students. Some people will even say that using arrow keys is a waste of valuable time, but I'm somewhat meh on that one, though I think there is tons of value to jumping to braces, beginning of code block, etc.

You can find videos on YouTube where people use emacs as a Java IDE. I don't think I'd be crazy enough to try it myself.
Programming homework and newbie help thread Quote
09-06-2015 , 08:52 PM
Yah i'm not dismissing the emac crowd and I don't think many beginners start with it.

Basically saying, all the features people typically consider from IDEs, are very useful and that people should consider learning them if they are refusing to do so.
Lots of value in writing code as fast as possible and some people don't realize it because they are never taught, which is the main thing that I notice from professors or teachers. I do think that we are approaching a time period where it is becoming more common to be keybinding aware from gamers becoming programmers.

I just think there are multiple types of people and some may not realize the true benefit and it was worth posting about.
Programming homework and newbie help thread Quote
09-06-2015 , 09:21 PM
Is that why our school pushes eclipse for Java, because it's designed for it?

But I can make net beans so much easier on the eyes so much quicker. :-(

And I know all the shortcuts to auto-gen all the bs code I shouldn't waste my time typing!
Programming homework and newbie help thread Quote
09-06-2015 , 10:08 PM
A school shouldn't force a certain IDE on a student. Probably ends up being teachers' preference and if they refuse to let people use other ones, they are probably not very good developers or lazy where they do not want to deal with it for some stupid reason. When a student could just strip it down to the minimum when handing it in.

If a student is using one of the top choices, there shouldn't be a problem, if he knows what he is getting or missing out on.
Programming homework and newbie help thread Quote
09-10-2015 , 02:56 PM
I'm trying to do a rudimentary calorie analysis program for fun, and I'm running into trouble.

The program has a food super class and several subclasses like macaroni, bread, etc.

What I'm trying to do is:
  • go through several nested for loops
  • add one of each food subtype to a Food ArrayList
  • check to make sure I haven't exceeded total available calories, and
  • if I have, then remove *all* of the most recently added food subtype only
  • increment the previous type by adding one more
  • then do it all again.

So I have the loop itself:

Code:
for(int i = 1;tm.underBal();i++){
            tm.addFood(new Quiche());
            for(int k = 1;tm.underBal();k++){
                tm.addFood(new Wrap());
                for(int m = 1;tm.underBal();m++){
                    tm.addFood(new MacMix());
                    for(int n = 1;tm.underBal();n++){
                        tm.addFood(new Bread());
                        if (tm.balanced())
                            out.println("Quiche = "+i+" Wrap = "+k+" MacMix = "+m+" Bread = "+n);
                    }
                    tm.removeFood(new Bread());                    
                }
                tm.removeFood(new MacMix());
            }
            tm.removeFood(new Wrap());
        }
and the code to remove the foods:

Code:
public void removeFood(Food f){
        while (foods.contains(f)){
        foods.remove(f);
        }
    }
What I need this method to do is to remove any of the subclass instances in the ArrayList foods. I'm hoping polymorphism allows this, but I'm not 100% on it. I start with 1 quiche, 1 wrap, 1 MacMix, then add a bread, check total calories, and if there's cals left keep adding bread until I hit cal goals or go over.

I was thinking maybe I could use instanceof somehow, but I don't know how well that would work.

Also, it doesn't quite feel right using removeFood with an anonymous new instance of each food subtype, so that's probably wrong, too.

Any tips? Any way I can make what I'm trying to accomplish more clear? Right now it's just going thru each of the top 3 loops once, adding bread until it's over calories, then exiting all the loops.
Programming homework and newbie help thread Quote
09-10-2015 , 03:15 PM
I changed removeFood to this:

Code:
for (int i = foods.size() - 1; i >=0;i--){
            if (foods.get(i).getClass().equals(f.getClass()))
                foods.remove(i);
        }
and it appears to work, at least it's removing foods. Now I need to rework the nested loop section as it's not working as I'd hoped. Bah!

edit

DERP

Think I figured it out. Don't mind me.

Originally designed it to dynamically update the calorie count, but forgot I removed that functionality. Needed the remove food to take out the calories when something is removed from the arraylist.
Programming homework and newbie help thread Quote
09-10-2015 , 03:35 PM
At a quick glance of what you posted.
You should be more elegant, with naming in your code.
underBal is an example of bad.

Why are you needing to do this all; in 4 for loops for calorie analysis.
If you're just tallying up the calories to see if you hit the max.

Why not write the code, so it just needs one for loop and have the objects needing to be tallied in it.

I don't get needing that many loops for what you're trying to do.
Random question, why are you not starting at zero in your for loops.
You can write code starting at 1 but that seems weird in a counting situation to start at 1.
Programming homework and newbie help thread Quote
09-10-2015 , 03:42 PM
Quote:
Random question, why are you not starting at zero in your for loops.
You can write code starting at 1 but that seems weird in a counting situation to start at 1.
my for loops don't do a comparison between anything related to the iterators, so it doesn't matter where they start. I'm doing 1 just to match the number of things added to the arraylist, such that I have less math to write later.

Quote:
Why are you needing to do this all; in 4 for loops for calorie analysis.
If you're just tallying up the calories to see if you hit the max.
I'm not tracking calories exactly. I'm tracking macro nutrients. So I want a balanced Meal to be x amount of fat, y amount of protein, z amount of carbs.

There may be a more elegant way to do it, but i'm just trying to see if any combination of available food types can come out to the balanced goals.

Quote:
You should be more elegant, with naming in your code.
underBal is an example of bad.
i don't disagree, but this is entirely for personal consumption, ****ing around, that sort of thing. Not anything I'll probably ever show anyone. Just a way to test solving a semi-complex problem in new and interesting ways.
Programming homework and newbie help thread Quote
09-10-2015 , 04:03 PM
Just an opinion of mine, if you stay away from that many nested loops by writing in a more elegant way; you will be faster and code will look useable.

If this is a personal project, no grade or anything and you're fooling around basically.
Seems like the time, to be as elegant as possible because it will help in future for designing the architecture of the objects.

Its not really complex, no matter what you will get a solution working and people always say its about the path you take; not about getting there.

Anyway seems cool, you interested in working around the medical or health field in the future?
Need more programmers in those fields because everything is a complete joke right now in that area for most places that are not in a big city.
Programming homework and newbie help thread Quote
09-10-2015 , 04:10 PM
What is the more elegant way to accomplish that which doesn't involve nested loops?

Note: when macros are balanced, it should output something like "2 quiche, 4 wrap, 2 MacMix, 6 bread" or whatever.

In other words, the goal of the program is to see if any combination of available foods exists that can add up to within a few grams of macro goals.

Because of this, I would think you'd need a for loop for every food type you want to check, with loops arranged from highest calorie at higher levels and lower calories at the lower, more repeated levels.
Programming homework and newbie help thread Quote
09-10-2015 , 05:01 PM
Quote:
Originally Posted by Roonil Wazlib
In other words, the goal of the program is to see if any combination of available foods exists that can add up to within a few grams of macro goals.
not sure exactly what you're looking for but thats a classic linear programming problem
Programming homework and newbie help thread Quote
09-10-2015 , 05:38 PM
Recursively adding the food with doing the computations; would be elegant in this situation you're in.
Probably one of the few times like going through directories, where recursion is great to look at compared to this many nested loops.
Programming homework and newbie help thread Quote
09-10-2015 , 08:30 PM
Quote:
Originally Posted by Roonil Wazlib
I'm trying to do a rudimentary calorie analysis program for fun, and I'm running into trouble.

The program has a food super class and several subclasses like macaroni, bread, etc.

What I'm trying to do is:
  • go through several nested for loops
  • add one of each food subtype to a Food ArrayList
  • check to make sure I haven't exceeded total available calories, and
  • if I have, then remove *all* of the most recently added food subtype only
  • increment the previous type by adding one more
  • then do it all again.

So I have the loop itself:

Code:
for(int i = 1;tm.underBal();i++){
            tm.addFood(new Quiche());
            for(int k = 1;tm.underBal();k++){
                tm.addFood(new Wrap());
                for(int m = 1;tm.underBal();m++){
                    tm.addFood(new MacMix());
                    for(int n = 1;tm.underBal();n++){
                        tm.addFood(new Bread());
                        if (tm.balanced())
                            out.println("Quiche = "+i+" Wrap = "+k+" MacMix = "+m+" Bread = "+n);
                    }
                    tm.removeFood(new Bread());                    
                }
                tm.removeFood(new MacMix());
            }
            tm.removeFood(new Wrap());
        }
and the code to remove the foods:

Code:
public void removeFood(Food f){
        while (foods.contains(f)){
        foods.remove(f);
        }
    }
What I need this method to do is to remove any of the subclass instances in the ArrayList foods. I'm hoping polymorphism allows this, but I'm not 100% on it. I start with 1 quiche, 1 wrap, 1 MacMix, then add a bread, check total calories, and if there's cals left keep adding bread until I hit cal goals or go over.

I was thinking maybe I could use instanceof somehow, but I don't know how well that would work.

Also, it doesn't quite feel right using removeFood with an anonymous new instance of each food subtype, so that's probably wrong, too.

Any tips? Any way I can make what I'm trying to accomplish more clear? Right now it's just going thru each of the top 3 loops once, adding bread until it's over calories, then exiting all the loops.
there is almost surely a better way to do this, but i'm not even sure i understand the goal. your explanation starts off mentioning super classes and nested loops -- that's definitely a warning sign that you're thinking about your problem in a way that's going to make your life difficult.

can you explain in plain english what the program does, the way you would explain it to your grandmother? i'll try to give you helpful feedback after that.
Programming homework and newbie help thread Quote
09-10-2015 , 09:35 PM
Takes an assortment of foods and checks every possible combination of those foods to see if there's a match for a person's macro nutrient goals (fat, protein, carbs)

Something similar to eatthismuch.com
Programming homework and newbie help thread Quote
09-10-2015 , 09:49 PM
Quote:
Originally Posted by Roonil Wazlib
Takes an assortment of foods and checks every possible combination of those foods to see if there's a match for a person's macro nutrient goals (fat, protein, carbs)

Something similar to eatthismuch.com
Is it supposed to return every possible solution, or just one?
Approximately how many foods need to be searched?
Would a goal be defined as a total calorie limit and then a breakdown of the macros by percent?
How exact does the match have to be? Is there a concept of within +/- X%?
Is there a constraint on the total number of foods? Eg, 3 meals a day? Or is simply any number that matches the calorie goal, so that you could 10 snacks or 2 big meals?
Programming homework and newbie help thread Quote
09-10-2015 , 10:02 PM
Every possible permutation given the foods available
Any amount of foods you feel like including
Your personal macro goals, which handles the total calorie and percentage goals on its own
I've allowed +/- 5 grams for each macro when checking for matches
For now, as a sort of proof of concept, it's any number of foods either entered individually or as a meal.

I'm sure there are better ways of figuring it out like e i pi says, just using a formula of some sort instead of iterating over every single permutation. I wouldn't have a clue how to figure out that formula, sadly.
Programming homework and newbie help thread Quote
09-10-2015 , 10:41 PM
Quote:
Originally Posted by Roonil Wazlib
Every possible permutation given the foods available
Any amount of foods you feel like including
Your personal macro goals, which handles the total calorie and percentage goals on its own
I've allowed +/- 5 grams for each macro when checking for matches
For now, as a sort of proof of concept, it's any number of foods either entered individually or as a meal.

I'm sure there are better ways of figuring it out like e i pi says, just using a formula of some sort instead of iterating over every single permutation. I wouldn't have a clue how to figure out that formula, sadly.
i think i understand. the person would enter X grams carbs, Y grams fat, Z grams protein, then you return their options, right?

if that's the case, exhaustive search over arbitrary numbers of options is going to quickly become infeasible. even searching for combos of 3 foods at a time is equivalent to the 3-sum problem which has n^2 complexity (n being the size of your list of all foods). as you allow combos of 4, 5, and more, you'll get higher order polynomial complexity.

if n is relatively small, or you decide to return whatever you've found after X seconds and quit, or some other compromise so you can still make the idea work, i'd suggest finding a stats library to help you iterate over all the possible combos you need -- no reason to reinvent the wheel there. and you can look at that code to see how you solve the general problem without hardcoding a fixed number of nested for loops.
Programming homework and newbie help thread Quote

      
m