• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=ArchXeno;46324740]I've been learning Java independently alongside non-programming college classes, but I've seem a lot of Java hate on /g/ and other places. I know it's verbose compared to other languages, but why exactly does it get so much dislike?[/QUOTE] From what I understand, a lot of the hate comes from the fact that all its code needs to be run through the JVM (Java Virtual Machine). This is what allows it to run on pretty much every platform you can think of, but also adds an extra layer of interfacing that is generally seen as slow, memory intensive, and in many cases vulnerable. I think its syntax is perfectly reasonable, and considering everyone's favorite language, C#, is for many situations identical in syntax I assume most would agree. It is a feature rich, insanely cross-platform language that is used by many for simple hobbyist programming up to corporate enterprise software. It is not without its flaws for sure, but it isn't a bad language and, for better or for worse, isn't going anywhere anytime soon. [QUOTE=sloppy_joes]I think another reason some linux graybeards dislike Java is its seen as being a lot easier.[/QUOTE] I don't think any serious programmer would try to argue that Java is a bad language because it is "easier" than C++. Barring esoteric languages and the like, programming is all about accomplishing a given task efficiently, accurately, and as quickly as possible. If anyone tells you that a language is bad because it is too easy to write code in, they clearly care about the wrong things and probably don't know what they're talking about.
[QUOTE=Socram;46324895]From what I understand, a lot of the hate comes from the fact that all its code needs to be run through the JVM (Java Virtual Machine). This is what allows it to run on pretty much every platform you can think of, but also adds an extra layer of interfacing that is generally seen as slow, memory intensive, and in many cases vulnerable. I think its syntax is perfectly reasonable, and considering everyone's favorite language, C#, is for many situations identical in syntax I assume most would agree. It is a feature rich, insanely cross-platform language that is used by many for simple hobbyist programming up to corporate enterprise software. It is not without its flaws for sure, but it isn't a bad language and, for better or for worse, isn't going anywhere anytime soon. I don't think any serious programmer would try to argue that Java is a bad language because it is "easier" than C++. Barring esoteric languages and the like, programming is all about accomplishing a given task efficiently, accurately, and as quickly as possible. If anyone tells you that a language is bad because it is too easy to write code in, they clearly care about the wrong things and probably don't know what they're talking about.[/QUOTE] the love of C# i believe is because it does many things well but nothing perfect afaik which is why i need to find some online tutorials ;_;
[QUOTE=paindoc;46324941]the love of C# i believe is because it does many things well but nothing perfect afaik which is why i need to find some online tutorials ;_;[/QUOTE] If you know programming constructs I would bypass any general C# tutorials and just start using it for a project, its the best way to learn. Unity, XNA, Monogame, something like that.
[QUOTE=paindoc;46322559][...] (beyond simple while and for loops in arduino and such)[/QUOTE] If you're at that level you'll likely do much better with a somewhat comprehensive book than with tutorials. If you use the latter you're very likely to miss a lot of advanced features. [editline]25th October 2014[/editline] [QUOTE=ArchXeno;46324740]I've been learning Java independently alongside non-programming college classes, but I've seem a lot of Java hate on /g/ and other places. I know it's verbose compared to other languages, but why exactly does it get so much dislike?[/QUOTE] It has barely evolved since it was created, so it lacks a lot of more recent features or has very verbose syntax for them or what is used to emulate them. There's also the issue with not being able to create custom struct types, which means some things will execute [I]a lot[/I] slower without inlining functions manually everywhere. Bytes are signed in Java and there's no matching unsigned 8-bit integer.
[QUOTE=sloppy_joes;46324871]It's also generally slower. [URL]http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?test=all&lang=gpp&lang2=java&data=u64q[/URL] I think another reason some linux graybeards dislike Java is its seen as being a lot easier.[/QUOTE] That's not really a fair comparison to make; you're comparing a compiled language to an interpreted/JIT compiled language - of course it's going to be slower. In relation to the original post, that's the price you pay for having that extra layer of abstraction. I wouldn't really call the JVM slow, however. As people have said before, it's all down to whatever you're comfortable with.
[QUOTE=Socram;46324999]If you know programming constructs I would bypass any general C# tutorials and just start using it for a project, its the best way to learn. Unity, XNA, Monogame, something like that.[/QUOTE] [QUOTE=Tamschi;46325757]If you're at that level you'll likely do much better with a somewhat comprehensive book than with tutorials. If you use the latter you're very likely to miss a lot of advanced features. [/QUOTE] Well being self taught I lack a lot of "foundation" material I guess. Usage of math operators to perform equations is hard for me, and I do have trouble with advanced concepts that my roommate (CS major) has no problem (which figures, but it does show the results of actual classes). Im downloading pdf copies of C# in depth and some basic programming books now (not wares I swear [i think]) and buying C# players guide since it seems to cover some pretty great material over all, and has quite positive reviews for a book that isn't pure reference
-snip, didn't merge properly-
- snip -
[QUOTE=Contron;46326260]That's not really a fair comparison to make; you're comparing a compiled language to an interpreted/JIT compiled language [B]- of course it's going to be slower.[/B] In relation to the original post, that's the price you pay for having that extra layer of abstraction. I wouldn't really call the JVM slow, however. As people have said before, it's all down to whatever you're comfortable with.[/QUOTE] Yeah I know, but I was just saying thats why it gets some hate. Don't get me wrong, I like Java, but those are some of the non-technical reasons people dislike it.
I personally dislike it because some of it's constructs are just plain stupid.
[QUOTE=cartman300;46327939]I personally dislike it because some of it's constructs are just plain stupid.[/QUOTE] Care to elaborate?
[QUOTE=Socram;46328194]Care to elaborate?[/QUOTE] Generics erasure is a good example, the feature is nice when developing but it turns into a horrible mess of casts and type checks at runtime, in addition to not actually being fully type safe at that point.
so i guess i somewhat understand this [code]a, b = 0, 1 while b < 10: print(b) a, b = b, a + b the output 1 1 2 3 5 8 [/code] but my question is does variable a get the previous value stored into it, like if the initial value is 0 and 1 and a + b is essentially 0 + 1 that turns to 1 so then that 1 gets stored into b which is then stored into a so in the next run then b now turns into the value 2 while a still have the value of 1 that then results in 3 so when it gets to that does 2 get stored into a? or am i really off? I'm reading the official documentation, and writing down notes from it, i'm just trying to understand it as i write it down :v:
a' := b b' := a + b [img]http://i.imgur.com/ULMzHCG.png[/img] If you were to expand that to assigning the variables one-by-one, you would need a temporary variable. tmp := a a := b b := tmp + b
[QUOTE=ThePuska;46334004]a' := b b' := a + b [img]http://i.imgur.com/ULMzHCG.png[/img] If you were to expand that to assigning the variables one-by-one, you would need a temporary variable. tmp := a a := b b := tmp + b[/QUOTE] that's what i thought, but when thinking about the process it just doesn't make any sense because after 1 + 1 it just doesn't work the way i am seeing it is if b is 2 then a is 2 but how do you get 3 if 1 isn't stored in a if b overrides it with 2?
[QUOTE=confinedUser;46334048]that's what i thought, but when thinking about the process it just doesn't make any sense because after 1 + 1 it just doesn't work the way i am seeing it is if b is 2 then a is 2 but how do you get 3 if 1 isn't stored in a if b overrides it with 2?[/QUOTE] [code](0) a, b := 0, 1 (1) a, b := (1, (0 + 1)) = 1, 1 (2) a, b := (1, (1 + 1)) = 1, 2 (3) a, b := (2, (1 + 2)) = 2, 3 (4) a, b := (3, (2 + 3)) = 3, 5 (5) a, b := (5, (3 + 5)) = 5, 8[/code]
So if I wanted to make a beeline from an enemy to a player, with the enemy being at (0,0), and the player at (60,70) (on a normal cartesian coordinate plane, for simplicity). The hypotenuse of the right triangle made by their locations is sqrt(8500) (which is ~92.2), and the angle made is ~49.4 degrees. Using only functions that can SET the x and y (such as enemy.setx() and enemy.sety() ) coordinates of an entity, how can i use these numbers to, at a steady rate, move towards a player's location?
Calculate the direction vector: dir = [60 70] - [0 0] = [60 70] Calculate its length: len = sqrt(60^2+70^2) = ~92.2 Normalise the direction vector to length 1: dir/len = 1/len * dir = [0.65 0.76] Move along the direction vector at a predetermined speed s: x_1 = x_0 + 0.65 * s, y_1 = y_0 + 0.76 * s
[QUOTE=proboardslol;46340267]So if I wanted to make a beeline from an enemy to a player, with the enemy being at (0,0), and the player at (60,70) (on a normal cartesian coordinate plane, for simplicity). The hypotenuse of the right triangle made by their locations is sqrt(8500) (which is ~92.2), and the angle made is ~49.4 degrees. Using only functions that can SET the x and y (such as enemy.setx() and enemy.sety() ) coordinates of an entity, how can i use these numbers to, at a steady rate, move towards a player's location?[/QUOTE] Work out the direction vector that goes from the enemy to the player dir = (player - enemy)/||(player - enemy)|| (we're working out the unit vector dir, which is the direction vector between player and enemy, see here if you're rusty on vectors: [url]http://en.wikipedia.org/wiki/Unit_vector[/url]) Think of the x/y coordinates as a ratio by which, if you move, you'll move directly towards the enemy. So, one step towards the player would look like this: enemy.pos = enemy.pos + dir*k (or enemy.setx(enemy.x + dir.x*k) ) Where k is a scalar which adjusts how far the player moves each step simply by multiplying the direction vector (think of it was simply extending the direction vector beyond a unit) Remember to recalculate dir on each step as the player will presumably be moving [editline]27th October 2014[/editline] :(
[QUOTE=esalaka;46341834]Calculate the direction vector: dir = [60 70] - [0 0] = [60 70] Calculate its length: len = sqrt(60^2+70^2) = ~92.2 Normalise the direction vector to length 1: dir/len = 1/len * dir = [0.65 0.76] Move along the direction vector at a predetermined speed s: x_1 = x_0 + 0.65 * s, y_1 = y_0 + 0.76 * s[/QUOTE] what does x_1 and x_0 / y_1 and y_0 correspond to?
[QUOTE=proboardslol;46345119]what does x_1 and x_0 / y_1 and y_0 correspond to?[/QUOTE] _1 is the next step after _0 I.E. enemy.x = enemy.x + (dir.x * s) enemy.x = enemy.x + (0.65 * s)
What is the advantage of [I]switch[/I] statements versus a series of if/else statements, and when should I use one over the other? This sounds like a homework question but Im genuinely curious as I've never seen them before until this online tutorial im doing to learn C#
[QUOTE=paindoc;46347662]What is the advantage of [I]switch[/I] statements versus a series of if/else statements, and when should I use one over the other? This sounds like a homework question but Im genuinely curious as I've never seen them before until this online tutorial im doing to learn C#[/QUOTE] Basically just readability. There are some optimization advantages I believe. If you find yourself writing a list of if statements that all test the value of a single identifier, such as: [code] if(x==1){ //do something } else if(x==2){ //do something } else if(x==3){ //do something } //... else{ //do something else } [/code] then this can be written with less brackets and overall text as: [code]switch(x){ case 1: //do something break; //use break if you want to exit the switch statement upon exit, //omit break if you want to continue checking the value of x with //the rest of the cases case 2: //do something break; case 3: //do something break; //... default: //equivalent of "else" statement. Optional //do some other shit }[/code] note: if-then statements can test any kind of logical comparison, such as x>1, x<1, etc. whereas a select-case statement can only test for equality (x==1, x==1, etc.). Of course, this is all in C. I don't know the rules in C#
[QUOTE=paindoc;46347662]What is the advantage of [I]switch[/I] statements versus a series of if/else statements, and when should I use one over the other? This sounds like a homework question but Im genuinely curious as I've never seen them before until this online tutorial im doing to learn C#[/QUOTE] Switch statements are generally used to check for an enumerated set of values that the programmer knows for sure could be going into the condition, while ifs are for more complicated condition checking and if the input cannot be determined at the time the program is written. Switch statements are also easier to read when used in the above circumstances, in my opinion.
alright, good to know. Thanks to both of you!
Also, switch statements are basically gotos and labels, which allow for interesting fall-through mechanics like in [URL="http://en.wikipedia.org/wiki/Duff%27s_device"]Duff's Device[/URL]. Plus, it generally is faster than if-else, because it can be optimized by the compiler into a direct access lookup table instead of retesting the condition over and over again.
Anybody know the output tables for 2 input inhibition gate? I did search on internet but strangely can't find anything. [editline]28th October 2014[/editline] [code] 0 INHIBIT 0 = ? 0 INHIBIT 1 = ? 1 INHIBIT 0 = ? 1 INHIBIT 1 = ? [/code]
[QUOTE=cartman300;46352026]Anybody know the output tables for 2 input inhibition gate? I did search on internet but strangely can't find anything. [editline]28th October 2014[/editline] [code] 0 INHIBIT 0 = ? 0 INHIBIT 1 = ? 1 INHIBIT 0 = ? 1 INHIBIT 1 = ? [/code][/QUOTE] [img]http://www.expertsmind.com/CMSImages/1646_INHABIT%20GATE.png[/img]
[QUOTE=proboardslol;46352274]an inhibit gate is basically a triple AND gate. All inputs must be 1 for the output to be 1. Basically it's like saying: [code]if((a && b) && c){[/code] the a & b are the first two conditions, which must both be 1 to equal 1, and then the third condition must also equal 1. so if there is a 0 in the input anywhere, the output will be zero[/QUOTE] Actually i remember from school last time we had to use a single AND and NOT gate but i don't remember exactly the outputs [editline]28th October 2014[/editline] Aha, found in one of my notebooks, it's this. [code] 0 INH 0 = 0 0 INH 1 = 0 1 INH 0 = 1 1 INH 1 = 0 [/code]
[QUOTE=cartman300;46352306]Actually i remember from school last time we had to use a single AND and NOT gate but i don't remember exactly the outputs[/QUOTE] you're correct, I meant to say that C must be false, not true. so it's: [code]if((a&&b) && !c){[/code] [editline]28th October 2014[/editline] [url=http://help.synthesisplatform.net/blocksim8/inhibit_gates.htm]for some reason this website has a different interpretation[/url]
Sorry, you need to Log In to post a reply to this thread.