Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 448 449 [450] 451 452 ... 795

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

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6735 on: November 29, 2014, 10:02:06 pm »

I'm starting to learn javascript.


Why the hell is it so friggin weird?
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6736 on: November 29, 2014, 10:07:19 pm »

How's it weird?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6737 on: November 29, 2014, 10:33:05 pm »

Code: [Select]
if (new Array() == false) {console.log('wat')};

var x=0.1+0.2;

if (x!=0.3) { console.log('you serious???') };

var y;

if (y==undefined) { console.log('This is normal...') };

undefined=x;

if (y!=undefined) { console.log('WHY') };


my favorite part is that this code snippet returns undefined... which is now defined as the same as x.
« Last Edit: November 29, 2014, 10:35:41 pm by Putnam »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6738 on: November 29, 2014, 10:40:07 pm »

The first one is just an implicity conversion to the bool type :P
python has an explicit bool([]) == False, which becomes implicit if you use it in an if clause like

if  []:
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6739 on: November 29, 2014, 11:50:57 pm »

God man, where did you find those "errors" in JavaScript? I suggest never reading anything by that person again. Other than the third example, the first is completely normal, expected behavior in any c/c++ based language, the second is 100% normal in all non-decimal number systems with finite precision.

Code: [Select]
if (new Array() == false) {console.log('wat')};This is the normal behavior of c/c++ derived languages. "new" tries to allocated memory to an object, and returns a pointer to the newly allocated memory. If the allocation call fails (e.g. not enough memory), then it returns a null pointer. "false" is the boolean value of a null pointer. so there's no "WTF JavaScript?" here, it's just checking whether the array was allocated, which is the best practice way to go about this. The writer can keep going about his shit-ass "wow proper coding looks retarded because I don't understand it, I won't bother checking memory constraints at all!
Code: [Select]
var x=0.1+0.2;

if (x!=0.3) { console.log('you serious???') };
You never compare floats because of finite precision rounded errors. That is 100% expected to fail.
[spoiler]This is the normal behavior of ALL computers and all number systems. This is where the guy is really revealed as a complete novice and not very educated in mathematics. ALL computer fractions are stored in binary, not decimal, and are rounded to their nearest binary equivalent. Since it's binary then unless those values are expressable as some exact addition of 1/2+1/4+1/8+1/16+1/32+1/64 ... 1/2n-1, where n = number of bits used to store the fractional part, then there will be rounding errors. Hence, binary can't exactly express 1/3,1/5,1/7,1/10 etc.

The binary representation of 1/10, being off-base, is an infinite repeating series of digits, analogous to 1/3 on decimal. say you stored numbers in decimal with finite precision. Then, 1/3 would be 0.33333333. Twice that would be 0.66666666. But 2/3 = 0.66666667 OMG numbers are broken ;o;

Code: [Select]
var y;

if (y==undefined) { console.log('This is normal...') };

undefined=x;

if (y!=undefined) { console.log('WHY') };


I tested this and couldn't get the error behavior
« Last Edit: November 30, 2014, 12:08:05 am by Reelya »
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6740 on: November 29, 2014, 11:53:19 pm »

The first one is just an implicity conversion to the bool type :P
python has an explicit bool([]) == False, which becomes implicit if you use it in an if clause like

if  []:
To be fair, that's just Python checking to see if the list has any values in it. Equivalent to "if len ([]) != 0:"
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.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6741 on: November 30, 2014, 12:11:25 am »

The first one is just an implicity conversion to the bool type :P
python has an explicit bool([]) == False, which becomes implicit if you use it in an if clause like

if  []:
To be fair, that's just Python checking to see if the list has any values in it. Equivalent to "if len ([]) != 0:"

So arrays return the length of the array in Python? which is 0, and boolean false has a numerical value 0 as well, whereas true evaluates to "1". This makes sense because there are no "little words" in a computer memory, there are only 0s and 1s. Every variable is a collection of 0s and 1s, and can be compared to other collections, no matter what they're named in the "language".

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6742 on: November 30, 2014, 12:18:10 am »

How's it weird?
Mostly because it looks vaguely similar to come, while still being completely different.

Void foo() {
}

Vs

Var foo = function() {
} ;

And then there's === which is wat
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6743 on: November 30, 2014, 12:31:59 am »

It's the computer equivalent of maths triple equality symbol
http://en.wikipedia.org/wiki/Triple_bar

http://conceptf1.blogspot.com.au/2014/01/javascript-triple-equals-vs-double-equals-operators.html

It enforces type checking:

1 == "1" is true
1 === "1" is false

It's been added in some non-typed languages to allow explicit type checking in comparisons, === actually runs faster too because it doesn't do an internal type conversion.

« Last Edit: November 30, 2014, 12:35:31 am by Reelya »
Logged

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6744 on: November 30, 2014, 01:28:42 am »

I saw that edit lol.  The old one wouldn't have actually worked right?  I was going to ask a question about it.
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

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6745 on: November 30, 2014, 01:39:14 am »

The first one is just an implicity conversion to the bool type :P
python has an explicit bool([]) == False, which becomes implicit if you use it in an if clause like

if  []:
To be fair, that's just Python checking to see if the list has any values in it. Equivalent to "if len ([]) != 0:"
So arrays return the length of the array in Python? which is 0, and boolean false has a numerical value 0 as well, whereas true evaluates to "1". This makes sense because there are no "little words" in a computer memory, there are only 0s and 1s. Every variable is a collection of 0s and 1s, and can be compared to other collections, no matter what they're named in the "language".
No? Arrays return the array. "bool ()" in Python returns True for any sequence that has at least one value. It also returns True for any non-zero int or float. I don't know what it does with other types like bytes or whatever.
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.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6746 on: November 30, 2014, 10:15:54 am »

Code: [Select]
if (new Array() == false) {console.log('wat')};This is the normal behavior of c/c++ derived languages. "new" tries to allocated memory to an object, and returns a pointer to the newly allocated memory. If the allocation call fails (e.g. not enough memory), then it returns a null pointer. "false" is the boolean value of a null pointer. so there's no "WTF JavaScript?" here, it's just checking whether the array was allocated, which is the best practice way to go about this. The writer can keep going about his shit-ass "wow proper coding looks retarded because I don't understand it, I won't bother checking memory constraints at all!

Um, the thing about this is that I'm pretty sure that JavaScript allocation failures, if they ever happened, would cause the VM to fail catastrophically and throw exceptions anyway.  I've never, ever seen code that checks if new Array() returned a sensible value.  Maybe it's needed in some implementations, but none that I've ever seen.

Quote
Code: [Select]
var y;

if (y==undefined) { console.log('This is normal...') };

undefined=x;

if (y!=undefined) { console.log('WHY') };


I tested this and couldn't get the error behavior

I've seen this one mentioned a lot but have never been able to reproduce it either.  I'm guessing it used to be possible in old browsers but no longer is for some reason.


How's it weird?
Mostly because it looks vaguely similar to come, while still being completely different.

Void foo() {
}

Vs

Var foo = function() {
} ;


JavaScript does still support defining functions in the old fashioned way, and usually does.

Code: [Select]
function foo() {
}

is mostly equivalent to

Code: [Select]
var foo = function() {
};

The difference is that the second is assigning a new function definition to the foo var, which can be invoked like a function.  Functions are first class objects in JavaScript, which means you can assign them and pass them around in functions as arguments.  It takes a little getting used to, but is an enormously powerful feature and one my favorite parts of JavaScript.

Anyway, the part of JavaScript that I find the weirdest is its inheritance model.  Prototypal inheritance is a neat idea, but in JavaScript's case at least it's confusing and leads to some interesting and leads to difficult to track down bugs.  Some syntactic sugar to make inheritance actually happen would be nice rather than having to do weird stuff assigning prototypes around.  The bad part is what happens if you forget the new keyword.  I guess this is more a problem of using generic function definitions as constructors, in as much as you can call them that for JavaScript.
« Last Edit: November 30, 2014, 10:26:47 am by Telgin »
Logged
Through pain, I find wisdom.

Rogue Yun

  • Bay Watcher
  • Beware of the Carp
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6747 on: December 01, 2014, 09:24:31 pm »

I asked this question somewhere else, but I think I aught to ask it here. How exactly do the utilities mods communicate with dwarf fortress?

I'm trying to create a way to interact with dwarf fortress a little differently, where dwarf fortress would run as a mini map and something like stonesense would be how thee player would see and interact with things. More as an exercise in logic than anything, but I could use somewhere to start.
Logged

.:Simple Mood 16x16 ASCII:.
Keep it Simple. Keep it Safe.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6748 on: December 01, 2014, 09:55:13 pm »

I believe they read df's memory directly and edit it directly. Dfhack is an api made by users to make reading and writing certain common memory areas easier.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Rogue Yun

  • Bay Watcher
  • Beware of the Carp
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6749 on: December 01, 2014, 10:09:17 pm »

Do you, or anyone else, know of any documentation on that?
Logged

.:Simple Mood 16x16 ASCII:.
Keep it Simple. Keep it Safe.
Pages: 1 ... 448 449 [450] 451 452 ... 795