Fun Stuff > CLIKC
A programming thread!
Masterpiece:
Oh wait, I know what I did wrong!
snalin:
Uuuuhrghr Haskell.
Apparently it's not that bad when you learn to write it properly, but I saw one to many "couldn't match the expected type '[[Bool]]' with actual type '[[[[Bool]]]]'" in my half-semester of being taught it. I might try it again. They've got a really great book (Learn You A Haskell For Great Good), and at least it's not fucking Lisp.
ankhtahr:
snalin: try Erlang, to me it feels like Haskell with more real world usecases, and also I feel more comfortable with Erlang than with Haskell.
In other news, I somehow finished the tasks, and am now working on the other programming task (which is due on May 12th, but I wanted to start early).
It starts so fucking easy (It's the new iteration of the "basic programming" course of last semester for the people who didn't manage to get enough points on the exercise sheets), but it gets difficult so fast, that I almost assume they worded the exercise wrong:
--- Quote ---Write the classes "Point", "Line", and "Triangle". A point is a two-dimensional "double" Vector, a line segment consists of two, a triangle of three points.
For the class "Point" a constructor, that creates a Point out of two "double" values. Also write constructors for the classes "Line" and "Triangle", which create a line segment or a Triangle out of two or three points respectively.
Write a method for the class "Line", which returns the point of intersection between itself and another given line segment, if it exists.
Write a constructor for "Triangle", which creates a triangle out of three line segments.
What do you need to change, if you transfer this into a three dimensional space? Which advantages do you now see in object oriented programming?
--- End quote ---
Classes: Check.
Constructors: Check.
Intersection between two line segments? Argh. The simplest solution I've found was this C++ code. Converting this to object oriented Java doesn't seem like such an easy task, if only because I need to write so much. Also I don't see how that should be easy to convert into three dimensions.
Pilchard123:
--- Quote from: snalin on 28 Apr 2014, 18:12 ---Uuuuhrghr Haskell.
Apparently it's not that bad when you learn to write it properly, but I saw one to many "couldn't match the expected type '[[Bool]]' with actual type '[[[[Bool]]]]'" in my half-semester of being taught it. I might try it again. They've got a really great book (Learn You A Haskell For Great Good), and at least it's not fucking Lisp.
--- End quote ---
A Russian spy is returning with information. "I was only able to copy the final part of the new American missile guidance system, but I can tell you that it's written in Lisp."
"How do you know?" asks his handler.
"Well..."
--- Code: ---))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))()())))))))))))))))))))()))))))
)))))))))))))))))))))))))))))))))))))))))))))))())))))))))))))))))))))))))))))))))
)())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))()))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
--- End code ---
snalin:
--- Quote from: ankhtahr on 28 Apr 2014, 21:16 ---Intersection between two line segments? Argh. The simplest solution I've found was this C++ code.
--- End quote ---
The person who wrote that needs to die in programmer hell. Seriously, don't write variable names like s, s1, s1_x. Also, you're allowed to use objects (or structs) and return objects in C++, there is no reason for not having that method read:
--- Code: ---Point get_line_intersection(Line line1, Line line2)
--- End code ---
instead of
--- Code: --- char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y, float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)
--- End code ---
EDIT6: Okay, that took a lot of tries, but the method pointed out in this article actually works. You have to check that the point of intersection is on the line, but otherwise it's golden. I really need to start doing more geometry again!
EDITEDIT: REMEMBER! Eclipse has a generate hashCode/Equals function from "source -> generate hashCode() and equals()", in addition to a bunch of other generators. You should use the equals one - Eclipse will generate a better equals method than you ever could. The correct one for the triangle class is:
--- Code: --- @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Triangle other = (Triangle) obj;
if (p1 == null) {
if (other.p1 != null)
return false;
} else if (!p1.equals(other.p1))
return false;
if (p2 == null) {
if (other.p2 != null)
return false;
} else if (!p2.equals(other.p2))
return false;
if (p3 == null) {
if (other.p3 != null)
return false;
} else if (!p3.equals(other.p3))
return false;
return true;
}
--- End code ---
Did you remember all of your null-checks? You didn't. I wouldn't have remembered them, that's for sure. Have them generated for you!
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version