|
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. |
On February 11 2014 17:24 gedatsu wrote: I'm iffy about including programming as a mandatory subject. Most people will never have a reason to code a single line in their entire life. There are more important skills to "everyday life" that we don't teach in school, such as driving a car.
On the other hand, there already are a number of technical subjects in school curricula that are equally useless. Chemistry is a big one, which I think should be ditched immediately. There's more to it than just being important in everyday life. I don't use chemistry, ever, but it's good to know how it works early so that if I'm interested, I can study it in high school and then get a career in it. I'm willing to bet that the amount of people with degrees in chemistry would sink very quickly if it was removed from the obligatory curriculum.
|
They should do it the way I learned some basic programming skills as a kid. Make them play MUDs and write their own scripts for the clients as their assignments. At least then you're actually writing something that's useful to you, you get a chance to test it actually being used and you learn the very basics that will go a long way if you'll ever want to improve.
What writing such scripts taught me: 1. Declaring and manipulating variables. 2. If/else/elseif statements. 3. For and while loops. 4. Regexp. 5. Stream manipulation.
That's for starters, you'll use it practically everywhere so it's good to know that and learning it through scripting is easier (especially when you get to test the results immediately).
Example:
Capitalize first letter of string s:
strcat(toupper(substr(s, 0, 1)), substr(s, 1))
|
Teaching children programming is useless; programming languages come and go faster than spoken languages so those are only of fairly limited use. Instead, teach them logic. Teach them critical thinking. Teach them problem solving. These things are the basis for programming anyway, and are actually useful in real-life.
|
Hyrule19167 Posts
The basics of programming are almost universal: conditional statements, variables, code flow, and loops. Learning one language makes it significantly easier to pick up others.
|
On February 11 2014 22:32 supereddie wrote: Teaching children programming is useless; programming languages come and go faster than spoken languages so those are only of fairly limited use. Instead, teach them logic. Teach them critical thinking. Teach them problem solving. These things are the basis for programming anyway, and are actually useful in real-life.
You cant just teach children abstract concepts such as critical thinking and problem solving magically. You need some sort of concrete foundation to teach these kinds of concepts through. You don't teach programming instead of critical thinking and problem solving, you teach programming as a way for students to learn critical thinking and problem solving. Then as an added bonus they also learn things like how computers work and knowledge of how to create basic programs themselves.
|
When you call many methods, e.g.:
object.method1().method2().method3()
Is it ok or is there a point when you need to simplify it? E.g.
Object obj = object.method1().method2(); obj.method3();
How far are you allowed to go without corrupting readability?
|
On February 12 2014 04:56 darkness wrote:When you call many methods, e.g.: object.method1().method2().method3() Is it ok or is there a point when you need to simplify it? E.g. Object obj = object.method1().method2(); obj.method3();
How far are you allowed to go without corrupting readability? I don't think there's any best practice for it, you'll just have to use common sense. When using stuff like LINQ in C#, it's very common to use tons of methods in a row, it's also common in JQuery and most functional languages. You get used to it, and if the methods have names which makes sense, it reads more like a sentence which makes it far easier.
I personally never limit myself, but I make sure to break often enough to keep it fitting in a vim window for example.
|
Code isn't readable when you can't read it anymore. Write some code with a long chain and look back at it after a couple of days. If you have trouble reading it, change it.
In other words: Depends on the methods. Especially: if the object doesn't change, you likely can get away with longer chains. If the methods do complex transformations, you probably should introduce some intermediate variables.
In terms of Linq (C#): Select and SelectMany and especially First and FirstOrDefault usually are good points to stop. A simple filter like Where or OfType usually isn't too hard to read.
|
On February 12 2014 04:56 darkness wrote:When you call many methods, e.g.: object.method1().method2().method3() Is it ok or is there a point when you need to simplify it? E.g. Object obj = object.method1().method2(); obj.method3();
How far are you allowed to go without corrupting readability? Just use the fact that newline is not statement terminating in most languages and just have the calls on new lines if it increases readability. But as others pointed out it heavily depends on circumstances.
|
On February 12 2014 04:56 darkness wrote:When you call many methods, e.g.: object.method1().method2().method3() Is it ok or is there a point when you need to simplify it? E.g. Object obj = object.method1().method2(); obj.method3();
How far are you allowed to go without corrupting readability?
There have been quite a lot of people wondering about your exact question. A way to think about this problem is called the Law Of Demeter (Link: https://en.wikipedia.org/wiki/Law_of_Demeter). Its widely accepted. I may try to explain it in my own words:
An object has references to other objects, these are its direct neighbours. They can be accessed through getter methods, in your example this would be 'method1()'. Both objects have a type (yes, even in dynamically typed languages). The first object - in your example 'object' now goes further and calls a method 'method2()' on its neighbour called 'method1()'. By the Law Of Demeter, this is OK as long as the type of that neighbour of a neighbour is either that of yourself or that of your direct neighbour. So any object may only know about types of its own type or of a type of any of its direct neighbours.
Lets get a little more concrete now: Lets say you have the following class (pseudo code, but you will get the point)
class House private House _left = new House private House _right = new House private Door _door = new Door public left() _left public right() _right
public door() _door
class Door private Handle _handle = new Handle
public Handle handle() _handle
class Handle private Color _color = new Color //not needed in this example
So you have a row of houses. Each house refers to its direct neighbours (left and right) and to its door. The types that House is allowed to know are therefore House and Door, but not Handle, because House has no direct reference to Handle, only indirectly through Door. Door is allowed to know about Door and Handle. Handle is allowed to only know Handle.
So inside a method of House, the following would be OK:
left().left().left().door()
but not
left().door().handle()
The first method chain has more methods chained (4) but the second has only 3. Yet the first is OK and the second its. Its because the second one needs a House to know about Handle. But House has no other reference to a Handle but in this method.
Now that I've written all of this i realize that it does not answer your question. Because no matter what version of your code you use, in regard to the Law Of Demeter its the same. House either references Handle our not. If its does so in 1 or 2 lines, does not matter.
To finally answer your question: I would say it depends on what the methods do and what the conventions in your language and project are. Maybe show us the real code or ask a co-worker or who-ever about the concrete case and let him tell you the reasoning behind his opinion so you can learn. In this very abstract case though I would say its a matter of personal preference.
|
Could someone explain how profilers work? I've noticed my GUI game grows by 4-8 bytes rapidly (per second maybe?). So, I've decided to run a profiler (VisualVM), the top memory results were:
Screenshot: http://prikachi.com/images/194/7057194t.png
I don't know if char[] is just being char or if I'm doing something incorrectly, but I don't like how my program's memory grows while idle. Suggestions?
|
Single snapshot isn't as helpful as multiple for a diff. Try to see what's growing, and by how much.
If your program's memory grows by 4-8 bytes per second, I wouldn't sweat it unless it does that indefinitely. 8 bytes of RAM is cheap.
|
On February 12 2014 12:41 darkness wrote:Could someone explain how profilers work? I've noticed my GUI game grows by 4-8 bytes rapidly (per second maybe?). So, I've decided to run a profiler (VisualVM), the top memory results were: Screenshot: http://prikachi.com/images/194/7057194t.pngI don't know if char[] is just being char or if I'm doing something incorrectly, but I don't like how my program's memory grows while idle. Suggestions? Where are you using all those char[]? I've never profiled java myself and I assume java uses it internally, but it just looks weird that there's so much char[] allocations going on when there's so little string activity.
|
On February 12 2014 16:28 Tobberoth wrote:Show nested quote +On February 12 2014 12:41 darkness wrote:Could someone explain how profilers work? I've noticed my GUI game grows by 4-8 bytes rapidly (per second maybe?). So, I've decided to run a profiler (VisualVM), the top memory results were: Screenshot: http://prikachi.com/images/194/7057194t.pngI don't know if char[] is just being char or if I'm doing something incorrectly, but I don't like how my program's memory grows while idle. Suggestions? Where are you using all those char[]? I've never profiled java myself and I assume java uses it internally, but it just looks weird that there's so much char[] allocations going on when there's so little string activity.
I think it's because of string's implementation. Either way, I've started using intern() on strings that are supposed to be reused. It's a bit better, but I wish Java's garbage collection was a bit more adequate. It's just so stupid to sit and wait for something to decide to finally deallocate an object.
|
I need to build an app for android, with a "EditText" where the user can enter a numeric value. It then calculates the binary, octal, and hexadecimal equivalents. There are 4 buttons which are +10, +1, -1, -10. these buttons manipulate the number in de EditText. i've got it to work with the buttons, when i press, for instance +1, it ups the number in the EditText by 1, then calculates the binary, octal and hexadecimal values.
BUT... when a user manually changes the number, the binary, octal, and hexadecimal textviews have to change aswell. How do i do this? The buttons work because on the ButtonListener i update the values, but how do i do this when i cant use a button to trigger the update method? i can't seem to figure this out .
(Also, i dont think my code adds anything to this post, so i won't add it)
|
On February 12 2014 22:22 Garfailed wrote:I need to build an app for android, with a "EditText" where the user can enter a numeric value. It then calculates the binary, octal, and hexadecimal equivalents. There are 4 buttons which are +10, +1, -1, -10. these buttons manipulate the number in de EditText. i've got it to work with the buttons, when i press, for instance +1, it ups the number in the EditText by 1, then calculates the binary, octal and hexadecimal values. BUT... when a user manually changes the number, the binary, octal, and hexadecimal textviews have to change aswell. How do i do this? The buttons work because on the ButtonListener i update the values, but how do i do this when i cant use a button to trigger the update method? i can't seem to figure this out  . (Also, i dont think my code adds anything to this post, so i won't add it)
I think this answers your question: http://stackoverflow.com/questions/14265553/java-android-programming-edittext-gettext-tostring
EditText.getText().toString()
Or do you need event handling? I've recently found Observer and Observable , they're useful when you need to let some object know about a change.
|
On February 12 2014 22:37 darkness wrote:Show nested quote +On February 12 2014 22:22 Garfailed wrote:I need to build an app for android, with a "EditText" where the user can enter a numeric value. It then calculates the binary, octal, and hexadecimal equivalents. There are 4 buttons which are +10, +1, -1, -10. these buttons manipulate the number in de EditText. i've got it to work with the buttons, when i press, for instance +1, it ups the number in the EditText by 1, then calculates the binary, octal and hexadecimal values. BUT... when a user manually changes the number, the binary, octal, and hexadecimal textviews have to change aswell. How do i do this? The buttons work because on the ButtonListener i update the values, but how do i do this when i cant use a button to trigger the update method? i can't seem to figure this out  . (Also, i dont think my code adds anything to this post, so i won't add it) I think this answers your question: http://stackoverflow.com/questions/14265553/java-android-programming-edittext-gettext-tostringEditText.getText().toString()
I already use the information said in there. I read the number and change it to hexadecimal, octal and binary when the user presses a button like +1. However, i need a way to trigger the update() method, when the number changes, without touching any of the buttons.
|
On February 12 2014 22:41 Garfailed wrote:Show nested quote +On February 12 2014 22:37 darkness wrote:On February 12 2014 22:22 Garfailed wrote:I need to build an app for android, with a "EditText" where the user can enter a numeric value. It then calculates the binary, octal, and hexadecimal equivalents. There are 4 buttons which are +10, +1, -1, -10. these buttons manipulate the number in de EditText. i've got it to work with the buttons, when i press, for instance +1, it ups the number in the EditText by 1, then calculates the binary, octal and hexadecimal values. BUT... when a user manually changes the number, the binary, octal, and hexadecimal textviews have to change aswell. How do i do this? The buttons work because on the ButtonListener i update the values, but how do i do this when i cant use a button to trigger the update method? i can't seem to figure this out  . (Also, i dont think my code adds anything to this post, so i won't add it) I think this answers your question: http://stackoverflow.com/questions/14265553/java-android-programming-edittext-gettext-tostringEditText.getText().toString() I already use the information said in there. I read the number and change it to hexadecimal, octal and binary when the user presses a button like +1. However, i need a way to trigger the update() method, when the number changes, without touching any of the buttons.
So you need some kind of notifier when the number is changed from EditText? Edit: actually, there is a solution here: http://stackoverflow.com/questions/11134144/android-edittext-onchange-listener
|
On February 12 2014 22:45 darkness wrote:Show nested quote +On February 12 2014 22:41 Garfailed wrote:On February 12 2014 22:37 darkness wrote:On February 12 2014 22:22 Garfailed wrote:I need to build an app for android, with a "EditText" where the user can enter a numeric value. It then calculates the binary, octal, and hexadecimal equivalents. There are 4 buttons which are +10, +1, -1, -10. these buttons manipulate the number in de EditText. i've got it to work with the buttons, when i press, for instance +1, it ups the number in the EditText by 1, then calculates the binary, octal and hexadecimal values. BUT... when a user manually changes the number, the binary, octal, and hexadecimal textviews have to change aswell. How do i do this? The buttons work because on the ButtonListener i update the values, but how do i do this when i cant use a button to trigger the update method? i can't seem to figure this out  . (Also, i dont think my code adds anything to this post, so i won't add it) I think this answers your question: http://stackoverflow.com/questions/14265553/java-android-programming-edittext-gettext-tostringEditText.getText().toString() I already use the information said in there. I read the number and change it to hexadecimal, octal and binary when the user presses a button like +1. However, i need a way to trigger the update() method, when the number changes, without touching any of the buttons. So you need some kind of notifier when the number is changed from EditText? Edit: actually, there is a solution here: http://stackoverflow.com/questions/11134144/android-edittext-onchange-listener
aah yes, that did the job, got it fully operational now thanks alot! I should really start using stackoverflow for this kind of junk
|
Anyone with practical experience of Java's System Look and Feel? It uses the native platform's L&F, so I wonder if there is any problem with that. I handle exceptions by reverting to the Cross Platform L&F which should be available for all JVM.
Edit: Motif L&F looks terrible... :D
|
|
|
|
|
|