Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 620 621 [622] 623 624 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 909067 times)

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9315 on: April 13, 2016, 04:27:15 am »

Over this last week or so I've been responsible for building, in Racket (specifically a very basic version without any bells and whistles [it's Scheme]), object-oriented programming support from scratch, complete with the *this* keyword and single inheritance. Now, it's finally done. That is possibly the longest I've ever spent on a single, non-huge-project assignment, having spent well over 18 hours building it over the course of a handful of days. Definitely a good feeling, but definitely a large pain in the ass (especially since our basic version of Scheme was lacking many bells and whistles that would have been very useful to have).
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9316 on: April 13, 2016, 09:25:38 pm »

Over this last week or so I've been responsible for building, in Racket (specifically a very basic version without any bells and whistles [it's Scheme]), object-oriented programming support from scratch, complete with the *this* keyword and single inheritance. Now, it's finally done. That is possibly the longest I've ever spent on a single, non-huge-project assignment, having spent well over 18 hours building it over the course of a handful of days. Definitely a good feeling, but definitely a large pain in the ass (especially since our basic version of Scheme was lacking many bells and whistles that would have been very useful to have).

What is Racket? An is a "Scheme" like some sort of algorithm/another name for algorith?

I want to say congratulations but I have no idea what you just accomplished. Shed some light for the newcommer if your time allows it?

Python arrays grow and expand to fit their contents IIRC.
Lists do, but sets and tuples do not.

Is that Array Lists or Linked lists? http://www.javatuples.org/ is brand new to me but I did find a site on my first google search.

I'm not sure how it actually works but why does it matter that you can only have a set number of elements in your data point? Isn't the point of arrays to fix the problem of assigning a variable to each and every single bit of data? I want to guess this has to do with saving memory in a program and building efficiency but I felt like asking first.

Also, stupid but how do you demand that your random number generator actually generate a number?
Spoiler (click to show/hide)
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9317 on: April 13, 2016, 09:37:16 pm »

Random.next______(####);

_____ is the type of thing you want.

#### is the range you want it in.  I don't know if you can do 'between x and y' but I think so?

Don't trust me on that, look it up in the javadoc.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9318 on: April 13, 2016, 09:40:32 pm »

Is that Array Lists or Linked lists? http://www.javatuples.org/ is brand new to me but I did find a site on my first google search.
I was talking about Python. I have no idea how Java arrays work.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9319 on: April 14, 2016, 12:35:16 am »

Over this last week or so I've been responsible for building, in Racket (specifically a very basic version without any bells and whistles [it's Scheme]), object-oriented programming support from scratch, complete with the *this* keyword and single inheritance. Now, it's finally done. That is possibly the longest I've ever spent on a single, non-huge-project assignment, having spent well over 18 hours building it over the course of a handful of days. Definitely a good feeling, but definitely a large pain in the ass (especially since our basic version of Scheme was lacking many bells and whistles that would have been very useful to have).

What is Racket? An is a "Scheme" like some sort of algorithm/another name for algorith?

I want to say congratulations but I have no idea what you just accomplished. Shed some light for the newcommer if your time allows it?

Python arrays grow and expand to fit their contents IIRC.
Lists do, but sets and tuples do not.

Is that Array Lists or Linked lists? http://www.javatuples.org/ is brand new to me but I did find a site on my first google search.
As the others have said, tuples are a python thing.

Arrays are fixed length, lists are not.  You would think, considering that, that arrays are more efficient but they usually aren't significantly faster than lists.  IMO there's not much reason to use arrays, unless you're using an existing function that requires an array as an argument.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9320 on: April 14, 2016, 12:57:05 am »

Over this last week or so I've been responsible for building, in Racket (specifically a very basic version without any bells and whistles [it's Scheme]), object-oriented programming support from scratch, complete with the *this* keyword and single inheritance. Now, it's finally done. That is possibly the longest I've ever spent on a single, non-huge-project assignment, having spent well over 18 hours building it over the course of a handful of days. Definitely a good feeling, but definitely a large pain in the ass (especially since our basic version of Scheme was lacking many bells and whistles that would have been very useful to have).

What is Racket? An is a "Scheme" like some sort of algorithm/another name for algorith?

I want to say congratulations but I have no idea what you just accomplished. Shed some light for the newcommer if your time allows it?
Scheme is a programming language in the Lisp language family that looks something like that:
Code: [Select]
(define (double x)
  (* x 2))
Racket is a Scheme dialect.

Lisp languages enable you to program stuff that in most other languages would require you to write a new compiler.
Logged
Taste my Paci-Fist

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9321 on: April 14, 2016, 01:05:51 am »

What is Racket? An is a "Scheme" like some sort of algorithm/another name for algorith?

I want to say congratulations but I have no idea what you just accomplished. Shed some light for the newcommer if your time allows it?
As Antsan mentioned, "Scheme" is a functional programming language and is one of the two main variants of LISP (the other one being Common LISP). "Racket" is a specific version of Scheme, and the language within Racket that we were using ("Pretty Big"), is essentially a very pared down version of Racket that is basically used only for teaching purposes.

Now the type of programming you see in languages like Java is called "object oriented programming", and, to put it in extremely basic terms, that involves gathering like functions into classes (like "Object", for example) that have a set group of functionality. You also tend to use step-by-step based programming styles, such as "do A; do B; do C;". On the other hand there are no real objects in functional programming, so you can't do something like, say "int bob = 3;", and in addition to that fact it uses a form of programming called functional programming, which the closest way to picture it is to picture that you are never allowed to say "do A; do B", at no point are you ever allowed to save what is officially called "state" (or at least you try to do so as little as possible). If you've ever done recursion without using global variables, imagine a whole language where the only thing that exists is recursion-esque functions. You can pass a variable to a function, modify it, and then pass it to something else, but at no point can you ever save it.

What I've done is essentially build the framework from scratch that is required for you to be able to do something similar to "Point bob = new Point(1, 2);", where "Point" is a class that stores an x and y coordinate. It's a huge rush to finally have done it and understand how it works, but it certainly was also a huge pain, it makes you at least sympathize with the people who were trying to write programs back in the early days of computers.

Arrays are fixed length, lists are not.  You would think, considering that, that arrays are more efficient but they usually aren't significantly faster than lists.  IMO there's not much reason to use arrays, unless you're using an existing function that requires an array as an argument.
So it's important to note the difference between Python "lists" (which are virtually identical to C "vectors") and C "lists", which are something completely different. Python lists and C vectors are essentially just arrays with a bit of code running on top of them to do some stuff (like resizing) automatically for you rather than having you worry about it. Unless you are tight on space, or you really want to enforce the fact that this array's size should never ever change in your code, using a Python list/C vector is identical in every way to an array and there's no real drawback.

On the other hand C lists have a big difference from arrays, which is that because they aren't stored contiguously in memory each block only knows about the block that immediately follows or precedes it. This means that while you are doing operations like adding to the end or the beginning it's still O(1) efficiency like just arrays are (and it actually beats arrays in accessing those since it never runs out of space, while C "vectors" or Python "lists" will eventually run out of space and have to perform a O(n) resize operation). C lists also function similarly to arrays in adding or removing to the middle (assuming you fill the array gap), both being O(n) efficiency. The big place where they suffer, however, is reading individual pieces of data out of the middle of a list vs. an array, where lists require O(n) while arrays are simply O(1). They also suffer greatly on space size as well; a C "list" for integers will take, at minimum, 3x the space that a simple C array would take in the same space (and a couple times more than a C vector or Python array would take). It's not a big deal if you are working with short lists on a big ol' computer, but if you're ever working with very large lists or in embedded systems than arrays are the way to go by far.

So in short:
Never changing length? - Array
Changing length? - C vector/python list
Reading/accessing/writing only to ends? - C List
Reading from the middle? - C vector/python list/array
Extremely limited on space/big amounts of data? - Array
« Last Edit: April 14, 2016, 01:08:23 am by i2amroy »
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9322 on: April 14, 2016, 01:45:55 am »

It's worth noting that the C "list" you're describing is a linked list, yes? Judging by your description.
The "lists" in Java are more like C vectors, I believe, although I don't know how well they perform.
(and frequently vectors are structures or classes that hold two to four floating point variables named x, y z, w.  ;))

Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9323 on: April 14, 2016, 02:42:11 am »

Oh... in C# lists are just arrays that can change in length AFAIK.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9324 on: April 14, 2016, 03:03:23 am »

C# list is like a c++ vector, yes. It's stored as an array internally, which gets resized as needed.
Logged

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9325 on: April 14, 2016, 12:48:35 pm »

It's worth noting that the C "list" you're describing is a linked list, yes? Judging by your description.
The "lists" in Java are more like C vectors, I believe, although I don't know how well they perform.
A doubly linked list, to be more specific, yeah. Java "ArrayLists" are indeed basically the same as C vectors (though Java, as you would expect, also has a "LinkedList" class available as well), and as such perform essentially identically AFAIK, albeit slowed greatly by the simple fact that it's an interpreted language running from a VM rather than running as straight machine code like C would. (To make things more confusing Java also has a "Vector" class, which is essentially the same as an ArrayList but with some added synchronization overhead, making it slower but allowing you to use multiple threads running on it at once [albeit still much slower than most manual synchronization implementations would be]).

Also:
(and frequently vectors are structures or classes that hold two to four floating point variables named x, y z, w.  ;))
Har Har Har, what are you, a mathematician? :P

Edit: Fixed misspeak.
« Last Edit: April 14, 2016, 01:59:03 pm by i2amroy »
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9326 on: April 14, 2016, 01:40:41 pm »

albeit slowed greatly by the simple fact that it's an interpreted language running in a VM rather than running as straight machine code like C would.

Not so much - both java and C# compile to bytecode which is compiled to machine code. Either "just in time," but only once per execution, or prior to execution, or by a background service before you decide to run it.

In the case of .net at least, this allows every .net binary to be optimized for your computer specifically, since the final compilation from bytecode to machine code happens on your computer. The main downside is that it's relatively easy to decompile anything written in either java or a .net language back into something resembling the original source code, and even obfuscators only make it annoying to figure out how something works, rather than impossible.
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9327 on: April 14, 2016, 01:57:34 pm »

Not so much - both java and C# compile to bytecode which is compiled to machine code. Either "just in time," but only once per execution, or prior to execution, or by a background service before you decide to run it.

In the case of .net at least, this allows every .net binary to be optimized for your computer specifically, since the final compilation from bytecode to machine code happens on your computer. The main downside is that it's relatively easy to decompile anything written in either java or a .net language back into something resembling the original source code, and even obfuscators only make it annoying to figure out how something works, rather than impossible.
Any form of compilation that involves JIT compilation will be significantly slower than a purely compiled language like C since it has to compile on the fly. (Especially C, since we've spent decades improving it's optimization processes). Programs that fully compile Java that are more common in the professional world (and less so in the academic/learning one that I mainly operate in for the time being) give it a closer edge, but it's still far behind simply in terms of overhead that the language requires (garbage collection anyone?).

That said I did indeed misspeak there by calling it an interpreted language when it's really not and I thank you for catching that. What I meant to say was "albeit slowed greatly by the simple fact that it's an language generally running from a VM rather than running as straight machine code like C would".

Edit, Small addendum: There are some cases where on-site compiling can allow you to perform optimizations that will, after they run once, allow for more efficient code than the C/C++ equivalents, (or at least comparable efficiency). However in the vast majority of cases simple things like direct pointer access to memory that C allows gain you improvements that are vastly superior to any that on-site compiling optimizations would allow, and often allow for much larger optimizations to be performed much more easily for the programmer in C/C++ than they would be in Java or C#.
« Last Edit: April 14, 2016, 02:05:13 pm by i2amroy »
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9328 on: April 14, 2016, 02:03:31 pm »

I think another problem with JIT would be that really sophisticated compilation requires a lot of runtime itself. If you want to compile in real time I assume there's a lot of stuff you won't be able to do.
Logged
Taste my Paci-Fist

Moghjubar

  • Bay Watcher
  • Science gets you to space.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9329 on: April 15, 2016, 12:17:28 am »

Welp, me + guys at handmade got together, built an engine over a few weeks (with windows, linux, and mac(mostly) support) and are planning to use it in the upcoming Ludum dare.  This oughtta be fun... (and first Ludum Dare for me)

Even got a website setup for streaming/misc: http://ludusengine.com/

Interestingly though, my main job is gonna be ART because I'm the only one whos drawn stuff. 
Logged
Steam ID
Making things in Unity
Current Project: Demon Legend
Made This too (publisher abandoned ) Farworld Pioneers
Mastodon
Pages: 1 ... 620 621 [622] 623 624 ... 796