Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Javascript Boolean

Name: Anonymous 2016-09-30 21:51

The Boolean object is an object wrapper for a boolean value.

Syntax

new Boolean([value])

Parameters

value
Optional. The initial value of the Boolean object.

Any object whose value is not undefined or null, including a Boolean object whose value is false, evaluates to true when passed to a conditional statement. For example, the condition in the following if statement evaluates to true:

var x = new Boolean("false");
if (x) {
// this code is executed
}


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean

Name: Anonymous 2016-09-30 21:57

it's fucking garbage

Name: Anonymous 2016-09-30 23:02

Standard::Boolean ShopInstance.ArticleInShoppingCart = new Standard::Boolean(Encoding::toUnicode("false", 8)).BooleanFactory.CacheSize.set(256);

if(ShopInstance.ArticleInShoppingCart.MemoryReference === Memory::InvalidReference) {
throw new Exceptions::ShopInstance.ArticleInShoppingCart.InvalidException.Exception(Encoding::toUnicode("Error message so specific that googling it produces exactly 3 results, none of which actually contain a solution to the problem.", 16));
}


Don't laugh now, wait until you see it in real life.

Name: Anonymous 2016-09-30 23:03

>>3
Oh shit, I forgot a ``mutable''.

Name: Anonymous 2016-10-01 0:08

>>1
Uh, you're using a STRING as an argument for the Boolean constructor. What if you instead used
var x = new Boolean(false);

EDIT: Just tested in node.exe, apparently a var assigned "new Boolean(true)" evaluates to true, however the negation of a var assigned "new Boolean(false)" evaluates to false.

Name: Anonymous 2016-10-01 1:34

>>5
if (new Boolean("false") && new Boolean(false) && new Boolean("FALSE") && new Boolean(0) && new Boolean()
&& new Boolean(-1) && new Boolean(NaN) && new Boolean(null) && new Boolean(undefined) && new Boolean([]) && new Boolean({})) {
// this code is executed
}

Name: Anonymous 2016-10-01 4:01

>>1

Why wouldn't that code be executed? You wrote
if (x) {
...

where x is of the type Object

Name: Anonymous 2016-10-01 9:02

Single false value for everything is the only option.
Like 0 for C and nil for Lisp.

Name: Anonymous 2016-10-01 10:41

This isn't exactly the main problem here, but this could have been prevented by not allowing implicit conditionals (i.e., if(var) instead of if(var == true)). JavaShit is un/dynamically typed. Implicit conditionals would only work if the type of the variable is known to be a boolean one.

Name: Cudder !cXCudderUE 2016-10-01 14:47

Makes sense to me. The if is testing whether an object is present, regardless of its contents. They could've added something like C++'s implicit conversion operators, but that would've made an even bigger mess...

void *x = malloc(sizeof(Boolean));
...

if(x) {
// this code is executed
}


>>9
== true is stupid because it leads to (x == true) == true and so forth.

Name: Anonymous 2016-10-02 11:13

Wrap your lips on these dubs

Name: Traction 2016-10-04 1:30

Name: Anonymous 2016-10-04 15:03

>>8
What's a NULL pointer?

Name: Anonymous 2016-10-04 17:04

>>8
That's more Lisp ``pornographic programming'' bullshit. Booleans are a separate type from pointers, lists, or integers. There are only two booleans.

Name: Anonymous 2016-10-04 17:27

>>14

You can have a False type, in the sense, that the type is inhabited. But if the type of nil was False, then nil cannot be. Then nil has to be nil.

Name: Anonymous 2016-10-04 18:41

>>15
You're still thinking like a ``pornographic programmer.'' The Boolean type has exactly two inhabitants.

Name: Anonymous 2016-10-04 19:59

>>16
What are you going to demand next, that we don't add strings with numbers? That 2 + "2" be considered invalid code and "0" == false not evaluate to truth value?!? You blasphemer!

>>14
But if the type of nil was False, then nil cannot be
You're not even making any sense.

Name: Anonymous 2016-10-06 9:50

var x = new Boolean("false");
if (x.valueOf()) {
// this code is not executed
}

RTFM

Name: Anonymous 2016-10-06 17:46

>>14
what about null? Ternary logic has more epistemic support

Name: Anonymous 2016-10-06 18:15

>>19
Null is like high impedance output. You can only have one active line driver on a bus if you want proper operation, so the others need to be in an off state.

Name: Anonymous 2016-10-06 20:59

>>17

False is uninhabited, so there are no objects living in the type false. It is like the empty set.

Name: Anonymous 2016-10-06 23:44

>>19-20
Null is not a Boolean value. It wouldn't be Boolean logic if there was Null.

Name: Anonymous 2016-10-07 0:00

>>22
I was talking about equivalence to logic circuits, dolt. Do you understand how you can have multiple signal drivers on a bus?

Name: Anonymous 2016-10-07 18:19

>>21
Oh, you must mean the Void type which is uninhabited. But that's not the problem here. The problem is to prevent a null value from inhabiting every fucking type. Because the way it's done in LITHP, there is a possibility of nil in every fucking value. You're writing a function? You've got to check every fucking argument to see if it's null. Your call tree has n levels? There will be n fucking nil checks for every fucking value because no function can be sure that the arguments it is called with are non-nil. The Common Lisp way is like being an amnesiac retard that checks and re-checks everything all the time because he can't remember what he has checked and what he hasn't.

That's why the null pointer was the billion-dollar mistake. The Right Way is of course to have a distinction at type level between things that might be null and things that are definitely not null.

Name: Anonymous 2016-10-08 7:24

Name: Anonymous 2016-10-08 7:50

>>25
;; empty dog class

(defclass dog () ())

;; a dog object makes a sound by barking: woof! is printed on standard output
;; when (make-sound x) is called, if x is an instance of the dog class.

(defmethod make-sound ((obj dog))
(format t "woof!~%"))

;; allow (make-sound nil) to work via specialization to null class.
;; innocuous empty body: nil makes no sound.
(defmethod make-sound ((obj null)))

Name: Anonymous 2016-10-08 15:41

>>25
"It's not a bug, it's a feature design pattern! Seriously!"

The null pointer was and is a billion dollar mistake that ruined among other things Common Lisp, Java and C#.

Name: Cudder !cXCudderUE 2016-10-08 16:16

>>25
ENTERPRISE QUALITY SCALABLE TURNKEY null SOLUTIONS

Since the child nodes may not exist, one must modify the procedure by adding non-existence or null checks[...]This however makes the procedure more complicated
What a strawman. They deliberately overcomplicate the function just so they can "simplify" it with some OOP bullshit.

This separates normal logic from special case handling, and makes the code easier to understand
Bullshit. It doesn't make the code "easier to understand" if you have to find where the hell that "special case" (which isn't really special, it's just the base case of the recursion) got separated out to.

int tree_size(struct treenode *n) {
return n ? 1 + tree_size(n->left) + tree_size(n->right) : 0;
}


Amusingly enough, counting the number of nodes in a binary tree is only 13 lines of x86 Asm and less than 30 bytes.

tree_size:
test eax, eax
jz tree_size_ret
push eax
mov eax, [eax+tree.left]
call tree_size
mov ecx, eax
pop eax
mov eax, [eax+tree.right]
call tree_size
lea eax, [eax+ecx+1]
tree_size_ret:
ret


>>27
Also bullshit.

Name: Anonymous 2016-10-08 21:57

>>28
hey, nice work

Name: Anonymous 2016-10-10 3:29

>>2
If it was, it would be collected

Name: Anonymous 2016-10-15 0:35

IRL in a dynamically typed language like JS there's no reason to use shitty wrapper objects like Boolean, String, Number. They're just bloat added to make the pure lean JavaScript language look like Java™.

Name: Anonymous 2016-10-15 1:27

Check dubs

Name: Anonymous 2016-10-15 1:30

Ignore dubs

Name: Anonymous 2016-10-15 14:20

>>33
Nice dubs!

Name: Anonymous 2016-10-15 15:42

>>28

Besides that, it also solves it the wrong way. Extending a type with a null object, means that your are adding null as subtype of that type. This wasn't what you wanted, because the problem with null is that it is unwillingly part of every type.

What you actually want is a type, which signals that a computation failed to produce output. This can be a type with two subtypes. One which holds a value and one, which don't:

type Optional a = None | Some a

map : forall a b. (a -> b) -> Optional a -> Optional b
map f (Some a) = Some (f a)
map f None = None


You can use map to lift a function into Optional, if you don't care about the existence of the value inside. Or unwrap it explicitly, if you do care.

Name: Anonymous 2016-10-15 16:37

>>28
Also bullshit.
Argument yourself. Have you read your TAPL today or is your bytefucking brain too small too understand the concept of types?

Name: Cudder !cXCudderUE 2016-10-16 11:22

>>35,36
...or is your academically-damaged brain too fucked to understand the concept of YOU CAN INTERPRET THE BITS HOWEVER YOU FUCKING WANT TO!?

Name: Anonymous 2016-10-16 20:38

>>37
Yes, you can interpret bits however you fucking want to. But there are very few ways to interpret them to achieve something useful. How many fucking ways are there to interpret a null pointer? What can a function do if it expects a pointer to an array and it gets a null pointer instead? It can only say "fuck, why doesn't this asshead Cudder use a type system that can prevent me having to deal with null pointers at runtime?"

Name: Anonymous 2016-10-16 21:00

>>38
Why would you expect a function to behave properly if given improper input? That's a sign of bad programming or bad input, it has nothing to do with a type system. That's like expecting strlen() to give valid results if you pass it a function pointer. Run-time type checking wouldn't fix that; most likely it would throw an exception, and unless you have special error-handling code, it will just end up crashing anyway.

Name: Anonymous 2016-10-17 14:31

>>39
Compile-time type checking however....

Don't change these.
Name: Email:
Entire Thread Thread List