|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
edit: I suck at posting
On September 10 2016 08:42 Manit0u wrote:Show nested quote +On September 10 2016 01:37 phar wrote: Yea this is likely not the important part of the error message. (In fact if you run with sudo the bit about a file not found may go away depending on your setup). Please give me some credit... 1. I've tried running it with sudo (same result). 2. I've read somewhere on the interwebz that it might be the result of someone using their libraries and paths to compile the code which breaks on my machine. I've created a new C file with a single assert that's failing, compiled it and dbg'd it, the result is the same. 3. I've installed a ton of additional libraries I don't need but might be used by it (libc6-dev etc.), same thing. 4. People on the interwebz keep saying that you should ignore this error but it's driving me mad. I did stuff like whreis file.c, which returned a manual but not the file. I've found the file eventually but under completely different path (somewhere inside /usr/share/). I don't even know what provides this specific file and there's no info about it on the net. Please help. My perfectionist soul is dying here because I don't know if valgrind/dbg stop because of this error or errors in the application... Edit: So far it seems to only show up on uncaught throws and asserts. Need to do more testing but I'm too drunk atm.
Browsing the internet watching GSL - you can get rid of error by putting that file in the path relative to the executable you're running as a quick fix if you rly care (but shouldn't matter tbh).
Real fix is you probably need to recompile whatever is calling it.
based off http://stackoverflow.com/questions/13152775/debugging-c-nptl-sysdeps-unix-sysv-linux-raise-c-no-such-file-or-directo and my testing just run (which is how I'm confident putting the file at relative path will get rid of error at least)
edit: looked into this a bit more since gsl finals sucked and it seems to be something about glibc. keep in mind i literally have written no c++ code ever but glibc abort.c includes signal, signal defines "raise" as an extern function, and has both a raise.c in a few places, including https://github.com/lattera/glibc/blob/master/nptl/sysdeps/unix/sysv/linux/raise.c. I'm not sure how extern is resolved by compiler but I'd assume that when it was compiled it resolved that^^ raise.c, even though it seems the glibc on ubuntu I downloaded from https://launchpad.net/glibc doesn't have the sysdeps under nptl.
|
When I skim through the discussions and whatnot I feel like an absolute noob, which I am haha. Started my first year through evening classes for a graduate degree in IT (choose to take the programming road and not networks) after working like an animal in something I really don't see myself doing for another 5 years, going through C# first, are there any websites (like hackerrank for example) where you can practice your C# skills? For exampe being presented with a problem and trying to find the solution and whatnot?
|
On September 10 2016 19:47 gswittiness wrote: When I skim through the discussions and whatnot I feel like an absolute noob, which I am haha. Started my first year through evening classes for a graduate degree in IT (choose to take the programming road and not networks) after working like an animal in something I really don't see myself doing for another 5 years, going through C# first, are there any websites (like hackerrank for example) where you can practice your C# skills? For exampe being presented with a problem and trying to find the solution and whatnot?
Do the problems have to mention C#?
What do you plan on doing with C#?
but here are some mathy problems: https://projecteuler.net/ and bioinformatics problems: http://rosalind.info/problems/locations/
probably not very useful for you though, practically speaking :p
|
On September 10 2016 20:17 Ktk wrote:Show nested quote +On September 10 2016 19:47 gswittiness wrote: When I skim through the discussions and whatnot I feel like an absolute noob, which I am haha. Started my first year through evening classes for a graduate degree in IT (choose to take the programming road and not networks) after working like an animal in something I really don't see myself doing for another 5 years, going through C# first, are there any websites (like hackerrank for example) where you can practice your C# skills? For exampe being presented with a problem and trying to find the solution and whatnot? Do the problems have to mention C#? What do you plan on doing with C#? but here are some mathy problems: https://projecteuler.net/and bioinformatics problems: http://rosalind.info/problems/locations/probably not very useful for you though, practically speaking :p
Well, our prof told us we'd be focusing on C# only (at least this semester) so right now that's also the only thing I want to focus on instead of getting ahead of myself by including other languages, one step at a time. Anything that can be helpful to learn and improve my C# knowledge is basically what I'm looking for.
|
|
On September 10 2016 20:21 gswittiness wrote:Show nested quote +On September 10 2016 20:17 Ktk wrote:On September 10 2016 19:47 gswittiness wrote: When I skim through the discussions and whatnot I feel like an absolute noob, which I am haha. Started my first year through evening classes for a graduate degree in IT (choose to take the programming road and not networks) after working like an animal in something I really don't see myself doing for another 5 years, going through C# first, are there any websites (like hackerrank for example) where you can practice your C# skills? For exampe being presented with a problem and trying to find the solution and whatnot? Do the problems have to mention C#? What do you plan on doing with C#? but here are some mathy problems: https://projecteuler.net/and bioinformatics problems: http://rosalind.info/problems/locations/probably not very useful for you though, practically speaking :p Well, our prof told us we'd be focusing on C# only (at least this semester) so right now that's also the only thing I want to focus on instead of getting ahead of myself by including other languages, one step at a time. Anything that can be helpful to learn and improve my C# knowledge is basically what I'm looking for.
Simply using it is one of the best ways to improve. Stackoverflow has a nice list of sites and forums that give hundreds of programming problems and puzzles. Some are specific for a language, but plenty are just open puzzles. Pick one that interests you and solve using C#.
http://programmers.stackexchange.com/questions/756/where-can-i-find-programming-puzzles-and-challenges
|
Call me a retard but is it normal to waste full day on setting up eclipse with Symfony and run the code against apache httpd server and still not working?
|
On September 10 2016 18:58 Manit0u wrote:Show nested quote +On September 10 2016 17:55 Hhanh00 wrote: Your question is about the 'No such file or directory.' or about the reason of the abort?
No such file or directory.
The compiler leaves debugging info (unless you strip them) that relates offsets in the binary code to lines in the source code. gdb breaks when your app raises SIGABRT (maybe because of an assert?). It tries to decode the stack by looking up return addresses. It found that the closest line is line 56 of raise.c but can't find the actual file on your system. By the way, that line is
int ret = INLINE_SYSCALL (tgkill, 3, pid, tid, sig);
which shows that we are about to go to the kernel which makes sense since we are raising a signal after all.
If you want to get rid of the message, you can download the source code of glibc and specify its location in .gdbinit https://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html
Obviously, you can also simply ignore it.
Edit: You don't have the file because it is a file from the glibc that was compiled by someone else. gdb doesn't care about what code belongs to who. Your code is treated the same way as any user code - including the C runtime.
|
Sensing I needed to review and make sure I understand java basics I wrote a pointless program. I wanted to check that I knew how to write things like equals, toString, getters/setters, constructors, and use inheritance correctly.
If anyone has free time could they look at my code and make sure I am not doing anything naughty? Also I have 3 questions about the code (one in particular is important)
animal class + Show Spoiler + package life;
public class animal { private String type; private int age; private String size; public animal(){ this.type = "unknown"; this.age = 0; this.size = "unknown"; }
public animal(int a, String t, String s){ this.age = a; this.type = t; this.size = s; } public animal(animal oldAnimal){ this.age = oldAnimal.age; this.type = oldAnimal.type; this.size = oldAnimal.size; } public String toString(){ return ("This is a " + this.type + ", it is " + this.age + " years old, and it is " + this.size); } public boolean equals(Object other){ if(this == other){ return true; } if(!(other instanceof animal)){ return false; } animal a = (animal) other; return this.toString() == a.toString(); } public void move(){ System.out.println(this.type + " moved"); } public void eat(String f){ System.out.println(this.type + " ate " + f); } public void setType(String t){ this.type = t; } public void setAge(int a){ this.age = a; } public void setSize(String s){ this.size = s; } public String getType(){ return this.type; } public int getAge(){ return this.age; } public String getSize(){ return this.size; } }
Human Class + Show Spoiler + package life;
public class human extends animal { private String name; public human(){ super(); this.name = "unnamed"; } public human(String n, String t, String s, int a){ super(a, t, s); this.name = n; } public human(human oldHuman){ super(oldHuman); this.name = oldHuman.name; } public String toString(){ return (super.toString() + " and it's name is " + this.name); } public boolean equals(Object other){ if(this == other){ return true; } if(!(other instanceof human)){ return false; } human h = (human) other; return this.toString() == h.toString(); } public void complain(String c){ System.out.println(this.name + " complains about " + c); } public void setName(String n){ this.name = n; } public String getName(){ return this.name; }
}
"engine" + Show Spoiler + package life;
import java.util.ArrayList; import java.util.Iterator;
public class life {
public static void main(String[] args) { ArrayList<human> humanList = new ArrayList<human>(); humanList.add(new human()); humanList.add(new human("Tim", "mammal", "medium", 25)); humanList.add(new human("Burt", "mammal", "huge", 43)); humanList.add(new human(humanList.get(1))); Iterator<human> iterate = humanList.iterator(); while(iterate.hasNext()){ human thisHuman = iterate.next(); System.out.println(thisHuman.getName()); } for(human h : humanList){ System.out.println(h.toString()); } System.out.println(humanList.get(0).equals(humanList.get(1))); System.out.println(humanList.get(1).equals(humanList.get(3)));
}
}
my questions + Show Spoiler + 1.) my equals method is based on what I was taught in lecture. my question is, what is the point of casting the object type when I am already checking if it is an instance of that object type?
in the specific example in lecture the professor does call an equals method within the equals method - he uses super.equals(other), but even with that example I don't understand why the casting is necessary.
2.) when I call super(oldHuman) in my constructor - what sorcery is this. it seems like magic. is this one of those things that java can "just do" ?
3.) System.out.println(humanList.get(1).equals(humanList.get(3))); is returning false. why? shouldn't this return true?
thank you to any kind souls who help me out
|
On September 10 2016 22:59 Wrath wrote: Call me a retard but is it normal to waste full day on setting up eclipse with Symfony and run the code against apache httpd server and still not working?
After 2 years of work experience, I think one could spend hours/days on stupid things which, once you figure out, could be simple. For example, I've spent about 3 work days trying to debug an application hosted by IIS. I couldn't figure out what the problem was when I was debugging from Visual Studio. It was happening, at least quickly, when there was no debugging/attaching to process involved and when there were a lot of requests in a short time. Anyway, solution was just to use 'using' block. What a stupid problem to have! :D
|
On September 11 2016 06:55 travis wrote:Sensing I needed to review and make sure I understand java basics I wrote a pointless program. I wanted to check that I knew how to write things like equals, toString, getters/setters, constructors, and use inheritance correctly. If anyone has free time could they look at my code and make sure I am not doing anything naughty? Also I have 3 questions about the code (one in particular is important) animal class + Show Spoiler + package life;
public class animal { private String type; private int age; private String size; public animal(){ this.type = "unknown"; this.age = 0; this.size = "unknown"; }
public animal(int a, String t, String s){ this.age = a; this.type = t; this.size = s; } public animal(animal oldAnimal){ this.age = oldAnimal.age; this.type = oldAnimal.type; this.size = oldAnimal.size; } public String toString(){ return ("This is a " + this.type + ", it is " + this.age + " years old, and it is " + this.size); } public boolean equals(Object other){ if(this == other){ return true; } if(!(other instanceof animal)){ return false; } animal a = (animal) other; return this.toString() == a.toString(); } public void move(){ System.out.println(this.type + " moved"); } public void eat(String f){ System.out.println(this.type + " ate " + f); } public void setType(String t){ this.type = t; } public void setAge(int a){ this.age = a; } public void setSize(String s){ this.size = s; } public String getType(){ return this.type; } public int getAge(){ return this.age; } public String getSize(){ return this.size; } }
Human Class + Show Spoiler + package life;
public class human extends animal { private String name; public human(){ super(); this.name = "unnamed"; } public human(String n, String t, String s, int a){ super(a, t, s); this.name = n; } public human(human oldHuman){ super(oldHuman); this.name = oldHuman.name; } public String toString(){ return (super.toString() + " and it's name is " + this.name); } public boolean equals(Object other){ if(this == other){ return true; } if(!(other instanceof human)){ return false; } human h = (human) other; return this.toString() == h.toString(); } public void complain(String c){ System.out.println(this.name + " complains about " + c); } public void setName(String n){ this.name = n; } public String getName(){ return this.name; }
}
"engine" + Show Spoiler + package life;
import java.util.ArrayList; import java.util.Iterator;
public class life {
public static void main(String[] args) { ArrayList<human> humanList = new ArrayList<human>(); humanList.add(new human()); humanList.add(new human("Tim", "mammal", "medium", 25)); humanList.add(new human("Burt", "mammal", "huge", 43)); humanList.add(new human(humanList.get(1))); Iterator<human> iterate = humanList.iterator(); while(iterate.hasNext()){ human thisHuman = iterate.next(); System.out.println(thisHuman.getName()); } for(human h : humanList){ System.out.println(h.toString()); } System.out.println(humanList.get(0).equals(humanList.get(1))); System.out.println(humanList.get(1).equals(humanList.get(3)));
}
}
my questions + Show Spoiler + 1.) my equals method is based on what I was taught in lecture. my question is, what is the point of casting the object type when I am already checking if it is an instance of that object type?
in the specific example in lecture the professor does call an equals method within the equals method - he uses super.equals(other), but even with that example I don't understand why the casting is necessary.
2.) when I call super(oldHuman) in my constructor - what sorcery is this. it seems like magic. is this one of those things that java can "just do" ?
3.) System.out.println(humanList.get(1).equals(humanList.get(3))); is returning false. why? shouldn't this return true?
thank you to any kind souls who help me out
1. It's standard practice to do an instanceof on a type before you cast it. In this specific case, you're checking if it isn't an instance of Human because if it's not an instanceof Human then it can't be equal. The way you're comparing the objects seems strange though. You should be ensuring that the fields have the same values rather than checking their toString output even though these technically produce the same thing.
2. This is a copy constructor. I'll just let you google java copy constructor and read about it.
Conventions wise; are all your class names lower case? Class names should be uppercase.
|
On September 11 2016 06:55 travis wrote:Sensing I needed to review and make sure I understand java basics I wrote a pointless program. I wanted to check that I knew how to write things like equals, toString, getters/setters, constructors, and use inheritance correctly. If anyone has free time could they look at my code and make sure I am not doing anything naughty? Also I have 3 questions about the code (one in particular is important) animal class + Show Spoiler + package life;
public class animal { private String type; private int age; private String size; public animal(){ this.type = "unknown"; this.age = 0; this.size = "unknown"; }
public animal(int a, String t, String s){ this.age = a; this.type = t; this.size = s; } public animal(animal oldAnimal){ this.age = oldAnimal.age; this.type = oldAnimal.type; this.size = oldAnimal.size; } public String toString(){ return ("This is a " + this.type + ", it is " + this.age + " years old, and it is " + this.size); } public boolean equals(Object other){ if(this == other){ return true; } if(!(other instanceof animal)){ return false; } animal a = (animal) other; return this.toString() == a.toString(); } public void move(){ System.out.println(this.type + " moved"); } public void eat(String f){ System.out.println(this.type + " ate " + f); } public void setType(String t){ this.type = t; } public void setAge(int a){ this.age = a; } public void setSize(String s){ this.size = s; } public String getType(){ return this.type; } public int getAge(){ return this.age; } public String getSize(){ return this.size; } }
Human Class + Show Spoiler + package life;
public class human extends animal { private String name; public human(){ super(); this.name = "unnamed"; } public human(String n, String t, String s, int a){ super(a, t, s); this.name = n; } public human(human oldHuman){ super(oldHuman); this.name = oldHuman.name; } public String toString(){ return (super.toString() + " and it's name is " + this.name); } public boolean equals(Object other){ if(this == other){ return true; } if(!(other instanceof human)){ return false; } human h = (human) other; return this.toString() == h.toString(); } public void complain(String c){ System.out.println(this.name + " complains about " + c); } public void setName(String n){ this.name = n; } public String getName(){ return this.name; }
}
"engine" + Show Spoiler + package life;
import java.util.ArrayList; import java.util.Iterator;
public class life {
public static void main(String[] args) { ArrayList<human> humanList = new ArrayList<human>(); humanList.add(new human()); humanList.add(new human("Tim", "mammal", "medium", 25)); humanList.add(new human("Burt", "mammal", "huge", 43)); humanList.add(new human(humanList.get(1))); Iterator<human> iterate = humanList.iterator(); while(iterate.hasNext()){ human thisHuman = iterate.next(); System.out.println(thisHuman.getName()); } for(human h : humanList){ System.out.println(h.toString()); } System.out.println(humanList.get(0).equals(humanList.get(1))); System.out.println(humanList.get(1).equals(humanList.get(3)));
}
}
my questions + Show Spoiler + 1.) my equals method is based on what I was taught in lecture. my question is, what is the point of casting the object type when I am already checking if it is an instance of that object type?
in the specific example in lecture the professor does call an equals method within the equals method - he uses super.equals(other), but even with that example I don't understand why the casting is necessary.
2.) when I call super(oldHuman) in my constructor - what sorcery is this. it seems like magic. is this one of those things that java can "just do" ?
3.) System.out.println(humanList.get(1).equals(humanList.get(3))); is returning false. why? shouldn't this return true?
thank you to any kind souls who help me out
I advise you to test for equals using the attributes themselves and not the toString. Also you need to call equals on the toString result because now you're testing for reference equality (which will fail) and not the kind of equals you want. That's probably the reason for 3) Most IDEs can generate the equals (and hashCode) for you. Btw, if you define your own equals you should also define a hashCode method that's compatible.
|
ah thanks guys
okay so class names capitalized, got it
shasta, you are correct about the problem with my equals method and your explanation makes sense. Don't know what a hashCode method is but I guess that's something new to learn
|
On September 10 2016 22:59 Wrath wrote: Call me a retard but is it normal to waste full day on setting up eclipse with Symfony and run the code against apache httpd server and still not working?
First of all, if you're developing with Symfony you don't even need Apache. Symfony has its own built-in server for development purposes if you need one.
You can of course still use Apache, Nginx or whatever else you need (for Apache note that Symfony doesn't use .htaccess and you must have proper Require All Granted etc. set in your host settings, you can look those up in the Symfony docs).
Second thing is the fact that you should not use Eclipse for that. NetBeans would be better but still shitty. Just for learning you could be using PhpStorm (with super duper mega excellent symfony plugin) in its 30-day free trial (or endless trial if you're a student). Trust me, it's miles apart from any freeware solution. I can't even look at Eclipse or NetBeans after using jetbrains products...
|
The amount of boilerplate code required to implement a trivial struct in Java is sad.
+ Show Spoiler + public class Animal { private String type; private int age; private String size;
public Animal(String type, int age, String size) { this.type = type; this.age = age; this.size = size; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getSize() { return size; }
public void setSize(String size) { this.size = size; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false;
Animal animal = (Animal) o;
if (age != animal.age) return false; if (type != null ? !type.equals(animal.type) : animal.type != null) return false; return size != null ? size.equals(animal.size) : animal.size == null; }
@Override public int hashCode() { int result = type != null ? type.hashCode() : 0; result = 31 * result + age; result = 31 * result + (size != null ? size.hashCode() : 0); return result; }
@Override public String toString() { return "Animal{" + "type='" + type + '\'' + ", age=" + age + ", size='" + size + '\'' + '}'; } }
Fortunately some IDEs can generate this for you but it's still a hassle when you don't have one or you want to update the class definition later.
It's also so easy to forget about checking for null values and forgetting about hashCode() when you implement equals.
Compare this to scala:
case class Animal(tpe: String, age: Int, size: String)
A single line is all it takes.
In case you are stuck with Java, you may want to take a look at Project Lombok that uses AOP to inject the boiler plate.
The java code becomes
@Data public class Animal { private String type; private int age; private String size; }
and ends up being the same bytecode.
PS: To the @OP, in additional to what other people told you, the main issue in your code is that equals doesn't handle null values and will throw an exception. Also, equals is supposed to return true only if both values have the same class so an animal cannot be equal to a human. With instanceof T you are checking if the right hand side is T or derived from T.
|
Ideally you never construct a new struct-like class yourself and just use some autogens like AutoValue.
|
Also you don't have to make getters and setters unless you need to control access. Just make the members public.
|
On September 11 2016 11:11 Manit0u wrote:Show nested quote +On September 10 2016 22:59 Wrath wrote: Call me a retard but is it normal to waste full day on setting up eclipse with Symfony and run the code against apache httpd server and still not working? First of all, if you're developing with Symfony you don't even need Apache. Symfony has its own built-in server for development purposes if you need one. You can of course still use Apache, Nginx or whatever else you need (for Apache note that Symfony doesn't use .htaccess and you must have proper Require All Granted etc. set in your host settings, you can look those up in the Symfony docs). Second thing is the fact that you should not use Eclipse for that. NetBeans would be better but still shitty. Just for learning you could be using PhpStorm (with super duper mega excellent symfony plugin) in its 30-day free trial (or endless trial if you're a student). Trust me, it's miles apart from any freeware solution. I can't even look at Eclipse or NetBeans after using jetbrains products...
I'm not a student and I can't guarantee that the workplace will provide me a phpstorm. That is why I'm trying to get a free IDE...
|
On September 11 2016 13:21 Blisse wrote: Also you don't have to make getters and setters unless you need to control access. Just make the members public.
The downside is in Java is that if you wanna change it to a method you have to change every callsite. You can argue that in the case you're refactoring a public property into a method that's not a big deal, but other languages let $object.property be either a direct instance variable lookup or a method call.
On September 11 2016 14:44 Wrath wrote:Show nested quote +On September 11 2016 11:11 Manit0u wrote:On September 10 2016 22:59 Wrath wrote: Call me a retard but is it normal to waste full day on setting up eclipse with Symfony and run the code against apache httpd server and still not working? First of all, if you're developing with Symfony you don't even need Apache. Symfony has its own built-in server for development purposes if you need one. You can of course still use Apache, Nginx or whatever else you need (for Apache note that Symfony doesn't use .htaccess and you must have proper Require All Granted etc. set in your host settings, you can look those up in the Symfony docs). Second thing is the fact that you should not use Eclipse for that. NetBeans would be better but still shitty. Just for learning you could be using PhpStorm (with super duper mega excellent symfony plugin) in its 30-day free trial (or endless trial if you're a student). Trust me, it's miles apart from any freeware solution. I can't even look at Eclipse or NetBeans after using jetbrains products... I'm not a student and I can't guarantee that the workplace will provide me a phpstorm. That is why I'm trying to get a free IDE...
If for some reason work refuses to pay for it I'd really recommend just buying it yourself. Idk if you're not in US but if you are it's pretty cheap; I did that for my first job and I didn't regret it at all.
|
On September 11 2016 12:09 Hhanh00 wrote:In case you are stuck with Java, you may want to take a look at Project Lombok that uses AOP to inject the boiler plate. The java code becomes @Data public class Animal { private String type; private int age; private String size; }
and ends up being the same bytecode. I've looked into AOP but never actually used it. You probably have some actual experience with it. I've always wondered how it affects debugging - you obviously can't step through single lines of code if you never write them. How's that working out for you?
|
|
|
|