Page 18 of 43

Re: Programming, computers, etc. [Serious]

Posted: Wed Sep 05, 2012 1:09 am
by dewero
Oh... Reading the context in the documentation makes it a little more clear.
public final Buffer clear()

Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.

Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:

buf.clear(); // Prepare buffer for reading
in.read(buf); // Read data

This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.
buffer.clear simply "resets" the buffer, and doesn't actually "clear" the buffer in the sense that data in the buffer is deleted. From what I read, it doesn't seem like it would affect normal coding too much, but then again, programmers like to do funny things.

Re: Programming, computers, etc. [Serious]

Posted: Wed Sep 05, 2012 2:36 pm
by Anonymously Famous
Sometimes resetting the buffer might be useful.

Re: Programming, computers, etc. [Serious]

Posted: Wed Sep 05, 2012 3:54 pm
by atomtengeralattjaro
meh. okay then.

today i continue fiddling around in java networking.

Re: Programming, computers, etc. [Serious]

Posted: Wed Sep 05, 2012 5:54 pm
by Anonymously Famous
I wish you luck.

Re: Programming, computers, etc. [Serious]

Posted: Thu Sep 06, 2012 12:48 am
by dewero
I strongly dislike networking. Maybe that's because I've never done anything with it before

Re: Programming, computers, etc. [Serious]

Posted: Thu Sep 06, 2012 12:50 am
by Anonymously Famous
I really appreciate those who understand and use it in their programming, because I like to use the Internet, and that's all about networking.

Re: Programming, computers, etc. [Serious]

Posted: Thu Sep 06, 2012 1:18 am
by ThingerDudes
had to make a server thing with sockets and encryptions and forking and crap for a project last year. Really really annoying. But fun once you get it working.

Re: Programming, computers, etc. [Serious]

Posted: Thu Sep 06, 2012 2:22 am
by Anonymously Famous
Yeah. It sounds really annoying.

Re: Programming, computers, etc. [Serious]

Posted: Thu Sep 06, 2012 7:37 am
by atomtengeralattjaro
ThingerDudes wrote:had to make a server thing with sockets and encryptions and forking and crap for a project last year. Really really annoying. But fun once you get it working.
what language/platform did you make it in/on?

Re: Programming, computers, etc. [Serious]

Posted: Fri Sep 07, 2012 2:48 am
by ThingerDudes
We had to do it in C. seg faults...so many seg faults...
and do documentation on it which was worth half the grade...
yeah...it was not a fun course.

Re: Programming, computers, etc. [Serious]

Posted: Fri Sep 07, 2012 2:56 pm
by Anonymously Famous
Writing documentation is a good skill to have.

Re: Programming, computers, etc. [Serious]

Posted: Mon Sep 17, 2012 4:50 pm
by atomtengeralattjaro
[continuing from the daily thread]

it occured to me that a 2-dimensional array is not the same as an array of arrays, because in the latter, you might be able to add arrays of varying size to an array of arrays, as opposed to a 2D array, which has only 2 dimensions.

a.)

Code: Select all

X X X X X X X X
X X X X X X X X
X X X X X X X X
X X X X X X X X
b.)

Code: Select all

X X X X
X
X X X X X X X X X X X
X X X X X X X X
i just checked, and it turns out java's syntax in arrays differs from C# in the following way:

java:

Code: Select all

        int[][] a = new int[3][2]; //okay (2D array, not an array of arrays)
        a[0][0] = 1; //cool
        a[0,0] = 1; //not cool
        
        int[,] c; //doesn't compile
        
        int[][] b = new int[3][]; //okay (a 3 sized array of integer arrays)
        b[0] = new int[2]; //okay (let the first element in the 3-sized array be a 2-sized int array)
        b[0][1] = 1; // let the second element of the first element of the b array be 1.

however, in C#:

Code: Select all

            int[,] a = new int[2, 2]; // okay
            a[0, 1] = 87; //okay
            a[0][1] = 44; //wrong

            int[][] c = new int[3][2]; //NOT okay

            int[][] b = new int[3][]; //okay (a 3 sized array of integer arrays)
            b[0] = new int[2]; //okay (let the first element in the 3-sized array be a 2-sized int array)
            b[0][1] = 1; // let the second element of the first element of the b array be 1.
Conclusion: double brackets like this: [][] are the only way to create a 2D array in Java, and are also able to create an array of arrays, but they only mean an array of arrays in C#.
also, accessing 2D arrays in Java is not possible with the C# syntax [,] and [2,3]
and accessing 2D arrays in C# is not possible with the Java syntax [2][3].


it's not all that complicated, i just kinda overcomplicated it, but i wanted to see how they really differ, because i've always thought the syntax of C# and Java are very similar on this basic level. Apparently not.

Re: Programming, computers, etc. [Serious]

Posted: Mon Sep 17, 2012 7:23 pm
by Anonymously Famous
Oh, they're similar, just not exactly the same. On a conceptual level, a 2d array is just an array of arrays with the lengths enforced. There are several languages where 2d arrays aren't explicitly possible - You have to enforce the lengths yourself. This can be tricky in languages that have arrays of modifiable length, like the Python list. Just do a myGrid.append(x) and you've messed up your 2d array.

Of note: Last week, for the first time in my memory, I had a problem in which a 3d array made sense (more accurately, a Python dictionary (named array) of lists of lists).

Re: Programming, computers, etc. [Serious]

Posted: Mon Sep 17, 2012 8:16 pm
by atomtengeralattjaro
ha, stacking dimensions is fun :)
are you saying that there are no real arrays in python?
It is my understanding that arrays (and i mean real arrays, forced and fixed) are good because it is extremely easy for the computer to index them in the memory. All it needs to do is get the address of the beginning, and then add the length of an item, times the index requested. If there are structs in the array, they all have the same length, and if there are objects, it's only their reference stored there anyway, and those are of the same length too. As opposed to lists, where you'd need to step through a bunch of them in different places just to get to the n'th element.

Re: Programming, computers, etc. [Serious]

Posted: Tue Sep 18, 2012 3:01 am
by Anonymously Famous
Python types can change on a whim, and Python lists don't enforce type. There is an array class that enforces type, and it's more memory efficient than lists, but it doesn't have fixed size.

Re: Programming, computers, etc. [Serious]

Posted: Sat Sep 22, 2012 1:37 am
by dewero
Oh the woos of a dynamic language...

Re: Programming, computers, etc. [Serious]

Posted: Sat Sep 22, 2012 4:22 am
by Anonymously Famous
I like dynamic languages.

Re: Programming, computers, etc. [Serious]

Posted: Wed Sep 26, 2012 8:24 pm
by klinscy
Dynamic = more complicated???

Re: Programming, computers, etc. [Serious]

Posted: Wed Sep 26, 2012 9:02 pm
by Anonymously Famous
Nope. Not as efficient, but you don't need to declare types or initiate variables usually.

a = "2"
a = int(a)

No error, because the type can change.

Also, Python and some other related languages can have multiple return values from functions, which I think is cool.

Re: Programming, computers, etc. [Serious]

Posted: Thu Sep 27, 2012 10:40 am
by atomtengeralattjaro
Anonymously Famous wrote:multiple return values from functions
now THAT would be a good thing even in non-dynamic languages. Anytime I have to give multiple results, i need to use out parameters or wrap them in some class. How does it work in python? i mean how do you invoke a method that has multiple return parameters, where do you put the results?