/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1492913742983.jpg (700x700, 67K)

Other urls found in this thread:

open-std.org/jtc1/sc22/wg14/www/docs/n2021.htm
quora.com/Can-C -do-everything-that-C-can
jsfiddle.net/feadf/
twitter.com/SFWRedditVideos

>there are still C programmers

You guys do realize C++ came out like 40 years ago, right?

Attached: 1546973483824.jpg (1460x1029, 334K)

C++ a terrible language and is no way a replacement for C.
It doesn't follow the spirit of C at all.

Anyone who calls the language good would rather it had come out 2 years ago.
And that's why it's bad.

>It doesn't follow the spirit of C at all.
What do you mean by this? I'm genuinely curious

>just made a program to rip apart epubs and convert them chapter by chapter into markdown by basically just removing the tags in the XHTML pages and fucking with the newlines
>upload the results on a private repo on Github
>all because my Vita doesn't have an epub reader app without jailbreaking it
On one hand, I'm glad that I can do this with ease, but on the other, I sincerely wish I hadn't had to, for so many reasons.

It doesn't do the exact same things the hard way.

>>upload the results on a private repo on Github
Why not a public repo? Will you make money out of it?

Is it possible to translate binaries from one instruction set to another? I know the answer is probably no, but why not exactly?

>>Why not a public repo?
Because I don't want everyone else to know the shit I'm reading.
>>Will you make money out of it?
>making money
>from something intended for the Vita
user, I....

C++ cannot declare same-type pointers to be non-aliasing. C does it with the keyword "restrict" (restrict type qualifier), C++ compilers usually have non-portable ways to do the same, since it's a very important and irreplaceable language feature.

C++ cannot allocate an array of runtime bound on the stack, see Array declaration. There is a proposal to add that to C++, especially since many compilers support such arrays as a non-portable extension, but it's been failing for various reasons. The workaround is the non-standard alloca(), perhaps hidden in an allocator.

C++ cannot initialize a struct if the order of its members is not known, cannot initialize a union to non-first variant, and cannot selectively initialize array elements, since it does not have C's designated initializers - see Struct and union initialization and Array initialization (the workaround is to initialize everything and then assign each member that needs a non-zero value, which is annoying whenever I have to deal with C APIs)

I can think of a few others, which aren't that major, in my opinion:

C++ cannot form (and doesn't really need) anonymous objects with lvalue access, in C those are compound literals
C++ cannot select expressions based on the argument type. In C that is Generic selection -- C++ has overloading instead
C++ has no pure imaginary numbers (although few C compilers implemented pure imaginary numbers): Arithmetic types (and in general, C's approach to floating-point numbers is far more robust than C++'s in several important ways). C++ approach seems to use libraries.
C++ doesn't have flexible array members: a C struct can have an array of arbitrary length as its last element (Struct declaration), C++ doesn't really need that and it breaks the whole type-object-size relationship.
C++ formally does not support type punning for unrelated types (C does, through unions), but most compilers define it for C++ as an extension

Oh I thought you uploaded only the code for extracting the markdown and not the markdown files itself.

I have a problem like the following

let stuff1 = [[10, 'red'], [6, 'red], [4, 'red']];
let max = 0;

for(let i = 0; i < stuff1.length; i++){
if(stuff1[i][0] > max){
max = stuff1[i][0];
}
}


And the max keeps being 6, what is occuring here.

I did both, but yeah, it's mostly the markdown files.

The C standards committee actually has their own definition for the "spirit of C", which they adhere to when standardising the language: open-std.org/jtc1/sc22/wg14/www/docs/n2021.htm
It's just the commitee's opinion, but it gets the point across pretty well:
>(a) Trust the programmer.
>(b) Don't prevent the programmer from doing what needs to be done.
>(c) Keep the language small and simple.
>(d) Provide only one way to do an operation.
>(e) Make it fast, even if it is not guaranteed to be portable.
>(f) Make support for safety and security demonstrable

(f was added as justification for Annex K, which failed pretty hard)

Yes, at will keep being using 40 years more.

Stay mad.

F really stands out though. Safety is the last thing I think of when I think of C

newbie here
when working with pointers saying something like int *ptr is the same as saying int* ptr right

almost everything you identify here is c99 or c11 bloat that has no place in c

yeah

Yes. The argument people have about preferring one over the other is a code style preference. The meaning is the same.

I love lua!

Attached: lua-chan.png (1300x866, 1.04M)

aight thanks

No, they’re not the same; the first one is for retards

Theoretically possible, but nobody wants to because you would need to go full autism.

Here's the source user copied from.
quora.com/Can-C -do-everything-that-C-can
I'm pretty sure this is just bait. It's difficult to imagine someone defining "the spirit of C" as what C has over C++.

The former is correct, the latter is incorrect.

And Lua loves you, user!

$("#btn1").click(function(){
data[num] = [];
data[num].push($("#size").val());
data[num].push($("#color").val());
data[num].push($("#name").val());
data[num].push($("#colorLab").val());
num++;
$("#size").val("")
$("#name").val("")
return false;
});


data is being passed as a parameter within a function.

stuff1 is data

I’m ready

Make max into a car?

I don't know what language you're using, but it might be comparing your integers as strings. So "6" > "4" > "10" > "0" because the first character of "10" is "1". Perhaps cast them as integers in the comparison.

var* my bad I am phone posting.

Your second entry is missing an apostrophe. Other than that, it actually works on my computer.

>Make max into a car

Attached: 4dc[1].jpg (675x1376, 668K)

Assuming this is JS. I just ran your code in my browser and it works fine.
Your representation of the problem isn't representative or you've got some bug in your interpreter.

Attached: file.png (491x159, 10K)

int* p makes logical sense, it means you declare p to be a pointer to an int

int *p syntactically means you declare *p to be an int

user please be quiet. That's not how your side of the argument goes.

int * ptr masterrace here. Whitespace everywhere!

When I use typeof it's telling me the numbers are being evaluated as strings, I did create a new array that casted the numbers as strings and used that to find max.

But why are they being treated as strings.

is JS just shitty?

The data is being collected like this.

I should have included that.

Does .val() only return strings?

No, they're not the same at all. int *ptr is the correct way to do it, and int* ptr is just wrong. Your compiler should honestly call you a faggot, if you use the latter.

>is JS just shitty?
Yeah. Undeniably. I've heard people say that "it's not JS that's bad and gay, it's the fault of people not using it correctly" but fuck that noise: if a language is that easy to use incorrectly then it's a shit language.

>Does .val() only return strings?
Comparison operators should work just fine on javascript regardless. "12" < 13 will return true, and "12" > 13 will return false.

Try parseInt() to get around this javascript retardation.

I bet you also use int arr[] and not int[] arr

is this idiomatic rust?
fn main() {
let v = [(10, "red"), (6, "green"), (4, "blue")];
let (a, b) = v.iter().max_by(|(a, _), (b, _)| a.cmp(b)).expect("Item");
print!("{}, {}", a, b);
}

Of course I do. I bet you use i[arr] and not arr[i].

I am looking for CSS positioning practice.

Is there a website that shows a bunch of sample website layouts and basically says, recreate this.

I realize I could just try and replicate websites I use and use Chrome Dev Tools to hold my hand when I get stuck but I feel I need some smaller problems to deal with first.

Have been on CodeAcademy and Free Code Camp but I want something that's straight deep end CSS.

Try "10" > "8", it will return false.

He's probably getting ""10" > 0 (integer comparison), true. Max is "10" (stored as string). At this point all comparisons are string comparisons.
"6" > "10" true (because '6' > '1'), max is "6".
"4" > "6" false, max is still "6"

And that's programming related how exactly?

>CSS
Does anyone even use that anymore? There are far more powerful alternatives.

Good point.

I did for a secondary problem where a number was being returned as a stirng, the original problem I just put all the numbers into a new array.

Does .val() in jquery only return strings?

Please help a retard
Where does ‘buf2’ get the same content as buf1?
int main (void)
{
int fd[2];
char buf1[12] = "hello world";
char buf2[12];

// assume foobar.txt is already created
fd[0] = open("foobar.txt", O_RDWR);
fd[1] = open("foobar.txt", O_RDWR);

write(fd[0], buf1, strlen(buf1));
write(1, buf2, read(fd[1], buf2, 12));

close(fd[0]);
close(fd[1]);

return 0;
}
It’s an example demonstrating how to make write() write to FD 1 which should print “hello world” on the terminal
Am I missing something or is this just some sloppy Rajeesh code?

Attached: 45A5313E-373E-4513-97DB-7282772D7A97.png (312x390, 43K)

Just use parseInt like normal people.

I am trying to learn the basics before moving onto more advanced tools.

What are some examples. Flexbox / Canvas?

I'm talking about css extensions, like sass and less, not whole frameworks. But yeah, it's probably best to learn css first. Go to w3schools or something.

val() can return numbers from certain html elements. jsfiddle.net/feadf/

But honestly if you're not sure just try it out.

write(1, buf2, /*HERE -> */ read(fd[1], buf2, 12));

>mfw I just learned runtime recursion is so slow even the C++ compiler is faster
return fibonacci() + fibonacci(); will compile (and get the result) almost twice as fast as the running time of return fibonacci(n-1) + fibonacci(n-2);

Why do compsci books still use recursion for every algorithm then?

Your compiler can probably optimize recursion into loops, if you tell it to optimize. Other than that, yeah, recursion is pretty stupid from practical point of view.

This is the same CIA nigger shit as chaining together a bunch of strcats or something. What a fucking mistake to return the dest pointer.

Recursion is efficient for trees. And trees are the most important thing ever. Praise the trees

Loops are always more efficient than recursion. Trees are no different.

>return fibonacci() + fibonacci(); faster than return fibonacci(n-1) + fibonacci(n-2);
So we're saying the templated version is a loop while fibonacchi() is a recursive call?

You're certainly gonna feel the pain for doing so many calls when you've got such trivial work. And it's possible you wrote the latter in a way that eliminates TCO.
>why do textbooks still teach recursion?
It's a good tool to have. Some problems are easier to express this way.
It's also a rather basic thing in problem solving. So it's worth teaching in math at the very least.
>Recursion is efficient for trees.
In development time maybe.

The template is memoized

Attached: 1550525862817.jpg (597x700, 212K)

>Loops are always more efficient than recursion

Attached: 305126.jpg (225x350, 28K)

while( t->left != nullptr)
{
t = t->left
}

for (; t->left; t = t->left);

That’s strange, so foobar.txt is contained in both fd[0] and fd[1] so when you write to fd[0], you write to foobar.txt, and when you read from fd[1], you read from foobar.txt into buf2?

who is this

my brainlet neural system struggles with planning recursion:(

How many types of trees are there?

If iterative programming is so much better than recursion, write an iterative loop for inorder traversing of a BST

Attached: 1539442393785.jpg (850x800, 65K)

At least three

You should. Use a stack.

I’m currently a CS major, but I want to either CE or EE. What should I go with?

how much do you like electricity?

>What should I go with?
EE. Java EE.

ggVGd

I think it’s kinda neat

Dang, really?

CS master stuff... Mostly reading papers. Used kaggle to make a nearest median classifier. Still dont know how gradient descent and derivatives work.

lol, nerd!

Attached: 1548911335578.jpg (416x508, 67K)

dG

welcome to /dpt/

Attached: 1548474086653.png (500x492, 350K)

:c

zap

Attached: 56cab22f7b869.jpg (600x322, 259K)

Nice Yuki but who's the girl in OP

If you go down hill by the most steep direction you will reach the bottom. Whats so hard to understand?

Yuki's boyfriend from season 3

bizarro yuki

Attached: Spock.jpg (1024x765, 49K)

Lambdas were a mistake

you were a mistake

How come Callisto is never in the OP anymore?

Attached: d5a816e4fcbba3aad07fe9f4c95c5652.jpg (960x1200, 168K)

triphobia

I do understand the concept. In a convex problem minimization is the same as the derivative equal to 0. It is when the dimensionality is larger than 3d, then I struggle to understand it. The thingy I did for my course involved minimizing a loss function with l1 norms (absolute values). I got a weird result where adding the derivative worked. So I put a minus in front of it, but still I dont understand why this was so. I used the sign function as the derivative, e.g., (|3-x|)'=sign(3-x).

add a copy of SICP in her hand + a fez and make the next thread

What's so great about Sussman?
Is there really no one else?