/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 5.png (1200x900, 824K)

Attached: flube.gif (460x405, 98K)

Rust is just

Lisp is the most powerful programming language.

JavaScript rocks!

Attached: js-rocks.png (1000x494, 286K)

Just found out that planning a project out before writing a single SLOC is a really bad idea.

Attached: Meido.png (600x800, 141K)

what is a good practice to read from a config file?
do I simply read line by line and then have a switch for all possible variables?

I'm very new to mathematica. I'm trying to play with financial functions I made for my stocks and dividends

what did I do wrong in mathematica that it's giving such an off-the-wall answer?

Attached: bbbbbbb.png (387x156, 7K)

(1395*(1+0.0659/4)**4)-1395 = 94.22738754692773

1395*(1+(0.0659/4)**4)-1395 = 0.00010277225851496041

notice the parentheses

JS quirk no 7:
[1,2,3,4,5,6][1,2,3] is equal to 4.

depends on the structure of the config file

>comma operator
Not too bad for an ecmashit quirk. C and C++ have the comma operator so you can do almost that as well.

C++20 has deprecated the use of the comma operator in an index operator.

>is equal to 4
why?

can't seem to figure this one out

I knew I had to have fucked something up with the parentheses. Thanks a lot

1,2,3 is equal to 3 (the last item in the list) and [1,2,3,4,5,6][3] is 4.

I'm getting calls from recruiters about C++ jobs and RTOS.

As I have no experience in this area, I'd like to get a project going and have some experience. Any suggestions? Bits of hardware I can utilise?

What has been deprecated exactly? The act of writing A[B, C]? The fact that it can be interpreted as A[{B; C}]? Some forms of overloading?

hint:
js> (1,2,3)
3

this
['10','10','10','10','10'].map(parseInt)
// output: [10, NaN, 2, 3, 4]

For good reason. It wants to introduce multi dimensional indexing

raspberry pi ?

The act of writing A[B,C]. Compilers are encouraged to warn you if you do it. It's expected that this syntax will be reclaimed at some later point for operator overloading with multiple arguments rather than an application of the comma operator.

Good to know. Thank you gentoomen.

Fuck, why didn't I think of that. But I need some project to work on it.

>don't read the documentation for the function you use
>act surprised when the function does what it's supposed to
Is there anything more low-brow than parroting popular JS inconsistencies that never appear in practice?

based apologist
console.log(typeof null);
// output: object

console.log(null instanceof Object);
// output: false

>never appear in practice
not sure 'bout that. And that's a nice way to dodge acknowledging the fact that Ecmashit is a pile of garbage.

that's what it should do you brainlet

you're not casting numbers, that's what Number() is for. parseInt converts the base of a number

>['10','10','10','10','10'].map(parseInt)
>parseInt(string, radix);
>Array.map(function callback(currentValue[, index[, array]]);

Gee wiz I wonder what went wrong. Oh right. You're a fucking idiot who doesn't know JavaScript OR functional programming.

hehehe
console.log(typeof NaN);
// output: number

console.log(NaN != NaN);
// output: true

console.log(NaN == NaN);
// output: false

console.log(NaN === NaN);
// output: false

>I'm your worst nightmare

Attached: Screenshot-from-2016-09-12-08-29-02.png (648x454, 72K)

>what are sane defaults

Can we stop talking about JS and talk about real programming languages instead?

A type system would have prevented this.

>The instanceof operator tests whether the prototype property of a constructor appears anywhere in the prototype chain of an object.
>null has no prototype
>acting confused

if your code ever does shit like this you already fucked up hard

however, if for whatever reason you need strict typing, use typescript

also, the fact that you think newer ecma is shit, reveals you're a pajeet at best

>sane defaults

what are you even on about

that's called typescript

Well, go on.

what's you favorite and what do you like about it?

Null IS a member of both the types "object" and the type "null". The typeof operator happens to return the first classification. Meanwhile instanceof refers to whether something is an object instantiated with the given constructor, null isn't instantiated with anything. First of all, if you're using OOP you're doing it wrong, secondly, if you can't work with !x && typeof x === "object" to check for nulls then you have a learning disability.

Because of those retarded nitpicks that all languages have? Hardly. If you stick to the functional parts of JS it's actually a very consistent and expressive language.

['10','10','10','10','10'].map(Number)
// output: [10, 10, 10, 10, 10]
ok retard

Would it really?
// there are two overloads:
Array#map(A => B): Array
Array#map((A, Int) => B): Array

// parseInt too has two overloads:
parseInt(String): Int
parseInt(String, Int): Int

Array("10", "10", "10", "10", "10", "10", "10", "10", "10").map(parseInt) // which one gets selected?

Every instance of unintuitive behaviour can be explained by describing the mechanics behind it. But that's irrelevant, the problem is that it's not intuitive in the first place. A PL should strive to be easy to understand and easy to predict the behaviour of.

one would expect parseInt to parse a string to number but ok

Is there a difference with ["10", "10", "10", "10", "10", "10"].map(x => +x) ?

In C#
1

My favorite is HTML because it lets me do pretty things

Also obviously forgot to mention x == null and x === null for null checking

Well did it not parse the strings to a number?
retard

That equality behavior is identical to C, so I don't see your point other than to point out the irony of NaN being typed as a Number. Gee, I guess they should have added another type just for NaN to prevent assholes from making fun of it. Except in C NaN is typed as float or double (aka a number...)

nice
just tested
> ["10", "10", "10", "10", "10", "10"].map(x => +x)
[ 10, 10, 10, 10, 10, 10 ]

no, because casting is different from parsing you idiot

parsing requires some form of algorithm that actually changes the value, while casting simply converts the value from one type into an other

>Well did it not parse the strings to a number?
>didn't saw the NaN

apply yourself

it does

One would not expect you to pass the array index to the radix parameter but ok

Not really, but Number is a builtin and it's more clear what you are doing, so using that is preferred.

Attached: 1 7qagwvx8Kwe2qPgD6FeJ-w.png (834x725, 43K)

weird flex but ok

NaN is a valid double value and doubles are numeric values.
retard

>NaN is a valid double value
make it stop plese

Overload resolution should just fail if there are multiple valid candidates. Like how (show . read) is disallowed in Haskell.

OK cool.

What's weirder tho is
js> Number(6) instanceof Number
false

['10','10','10','10','10'].map(n => parseInt(n))
// output: [10, 10, 10, 10, 10]

['10','10','10','10','10'].map(R.unary(parseInt))
// output: [10, 10, 10, 10, 10]


Oh look, it works when you don't make obvious mistakes.

Attached: maxresdefault[1].jpg (1280x720, 47K)

based ramda-bro

>replies after people have pointed out the mistake
wow

This. C++ should do this too, since it has a way of choosing when and how to hide overloads.

objects are objects, numbers are numbers

instanceof is used on objects with prototypes.

typeof(Number(6)) === "number"
true

Attached: cc.png (142x89, 2K)

Say you have a snippet of code that does something neat. But then you redesign your program to work in a different way. You refactor out the code, losing it forever. Would you save the code in case you need it at some other time?
Where do you save it?
Do you have a repository of random snippets?

#include
#include

int main() {
union N {
uint64_t y;
double x;
} N;
N.y = 0x7FF0000000000001ULL;
std::cout

You suck at programming

I'd just like to interject for a moment. NaN is a valid double, but not all valid doubles are numbers. Calling the double type the number type is straight up wrong.

have you heard of git?

this must be bait

and you suck my dick on Saturdays

I know but that's still a leaky abstraction. new Number isn't the same as Number, cause why not, and Number doesn't produce a Number but a number. Because the thing Ecmashit lacks the most is a primitive/boxed retarded distinction like it's statically-typed like Javagina or something. Fucking wew.

Ecmashit has a unified number type that's both int32 (well int53) and float64 at the same time. JAVASCRIPT-CHAN IS BEST GIRL

are you having a stroke?

A simple function call and an object construction with new have different semantics in literally every language.
retard

What does git have to do with saving random code that cannot be properly categorized?
I'm asking, if you save those snippets, how would you save them

>well int53
No, it's (u)int32 and double, but there is also bigint with its arbitrary precision.

My point stands.

JavaScript is the only language I know of where Number() and new Number() mean something different. Most languages pick one or the other.

I have a folder full of code snippets and small programs. I just write a Makefile to be sure that everything compile. And that folder use git.

It's called gist. It's part of git hub. Google is your friend (not really.)

>my function is called Number
>It's nothing to do with the adjacent class "Number" of course, are you mentally challenged bro? How did you not know? Despite the fact that there are a bunch of languages that use Class(...) with no new to instanciate Class

>A simple function call and an object construction with new have different semantics in literally every language.
no it doesn't, there are languages where object construction is done with a function call thats identical to a normal function call. Rust does this for example.

I used the wrong type, u32 overflows, u64 works.

Attached: 1533092704623.png (1920x225, 25K)

One is a function call, the other is an object construction. Guess which is which.
retard

No, it's just double. Crazily enough you can always just store integers in a floating point type. Who knew?

That's kinda semantics, but do you think Double is a subset of Number? In no particular language, just in general.

get over it

What the fuck are you on about? That's github, not git.

Double is a superset of Number

in C++

int myInt = int(42);
int myInt = new int(42);


Oh nos, it's confusing! Why can't everything just be Java or C#?

Explain this JS:
(![] + [])[+[]] + (![] + [])[+!+[]] + ([![]] + [][[]])[+!+[] + [+[]]] + (![] + [])[!+[] + !+[]];

returns the string 'fail'.

No. Neither is a subset of the other since there are doubles that are not numbers and numbers that cannot be represented as doubles. They do have an intersection of double representable numbers, though. I would call that intersection something like Real64, not even Number64 since there are obviously uses for complex numbers and so on.

N.B. IEEE floating point "infinities" just behave like large numbers so that's not an issue.

The problem is that you’re stupid and a shit programmer

Not really. It can represent signed 32bit ints and do bitwise operations on them, but outside of these bounds you go to floating point and bitwise operation forcibly cast to singed 32bit int. The actual representation is implementation-defined but the interface shows a duality.

the new operator is one of the most retarded parts of C++ though

I'm assuming he meant github, duh.

Are you genuinely confused or are you just being pedantic and argumentative?

>Explain this JS
Type coercion. Looking at the thread however that's too advanced of a concept for you to understand.

String indexing and concatenation.

>(![] + [])[+[]] + (![] + [])[+!+[]] + ([![]] + [][[]])[+!+[] + [+[]]] + (![] + [])[!+[] + !+[]];

It's an easter egg placed in the language by the the original author just in case anyone was ever stupid enough to type that.

Well then 1/3 is not a number. nice.

I basically agree. It's more of a Rational64, or FloatingPoint64 (well Float64, like in some newfangled languages)