/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

youtube.com/watch?v
stackoverflow.com/questions/16522341/pseudo-generics-in-c
twitter.com/SFWRedditImages

First for APL

How do I achieve mirror reflections in opengl?
do I really have to manually recreate the scene in the mirror but flipped and then crop out everything outside of the mirror with the stencil buffer?

give me a quick rundown on useful vim commands and features. this book is too long. all i ever really use is :wq and :q!

in python with matplotlib i want to make two lines from x to y and if they intersect somewhere to fill the area.

I found lots of fancy ways to use fill_between but i can't find a way to fill area between two simple lines that go from x,y

just use a matrix transform

Is there a point in """"mastering"""" C on my own after I get a grade on it in CS? Or should I just move on to other languages as soon as possible?

Move on, there's nothing to master.

mastering C is the first step to writing masterful C++.
or you could skip it and create embarrassing code for everyone to see

Just learn it. It's a small language. As long as you know what everything does you'll be set.

Voxel global illumination specular cone tracing.

but muh evil """raw""" pointers/"""raw""" arrays/any other C feature here

...

life is too short for vim, use nano

:%s/OP/faggot/g

thanks

Playing with Quake 3's source code.

Hello /dpt/ I am trying to learn c++ and I just don't understand the syntax behind dynamic memory allocation.

I think that new data type; asks for some memory of that type and you have to give it a pointer. But what I don't understand is when you use initialisation int *ptr1 = new int (5);

What even confuses me more is the syntax behind arrays.

int *arrayname = new int[meme];

Why do you use *arrayname instead of just arrayname?

You're receiving a pointer from the call to new.
Malloc does the same thing

Arrays are accessed with pointers.

*arrayname points to the first entry of the array
arrayname[0] goes to that pointer and retrieves the value
arrayname[2] increments the pointer by (2 * storage size in memory units) and retrieves the value

heap - memory where you have to coordinate with everyone else
stack - memory that only the function has the right to use
dereference - go into a pointer one level
address of - go up a pointer one level
so *&*&*&*&*&*&i = i
k&r has a good section on it, recommend
w - forward one word
b - back one word
dd - select line and delete (cut like ctrl x but into vim's buffer)
dw - delete word
p - paste below current line
P - paste above current line

You don't "learn" a language, that's a common misconception. The skills you learn in one language will transfer to another well. C is good in that you learn to do things the hard way, so you might learn "too much", which is better than using, say, Python and learning too little and then wonder why your program broke in some obscure (read: low level) way.

How would I go about confirming that user input is an integer? I use Java.

quit
exit
q
:quit
:q
:q!

Working on some /scala/ for machine learning. I still miss python :(

int number;

try
{
number = Integer.parseInt(string);
}
catch (NumberFormatException e)
{
System.err.println("Ya were supposed to input a number, ya dingus!");
}

cast it to int, if they're providing bad input better luck next time, don't do that

try {
int i = Integer.parseInt(someString);
} catch (NumberFormatException e) {
throw new StackOverflowError("get back to work pajeet");
}

That's not an exceptional situation.

scala bro
*non gay hug*

and your life isn't an acceptable situation. what do you want from us, user?

not programming, I'm trying to script a simple thing:

An alias for getmp3 that does:
youtube-dl -f bestaudio --extract-audio --audio-format mp3 --postprocessor-args "-threads 4" %1
Equals sign appears to be an argument separator, can I escape it somehow?
Example, link gets cut off:
youtube-dl -f bestaudio --extract-audio --audio-format mp3 --postprocessor-args "-threads 4" youtube.com/watch?v

Pattern.matches("[^\d]", string)

returns true if your string contains are non digit character

if you want to do the same thing for floats its more complicated dealing with the "."

what shell are you using?
and yes, you want to put the URL in quotes.

assuming bash, use single quotes if you dont need variable interpolation, double quotes otherwise

>using regexes instead of library functions desgined for the job
kys tbqh

your "solutions" explodes on the following (valid) inputs:
-1
+1
1e+3

C++ is disgusting

Why?

>A
>1.0
>-1

I wanna be a game dev guys

batch, cmd in windows 10
I've tried "%1"

it's the best I have

>batch, cmd
lol kys before it's too late. batch is the absolute worst, when it comes to anything really, but when it comes to quoting in particular.

learn powershell at least, learning batch is a waste of time

You need to call it like getmp3 "url"
this
t. wrote several moderately complicated programs in batch when i was a kid

Daily reminder that Rust can't handle anything more complex than immutable trees "safely" without performance degradation and extreme verbosity.

bloated, design by committee, oop is bad, can't compile it for shit, not even fast, has to trust the compiler (see before) to not produce memory leaks, and doesn't bring anything new to the table

reminder that behind able to statically check 90% of your code and having to flag 10% of it is better than having no static checking for any of it

>not even fast
>doesn't bring anything new to the table
meh

>it statically checks 90% of my fizzbuzz toys
And yet it can't handle anything more complex than immutable trees safely. I.e. it fails precisely when static checking could bring some actual benefits.

Your only argument for this so far comes from not understanding how borrowing works.

We can already do that with C external tools, there is no need to go on Mozilla's wild ride for it

>he unironically believes C++ brings anything new to the table
Name one new C++ feature that isn't a clumsy analogue of a feature that's been available in a bunch of other languages for decades.

Not an argument. Come back when you have some kind of defense against the fact that Rust fails at anything beyond immutable trees.

He's implying the opposite. That bringing something new to the table isn't a critical feature for a language, especially a system's language.

C doesn't have tuples, generics, lambdas, algebraic types, iterators, etc.

RAII and templates were good ideas

somewhat gimped in C++, but largely C++ innovations and quite useful

But then you could use C. My point is just that of the new "features" in C++, none of them are good, so you just end up using C with a worse compiler.

>He's implying the opposite
>that bringing something new to the table isn't a critical feature for
>a system's language
You're conveniently ignoring the other line. Surely, a language for system programming should be fast.

>But then you could use C.
I actually program in C for a living, and I will use C++ over C any day. STL containers alone is a reason to use C++ over C IMHO.

C isn't a programming language, not in the modern sense. C is a portable assembly language.

Those have nothing to do with static checking.
Why would it need any of those? They are trivial to implement in the form of libraries if you're desperate for them.

How do I properly scan a string for input in C?
I just need the first word but if I input two or more with space in between those words automatically read in for input. And even if I input ONE word it for some reason eats up first word from printf.

It is fast, but there are gotchas. C++ isn't a language for retards.

Which library adds generics to C?
Or ADTs for that matter.

Only because C++ is unreasonably complex. A better designed language could have been just as fast and expressive while also being consistent and free of unnecessary holes.

^f : forward 1 char
^b : backward 1 char
^n : next line
^p : previous line

M-f : forward to next word
M-b : backward to last word
^a : back to the start of the line
^e : forward to the end of the line

^x ^c : exit
^x ^s : write file
^x ^w : write file with new name
^x ^f : open new file

^x 3: split window horizontally
^x 2: split window vertically
^x 0 : merge active window
^x ^o : change active window
^x b : change active buffer
^x k : close buffer

M-w : copy
^w : cut
^y : paste
^ : set marker


M-x "term" : open terminal

>RAII and templates
RAII is a language crutch, and templates are poor man's parametric polymorphism.

>Only because C++ is unreasonably complex.
Blame backwards compatibility with C for this.

Ah, I forgot about

M-x "butterfly" : Best function ever

Point is, even if you use unsafe blocks and unchecked functions all over, you're still getting a lot out of the language. Don't forget modules as opposed to headers.

>C++ isn't a language for retards.
Then how do you explain the fact that every C++ programmer is a retard and all C++ code is abominable dogshit?

RAII is the most useful pattern for manual memory management and templates are far more efficient than full parametric polymorphism.

So you're saying the entire basis for the language was a mistake?

>templates are poor man's parametric polymorphism
Enjoy your extra indirection.

char* word;
char* s;
#define SPACE ' '
memcpy(word, s, (strchr(s, SPACE) - s));

>muh hot opinions
I'm not here to engage in shitposting, user. If you have technical issues, I'm more than happy to discuss with you, but arbitrary anecdotes and general flamewaring is not my style.

>So you're saying the entire basis for the language was a mistake?
Well, yes. This is a well-known fact and a widely acknowledged consensus among top C++ advocates such as Herb Sutters and Scott Meyers.

Generics are bad, but a quick google search reveals stackoverflow.com/questions/16522341/pseudo-generics-in-c for the truly insane man.

Glad we're in agreement then.

D isn't the answer, by the way.

>RAII is the most useful pattern for manual memory management
>manual memory management
It's a language crutch.

>templates are far more efficient than full parametric polymorphism
This doesn't change the fact that it's mostly just a dumbed-down and clumsy implementation of parametric polymorphism. There's nothing innovative about the concept.

>Glad we're in agreement then.
I don't think we are. C compatibility is holding C++ back, but idiomatic modern C++ is beautiful.

I thought speed was important?

Parametric polymorphism is just a language crutch anyway. You should just manipulate memory like real programmers do.

But there are static analysis tools for C which can spot a whole lot of vulnerabilities, we also have gcc hardened wrapper which has a mostly negligible performance impact and vastly improves the safety of the language.
>modules as opposed to headers
And why is this a good thing? So you can force rust's package manager down peoples' throats?

Who cares efficiency in a systems programming language right? Let's just add GC and millions of function pointers so you don't have to worry about deleting your objects and you can have that juicy parametric polymorphic.

Rust doesn't depend on Cargo at all.

Modern C++ is an endless pile of hacks. It's ugly as sin.

>If you have technical issues
I don't have "technical issues" because I don't use your sad joke of a language. C++ is a black hole that sucks you in and robs you of your time and productivity, but by the time you realize what a godawful language it is, it will have sucked so many hours out of your life that you'll find it psychologically hard to ditch it, and will probably become one of these delusional 40+ years old corporate project managers who eternally shill for C++ as the only option, even in the face of mounting evidence against it, simply because you lack the perspective that you could've gained from learning 10 other languages in the time it takes to memorize the necessary rituals to work around every one of the C++ design flaw.

Like python doesn't on pip, and node doesn't on npm?

As I said, I've worked with C++ as a language in the past and I work mainly with C these days, and I know what takes the longest time to get right.

That's your opinion. It's not an argument though.

Also, I learned C++ in 8 months. It's not hard when you know C in and out from before. I don't understand the meme that it's somehow impossible to learn C++.

yeah, Common Lisp really is the best language ever.

Describe all the different ways you can initialize an object, what the differences between them are and when any of them work.

Are you literally retarded? You can cry "muh efficiency" from here to eternity, but this doesn't change the fact that there's nothing "innovative" at all about templates, or the fact that RAII isn't a worthwhile feature outside the context of C++. C++ constantly tries to clumsily emulate features from other languages. No other language will ever need to emulate the "innovations" of C++.

An entire languages was created just to jerk off about how good C++ could have been. Templates being one of the major selling points of that language.

I can do that, but then you will make some angry post about how ridiculous it is that you can do it in 5 different ways and how it really just should be one. So I don't really feel like spending time posting something anyone can Google in less than two seconds (hint: there is a dedicated wikipedia article for this).

>being so proud of memorizing a thousand pages' worth of C++ design flaws and their workarounds
Shoving a cactus up your ass is also "hard". That doesn't mean that opting to do it showcases any merits.

>efficiency isn't innovative
No shit sherlock.

>RAII isn't worthwhile feature outside the context of C++
Literally all modern languages have a concept of scope, Java and C# copy the scope concept very much (C# even allow you to write custom destructors, thus supporting proper RAII).

Also, as said before. The point of C++ isn't to be innovative, it's supposed to be a type-safe alternative to C with modern programming concepts such as fucking generics.

I never said C++ was neat because it is somehow hard to learn. In fact, my post said the opposite, that C++ isn't hard to learn. Why are you arguing a strawman?

maybe dumb question but if i have an if statement with an OR operator, for efficiency should i always have the most common case as the first one? or does it not matter or differ for each language

You should rather rely on compiler magic intrinsics if branch prediction is that critical (see Linux kernel style likely vs unlikely macros). But I sincerely doubt that branch prediction is that important in your code, and if it is, you should try to work around it instead.

>people trying to replace C++ proves how good C++ is
>invoking rust as an argument
Are you okay?

>Templates being one of the major selling points
Nobody cares. There's nothing innovative about templates. By your logic, the C++ version of closures is also an "innovation".

>>invoking rust as an argument
D, dumbass. Since when were Generics a selling point of Rust?

it mean it's not, it's just a theoretical

>Since when were Generics a selling point of Rust?
>rust-lang.org
>Featuring
>trait-based generics