[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 325
Thread images: 20

File: daily programming thread2.webm (2MB, 600x338px) Image search: [Google]
daily programming thread2.webm
2MB, 600x338px
old thread: >>57179300

What are you working on, /g/?
>>
Your mother.
>>
How do I make a django server?
>>
commies get out edition
>>
let's leave all the politics behind :)
>>
>>57184318
>tfw decltype(o.size())
>>
>>57184339

If anyone wants to still talk politics, it should be contained to the last thread, since it is on autosage and cannot be further derailed.

Alternatively, take it to the Discord chat.

>>57184329

Have you tried googling "django tutorial"?
>>
>>57184323
Nah. If I came to power as a dictator I'd start "annexing" a good deal of the private sector (by force), and use their equipment and personnel much better than they ever did. All I need is a small entry point to make everything else I don't want around more or less fizzle out on its own. Hopefully this would happen before we get to the point when they'll absorb parts of the police, or start building their own private armies. They must be a relatively soft target.

Take the biotech sector, for example. Their problem is less the exhaustion of low hanging fruits, and higher risk for subsequent development, but more artificial barriers that have to do with not destroying their existing markets and maximizing profits. The State does not have this problem. It only, ideally, needs to remain profitable. Its fruits naturally naturally benefit the public good.

The re-education might be deliberate, via using the media's hollowed out shell to start deploying content that gets people to think, and eliminating a lot of the marketing bullshit. Or indirect. I don't know. The media and their disingenuous spin would have to be controlled.

You don't even know the origin of your own discomfort. It's infantile and pathetic.
>>
Why is generic programming in C such a pain?

No, nonstandard GNU extensions and C11 _Generics don't count because that won't compile anywhere.
>>
How do I add each digit in an array of numbers?

eg: 1234 would be 1 + 2 + 3 + 4, in c++ please
>>
>>57184402

>C11 _Generics don't count because that won't compile anywhere.
Compiles on every platform I've used.
>>
>>57184417
For loop.
>>
>>57184395

What you're describing is fascism. You're Mussolini, except even more of a sanctimonious wiener.

How that's possible, we may never know.
>>
>>57184417
sprintf(...);
unsigned i, result = 0;
for (i = 0; i < strlen(buf); i++)
if (buf[i] >= '0' && buf[i] <= '9')
result += buf[i] - '0';
>>
>>57184417

Use integer division and modulo arithmetic to extract the individual digits.

1234 / 10 = 123
1234 % 10 = 4

I think you can see where this leads. Now go do your homework yourself.
>>
>>57184441
Gotta just do what works. The ends justify the means, both short and long term.
;^)
>>
>>57184417
>each digit in an array of numbers
what do you mean by this
>>
>>57184318
I made this cancerous webm that has plagued /dpt/ for so long.

Ask me anything.
>>
>>57184467
What made you want to watch a literal fetish anime?
>>
>>57184462

This is why the people have the right to keep and bear arms.

Might want to contemplate that before your PNF-style takeover.
>>
>>57184456
>unsigned
uh-oh
>>
>>57184467
>I wonder how many people watching this want to fuck me
lol
>>
>>57184476
What's wrong anon?
>>
Hello /dpt/ , learning C as my first programming language but I'm stuck on a simple question, how do I print an character array of size 6x6 which contains only '-' characters? Thank you
>>
>>57184494
A nested for loop 6 levels deep.
>>
>>57184471
I honestly don't know, I'm not even into traps.
It was pretty fucking shit though, i just kept watching it for the amusing subs.
>>
Rich and don't work your ass off to get smart and contribute to society? stay fucking poor.

Poor and don't work your ass off to get smart and contribute to society? stay fucking poor.

Encourage people to work their ass off and get smart and contribute to society, that is meritocracy.

Of course everyone must start at an equal line so there won't be any excuses for being a lazy scumbag of Earth. Which means the right to live at bare minimum, nutrition and health wise, and equal access to education.

Machines are advancing, that bare minimum can be possible for everyone. Whether they aren't allowed to enjoy life unless they study is another question.
>>
>>57184472
There would be nothing to rebel against. Maybe some people like you would take to the streets, but all you'd find is people going about their day. And you'd spend the rest of your life remembering that moment moment of wondering where the organized revolt was, and you would learn how people, and the world, really work.
>>
>>57184476

Right. Anon should be using size_t to match the return value of strlen. While size_t may be the same type as unsigned int on some platforms (such as i386-linux), this is not the same on others (such as x86_64-linux), and therefore, the problem fails when processing a 5 gigabyte string on 64-bit Linux. Anon should also not be calling strlen in the loop itself.
>>
>>57184517
How exactly do you end up with a 5gb string?
>>
>>57184517
>5 GB string
do you listen to yourself?
I told anon to convert an integer to a string.
There's absolutely no way this string could be larger than 64 bytes.
>>
>>57184515
Also, you'd be enjoying universal health care and no insurance game (forced on you by your employer, often) to drive up prices. I mean, there'd be an opt out added, taxes included, but no one would use it. Ultimately insurance companies in most regions would only be capable of existing in theory, but have no viability in practice (until the system degenerated for whatever reason).

Also, we wouldn't be heavily outsourcing for skilled labor. So yeah, you'd be complaining alright when you're getting medical care for an extremely low cost.
>>
>>57184534

Well Anon, I've still got a 1 GB .tar.gz file sitting around on my SSD that expands to a 14.2 GB folder containing a bunch of rather large CSV files containing some tagged data on a corpus of ancient sumerian texts. The largest of these files is 3.2 GB. It would not be difficult to imagine larger files, however.

Now let's imagine I wanted to load an entire one of these sons of bitches into memory.
>>
>>57184541

Now let's imagine we're working with arbitrary precision arithmetic...
>>
A:
uint8_t src[400];
uint8_t dest[400];
for (int i = 0; i < 400; i++)
dest[i] = src[i]


B:
uint32_t src[100];
uint32_t dest[100];
for (int i = 0; i < 100; i++)
dest[i] = src[i];


Would it be correct to say that B runs 4x faster than A or at least somewhat faster than A?
>>
>>57184515
>>57184597

I would sooner kill myself than live in your fantasy world.
>>
>>57184616
Not really, they're running at the same speed.
B just does less work.
>>
>>57184395
>If I came to power as a dictator I'd start "annexing" a good deal of the private sector (by force)
Dropped
>>
>>57184606
>Now let's imagine I wanted to load an entire one of these sons of bitches into memory.
In real life you would not do this.
You'd either process it line by line or chunk by chunk.

I meant it in a practical sense when I said how exactly would you end up with a 5gb string.
>>
>>57184618
Oh well, you're probably broken for life anyway. It'd make me miserable to be in charge, but I'd do it for the greater good. If you wanted to end your misery, then perhaps that's what should happen.
>>
>>57184631
>B just does less work.
Wouldn't that mean less instruction overhead and better pipeline use?
>>
>>57184660
Yes, because it literally does less work.

I'm not sure what point you're trying to make.
Execution time grows with the amount of work in a linear fashion.
>>
>>57184673
Yes, so B should complete 4x quicker than A should it not?
>>
>>57184685
I already answered that.
Go away.
>>
>>57184696
I will not.
>>
>>57184696
why you and I gotta write all this?
just a yes/no and boom done
>>
>>57184642
>you're probably broken for life anyway

That's an interesting way to look at things.

> It'd make me miserable to be in charge, but I'd do it for the greater good.

You'll likely live a happy life then, because you'll never be in charge of anything.
>>
>>57184616

Yes. It takes the exact same amount of time to load/store a word as it does a byte on most architectures. Since there are 4 times less loads/stores on B, it is a better way to do things.
>>
>>57184737
Interesting. how often do people take advantage of this? I think I see most people doing bytewise copies rather than wordwise copies.
>>
>>57184729
>because you'll never be in charge of anything.
100% slavery is mechanically impossible.

But you're probably right. I tend to just make certain I'm independent, and detach. It's very difficult to stage a takeover that isn't spectacle based anyway, and you necessarily have to do a lot of bullshitting and infighting. Very few ways around that.
>>
>>57184752
It's called writing multi-threaded code.
If you're too lazy to do that, modern CPUs will do it for you within the same core with out of order execution, but this only goes so far.
>>
>>57184781
Are you replying to the right post? this has nothing to do at all with what I was talking about.
>>
>>57184606
File streaming was literally invented for this use-case

>>57184752
When doing large byte copies people usually use memcpy() or memmove(), or the compiler turns their gigantic shitty inefficient for loop into a memcpy().
Point is that every C programmer worth a damn knows and uses memcpy()
>>
>>57184752

You ever used memcpy or memset? Optimized implementations of these will not copy/set memory one byte at a time, but using blocks of 4 or 8 bytes as often as possible. Consider this: http://lxr.free-electrons.com/source/arch/x86/lib/memcpy_64.S
>>
My self-organizing map- function now uses Rocchio clustering to get starting points.
It's slow but I think I can make it faster.

I should print it red. red goes faster.
>>
>>57184898
>red goes faster.

fact
>>
>>57184494
Go to the /g/ wiki and download and read literally any of the C books. Legit chapter 2 shit anon.
>>
>>57184873
>>
>>57184954
Which book are you reading? I wanted to learn Scheme, but seriously SICP is a big meme and Edwin is a joke.
>>
File: rong.jpg (74KB, 720x960px) Image search: [Google]
rong.jpg
74KB, 720x960px
>>57184984
>SICP is a big meme
what's rong with it
>>
>>57184898
>>57184905
#include <stdio.h>
#include <time.h>
FILE* log_file;
void benchmark (const char* name, void (*fn)(void)) {
clock_t t0 = clock();
for (int i = 0; i < 100000; i++)
fn();
clock_t t1 = clock();
fprintf(log_file, "finished '%s' in: %.2fs\n",
name, (double) (t1 - t0) / CLOCKS_PER_SEC);
}

void test_red () { printf("\x1b[31;1mRED\x1b[0m "); }
void test_green () { printf("\x1b[32;1mGREEN\x1b[0m "); }
void test_blue () { printf("\x1b[34;1mBLUE\x1b[0m "); }

int main (void) {
log_file = fopen("log.txt", "w");
benchmark("red", test_red);
benchmark("green", test_green);
benchmark("blue", test_blue);
fclose(log_file);
return 0;
}


$ gcc the_ultimate_test.c -std=c99 -O2 && ./a.out && cat log.txt
finished 'red' in: 0.12s
finished 'green' in: 0.17s
finished 'blue' in: 0.14s


You guys really are right... red is faster
>>
>>57184984
read some book by david touretzky
pretty good, assumes you've never programmed before
but you can do practical common lisp, which is what most anons would recommend
>>
>>57185065
If you add a white racing stripe it'll go even faster
>>
>>57185065
kek
>>
File: 1418673922875.png (125KB, 318x368px) Image search: [Google]
1418673922875.png
125KB, 318x368px
I was using clock() to measure execution time, but on some platforms, (specifically VPSes), clock() always returns 0.

Is there a foolproof portable way to measure execution time in C?
>>
>>57184402
Many people who stick with pure C end up creating metaprogramming frameworks to deal with stuff like that.
>>
>>57185065

You are not printing the same amount of characters.
>>
>>57184984
Racket, which is what Scheme became, has a lot of tutorial stuff in it's IDE on how to learn the language.
>>
>>57185123
There isn't a foolproof way to do anything in C. There are possible exceptions in just about every corner of the standard.
And people applaud the language for that...
>>
>>57185175
C is basically a language full of functions that throw but without try catch blocks
>>
>>57185142
$ less do_not_underestimate_the_red.c
...
void test_red () { printf("\x1b[31;1mRED..\x1b[0m "); }
void test_green () { printf("\x1b[32;1mGREEN\x1b[0m "); }
void test_blue () { printf("\x1b[34;1mBLUE.\x1b[0m "); }
...

$ gcc do_not_underestimate_the_red.c -std=c99 -O2 && ./a.out && cat log.txt
finished 'red' in: 0.73s
finished 'green' in: 0.76s
finished 'blue' in: 0.96s
>>
>>57185123
Depends on the architecture anon and if this is for benchmarking or not.
RTDSC is what you want for Intel 32 and 64 ones if that's the case: http://www.intel.com/content/dam/www/public/us/en/documents/white-papers/ia-32-ia-64-benchmark-code-execution-paper.pdf
>>
>>57185175
People applaud the language for running on a lot of stuff, being fast and not falling to a lot of the more retarded language hype that came later on. (of which C++ fell for almost everything)
>>
>>57185063
Read it, and you will notice.
>>57185066
>>57185167
Kay, ty for the options, I've also considered Clojure from some FP memers. In the future gonna try one of these.
>>
>>57185123
Probably having a specific call which is implemented differently for each platform would be my guess?

Handmade Hero deals a bit with it in this episode iirc: https://hero.handmade.network/episode/win32-platform/day010
>>
>>57185184

It's from a different time, lad. It evokes a particular programming style -- as the great John Daly once said, "grip it and rip it!"
>>
File: 1460612894768.png (658KB, 966x710px) Image search: [Google]
1460612894768.png
658KB, 966x710px
>tfw no C++ Without Classes
>>
>>57185247
It's also so popular since it's easy to make a compiler for it. Your optimizations don't have to be very good, since c is low level enough you can self optimize.
>>
>>57185269
So I have to include inline asm?
>>
>>57185296
That would be fucking retarded and shit.
C++ is pretty much built on and around classes. C++ would not be C++ without it.
>>
>>57185296
But there is C++ without classes?
Just write C code in C++ using structs and what not.
>>
File: 1470284474790.jpg (186KB, 743x743px) Image search: [Google]
1470284474790.jpg
186KB, 743x743px
>>57185310
>That would be fucking retarded and shit.
>C++ is pretty much built on and around classes. C++ would not be C++ without it.
>he hasn't heard of Modern C++, More Modern C++ or Modern Effective C++ or More Effective C++ or More Modern Effective C++
>>
GUI for byzantine
>>
related to the topic at hand: today's botnet rewrites a lot of standard library functions because you can't count on their presence

https://github.com/0x27/linux.mirai/blob/master/mirai/bot/util.c
>>
>>57185299
>since c is low level enough you can self optimize
On an interesting side note, if you made a C++ implementation that was fully unoptimized, it would actually be slow as shit.
>>
>>57185321
>C++ using structs
Anon..
I'm sorry to break this to you, but C++ structs are just public classes.

>>57185322
You literally cannot use 99% of C++ without using a class.
If you do, you're actually just using C.
>>
>>57185373
>You literally cannot use 99% of C++ without using a class.
>If you do, you're actually just using C
I hope you don't actually believe this, or at least aren't dumb enough to think that a struct with a different name counts as a class
>>
>>57185402
structs in C++ are literally classes that are public by default rather than private.
You're retarded if you think otherwise.
>>
>>57185402
>>57185373
>>57185322
>>57185321
>>57185310
I knew this would devolve into a terminology war...

Yes, in C++, the following are ***EXACTLY*** equivalent:
struct Foo {
<pub members>
private:
<priv members>
};

class Foo {
public:
<pub members>
private:
<priv members>
};


You could code in a style where you don't define any methods, and pretend that your structs are C structs.
However this would literally just be limiting yourself for no reason. If you want real functional/"purely procedural" programming then rm /usr/bin/g++.
>>
>>57185416
A class by definition has methods
>>
>>57185434
And C++ structs can have methods, since they are literally just public-by-default classes.
Your fucking point?
>>
>>57185449
Well a struct with methods is technically a class, but a struct without methods is not.
>>
>>57185434
>>57185460
>>57185449
Fucking get over yourselves, you're pointlessly bickering on 4chan about terminology.
Just code however makes you happy, or however your employer/codebase expects.
>>
/dpt/, where people that barely know anything argue with people that know just as little as they do
>>
>>57185433
>limiting yourself for no reason
Nobody wants your shitty OOP bullshit, stop peddling it
>>
What should I read to learn more about instruction set architectures?
I don't understand why one would be more efficient over another.
>>
Tensorflow AI guy from the last thread.

Adding crossed columns increased accuracy by 1-2%, so I'm now up to a still shit 56%.
>>
>>57185486
Constructors and destructors are useful, even (especially) when implicitly generated.
Methods are a viable alternative to excessive overloading.
Methods can make code easier to understand.
Every single C++ library in existence uses methods, even if they don't go down the OOP rabbit hole. OOP is more than just methods attached to classes, even though that is a big part of it.
Stop being a purist asshole and just realize that some features can be useful and you should consider using them. The entire point of 'modern C++' is to be exceptionally multi-paradigm.
>>
>>57185373
>>57185416
>>57185449
Classes have reference semantics, structs have value semantics
Classes have an infinite lifetime, structs don't
Classes can be inherited, structs can't
It's nowhere near as simple as your retarded "public-by-default classes" definition
>>
reminder of RAII
>>
>>57185525
>Constructors and destructors are useful
They needn't be methods.
C++ could just as easily have done

std::construct<T> ...
std:: destruct<T> ...


Hell, they could do it now and just have it automatically work for existing constructors/destructors
>>
>>57185506
it's true, it's only the decoding of the instructions and the processor architecture that makes a difference, for example ARM has fixed length instructions vs x86 which makes address calculation and decoding faster
>>
>>57185506
Mang, you should read Inside the Machine by Jon Stokes, I barely remember the facts of why some platforms were better to the other, but it's easy to grasp (I remember pipeline bubbles, opcodes, and all that shit).
Tho, that book only talks about RISC and CISC. Pretty high level desu, but very enlightening.
>>
>>57185532
We're talking about C++ here, not C# you fucking tard.
>>
>>57184318
is there a gcc extension that allows for multiple definitions for one function as a form of branching through the compiler instead of instructions? for example, allowing the compiler to use these two functions to determine if a number is less than 4 instead of the CPU at run-time with if statements
int function(int x < 4) {
return 1;
}
int function(int x >= 4) {
return 0;
}

if not, does anyone know what language I might be thinking of?
>>
>>57185532
Are we talking about the same language?
'struct' and 'class' are literally exactly the same keyword except for one begins member declarations to be public, the other private.
C++ structs can have reference semantics. C++ classes can have value semantics.
C++ has no concept of lifetimes.
C++ structs can be inherited.

>>57185555
Like most widespread languages, they didn't get it completely right the first time but they inevitably figured out the "right thing". Unfortunately we suffer a bit from this but it's harder to recreate from the ground up than to slowly accumulate features.
>>
>>57185577
Haskell maybe? I once wrote a language that worked like that, I'd share the github but I don't want to put my identity on 4chin
>>
>>57185577
the alternative being
int function(int x) {
if ( x < 4) return 1;
return 0;
}

the use-case for this would be to avoid extra comparisons in an already tedious subroutine with millions of calls to it
>>
>>57185578
They got it completely wrong the first time, and have only occasionally been adding good things from other languages

Modern C++ involves none of the original C++
>>
>>57185598
would that language happen to be implemented in go?
>>
>>57185617
No, it was C++. Then I tried to bootstrap it but it was kind of a shit language overall.
>>
>>57185577
Haskell:

function x | x < 4  = 1
| x >= 4 = 0

notb True = False
notb False = True
>>
>C++ language design
>"hey let's redefine null for no appreciable benefit"
>>
>>57185777
>C++ language design
>Hey lets introduce references that can't be null and can't be changed later!
>>
>>57185577
>>57185598
>>57185644
after doing some more searching with "pattern matching function declaration" I found ocaml, javascript, scala, and now I'm thinking it may have been a lisp
I don't think it was haskell based on the code alone, I remember it being more c-like
>>
im studying strings and stacks in c.pretty cool
>>
>>57184402
Why is generic programming such a pain?

No, languages other than C don't count because that won't compile anywhere.
>>
>>57185322
Thank you Emilia-tan.
>>
>>57184389
>Discord
Since when do we use discord?
>>
>>57186081

For a while now, actually. It's just only recently that we've had people actually using it.

https://discord.gg/ekAQ3
>>
>>57186081
since the guberment agents started shilling it
>>
I'm a NEET programmer, how do I make money fast?
Android? Freelance? I have no idea how the "adult world" works
>>
all the lisping i've done is inside clisp
and I know cl is compiled

so how do I do shit, is there a main subroutine like in c or what?
>>
>Download music torrent from TPB
>Notice odd little file in it
>REBOOT.FOLLOW
>Inside of folder, two files
>MetroFramework.dll
>REBOOT.FOLLOW.exe
>WTF is this bullshit?
>Open in hex editor
>It's a .NET program
>Find this string:
>"I created this simple program in hopes to simplify following my uploads."
>"I am currently in development of a program to allow full-blown simplified searching / downloading on KAT, but this is to be done in the future."
>"For now, this is my form of communication to the public."

What is the point of making such a program?
>>
>>57186360
Making a bot.net
>>
        if (!gender.equals("M") || !gender.equals("F"))
{
throw new ParseError("Gender must be either M or F");
}


This is for an assignment. Would they accept this?
>>
File: WTF.png (155KB, 1488x800px) Image search: [Google]
WTF.png
155KB, 1488x800px
In all seriousness though, does anyone know of good tools for decompiling .NET shit? I'm bored and would like to see what the hell this thing does.
>>
>>57186410
Enjoy getting expelled after your SJW teacher gives you an F and you complain to the head of department and the dean.
>>
>>57186416
>porter robinson

as expected from a brony
>>
>>57186410
>gender = "m";
>"Gender must be either M or F"
???
>>
>>57186410
>Not accommodating non-binary gender identity
You're done for, Anon.
>>
>>57186431
What the fuck do you listen to?
>>
>>57186416
Well Jetbrains tend to be good so I assume dotPeek should be decent.
>>
>>57186410
Gender should be a float from -1 to 1. -1 representing masculine, 1 representing feminine.
>>
>>57186449
lately?
hierophant green, breakbot, falcom sound team jdk, perfume, serani poji, yann tomita
>>
>>57186471
</thread>
>>
>>57186471
>not complex, to account for imaginary genders
>>
>>57186416
>Ubuntu
No wonder why you stick to a language worse than Java.
>>
>>57186410
>.equals
I hope they don't accept this language
>>
>>57186498
It's required to be in Java. I fucking hate working in this shit, It makes me suicidal every time it forces me to handle an exception.
>>
>>57186510
just write your own strcmp, dummy
>>
>>57186496

Which one would that be, Ruby, C, or C++?
>>
>>57186523
but strcmp is even shittier.
C++/C# == for string comparison is superior.
>>
>>57186525
C++ is even more retarded than Java actually
>>
>>57186531
>overloaded == operator
WHAT THE FUCK
>>
>>57186548
>I'm too stupid to grasp operator overloading
Your C compile overloads operators for different builtin data types anyway, may as well allow user defined overloads too.
>>
>he can't create his own operators
>>
>>57186554
What is simplicity
>>
>>57186531
> C++ strings aren't null terminated even though it's missing cousins with C
Wew
>>
>>57186480
Do you like Grimes?
>>
>>57186554
That's because those overloads make sense.
What doesn't make sense is comparing 2 strings with a == operator.
In C, if ("str1" == "str2") is a comparison between 2 readonly char * pointers, which are variables, and not objects.
>>
>>57186568
str1 == str2

this is simplicity

>>57186570
They are, because of C's mistake
They also count length
>>
>>57186568
What is abstraction?

Wait dw, of course a Cfag wouldn't know what abstraction is.
>>
>>57184467
sauce?
>>
>>57186582
It makes perfect sense
>>
>>57186535

You seem to have a high opinion of Java.
>>
>>57186583
I looked it up for this very shit post. C++ strings are not null terminated.
>>
>>57186582
>That's because those overloads make sense.
No they don't.
10.0 == 10 should treat 10.0 as an integer because that's what they are under the hood anyway.

See, I can play this game too. Ctards just can't into abstraction.
>>
>>57186587
Boku no hime
>>
>>57186600
str.c_str()
>>
>>57186604
Having to cast every fucking comparison like that would be annoying.
>>
>>57186596
I don't. But at least, Java makes sense with itself in its bullshit. C++ forced backward compatibility with C and failed miserably.
>>
>>57186600
As of recently*
They used to be, INTERNALLY.
string::c_str() still returns a null terminated char pointer
>>
>>57186600

C++ std::strings are not required to be null terminated. However, the result of c_str() has to be null terminated, so it is quite often for implementations of std::string to be null terminated so as to not have to copy to a new buffer every time c_str() is called.
>>
learning lisp was a mistake
>>
File: bully_waifu2x_art_noise3_tta_1.png (275KB, 460x1321px) Image search: [Google]
bully_waifu2x_art_noise3_tta_1.png
275KB, 460x1321px
>>57184467
Thank you for doing this. I love traps.
>>
>>57186619

Despite its wonkiness, C++ is still more pleasant to program in compared to Java.
>>
>>57186659
This. And I fucking hate C++ sometimes.
I have more of a tsundere relationship with C++.
>>
>>57186568
>appeal to simplicity
what did he mean by this?
>>
>>57186659
>>57186676
Definitely Stockholm syndrome.
>>
>>57186682
>>this language makes me want to kill yourself
>appeal to emotion

no idea
>>
>>57186692

Maybe. It was my first programming language.
>>
File: FizzBuzz.png (13KB, 578x461px) Image search: [Google]
FizzBuzz.png
13KB, 578x461px
>>57186700
Mine was MSWLogo
>>
>>57186692
There is no alternative.
>>
>>57185577
Elixir:
defmodule Anon do
def func(n) when n < 4 do
IO.puts "less than four"
end

def func(n) when n >= 4 do
IO.puts "greater or equal to four"
end
end

Anon.func 3
Anon.func 5
>>
>>57185577
C++17:
constexpr unsigned x = 2;
int function()
{
constexpr if (x < 4) {
} else {
}
}
>>
>>57186773
No.
>>
>>57186777
Yes.
>>
>>57186783
How do I call that function with the number 4?
>>
>>57186773
>constexpr if
Man, C++ just keeps surprising me with features I never knew about.
>>
>>57186786
template <int n>
int function()
{
constexpr if (n < 4) {
return 1;
}

return 0;
}

function<3>();
function<5>();
>>
>>57186803
Ok, now do it at runtime without recompiling
>>
>>57186810
The initial question was asking about compile time and not runtime.
>>
>>57186820
No it wasn't.
>>
>>57186810
It's fundamentally not possible with the way you want it done.

Either settle for compile time or deal with the runtime overhead.
>>
>>57186824
> allowing the compiler to use these two functions to determine if a number is less than 4 instead of the CPU at run-time with if statements
>>
File: 1475572773555.jpg (29KB, 398x356px) Image search: [Google]
1475572773555.jpg
29KB, 398x356px
> needing to resort back to c character arrays to have a bounded strings in c++
>>
>>57184417
C#
        int[] myArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int kek, result = 0;

for (kek = 0; kek < myArray.Length - 1;kek++) {
result += myArray[kek];
Console.WriteLine(result);
}
>>
>>57186831
Yes, but presumably you would also like to be able to actually call that function, at runtime, as well.
>>
>>57186836
You can call it at runtime - just not using a runtime variable.
>>
>>57186833
> -1
>>
>>57186839
>You can, you just can't!
Nice try dumbass, what a stupid fucking joke

Your solution doesn't even do what he wants.
He specifically asked for seperate function declarations.
>>
>>57186833
D:
void main(string[] args)
{
import std.algorithm;
import std.stdio: writeln;

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
.sum
.writeln;
}
>>
>>57186833
>>57186848
MASSIVE KEKS

Remove the -1
>>
Has anyone used Codewars.com for drilling in general practices?
Is it any good?
>>
Which books can I read to I learn some computer science principals that are essential for programming?
What are some good books for programming concepts in general?
>>
>>57186870
in Haskell this is just
main = print $ sum [0..9]
>>
>>57186883
Here (You) go:

http://www.introprogramming.info/english-intro-csharp-book/
>>
>>57185577
constexpr int function(int i)
{
return i < 4;
}
>>
>>57186897
Yeah in D you could technically also do:
>iota(0, 9).sum.writeln;

But the main/import boilerplate is here to stay. You can also use from..to to generate a range but IIRC it can only be used within foreach statement.
>>
>>57186925
FP is GOAT but languages like D are trying to tread the line
>>
>>57186870
>GC
I wonder if they cry themselves to sleep over this lapse of judgement. Must have sounded like a good idea too at that time with Java and C# having GC.
>>
>>57186953
D language theme song
https://www.youtube.com/watch?v=nOL0ll2cLGk
>>
fucking hate all this stupid ass terms like "lexical scoping" or "rvalues"
>>
>>57186985
I once heard that the average American only uses 500 different words.
>>
>>57186985
What's wrong with them?
>>
>>57186985
fuck words
>>
>>57186985
Same. But they aren't without utility, so I suggest you work passed the initial investment, learn them, and learn to think more precisely.

Adopt a disgusting level of labels and categorical thinking.
>>
>>57186991
The French only use about 10
>>
>>57187002
"I surrender
"Please do not hurt me
"Take my wife
>>
>>57187002
>>57187010
I'm french and this is accurate
>>
Google or AWS or OVH?
>>
>>57187024
oh shit i forgot "le"
>>
>>57187043
le what?
>>
>>57187040
/dpt/ or >>>/g/wdg or reddit?
>>
File: ama.webm (2MB, 1280x720px) Image search: [Google]
ama.webm
2MB, 1280x720px
/dpt/-chan, daisuki~

>>57186985
>philistine

>>57186883
structure and interpretation of computer programs / how to design programs
concepts, techniques, and models of computer programming (has chapters on concurrency and distributed programming contrary to sicp and htdp)
lambda calculus for dummies
programming languages: application and interpretation
object oriented programming languages: application and interpretation
SOLID principles
read uncle bob (clean code), martin fowler (design patterns), kent beck (design patterns, tdd)

>>57186352
isn't the main procedure implicit?

>>57186310
https://www.upwork.com/

>>57185569
cisc and risc is now an obsolete terminology.

>>57185506
Computer systems: a programmer's perspective is an accessible introduction to the subject.

>>57185346
>no itof nor strtod
Amateurs.

>>57185065
>Buffered IO

>>57184616
Depends the architecture. On intel, the answer is no.

>>57184494
    for (int i = 0; i < 6*6; ++i)
{
putchar(a[i]);
if (i!=0&&i%6==5)
putchar('\n');
}


>>57184417
In doubt, always use OOP.
#include <iostream>

using namespace std;

struct IndexableInteger {;
const int number;
IndexableInteger (const int number) : number{number} {}

int operator[] (size_t index) {
int n = number;

while (index--)
n /= 10;

return n % 10;
}

size_t length () {
int n = number;
size_t l = 1;
while(n/=10) ++l;
return l;
}
};

int main(void)
{
IndexableInteger ii{12345};
cout << ii.number << " = ";
int total = 0;
for (int i = 0; i < ii.length(); ++i)
{
cout << ii[i];
if (i+1 < ii.length())
cout << " + ";
total += ii[i];
}
cout << " = " << total << endl;
}


>>57184402
>nonstandard GNU extensions
Both GCC and Clang do support GNU C.

>>57184402
>Why is generic programming in C such a pain?
C is one of the worst programming languages PLT wise.

>>57184318
Thank your for using an anime webm.
>>
>>57187053
Fuck off
>>
https://www.youtube.com/watch?v=8C8NnE1Dg4A

I'm getting wet.
>>
>>57187053
I love you, Ruby-ちゃん.
>>
>>57187052
Explain how "Google" is /dpt/
>>
>>57187053
>webm
I need to know context.
>>
>>57187053
>Depends the architecture. On intel, the answer is no.

>intel
>architecture

??
>>
>>57187081
https://en.wikipedia.org/wiki/Microarchitecture
>>
>>57187096
Probably should edit your previous post to say microarchitecture then.
>>
>>57187104
>r/eddit
>>
File: ano.jpg (250KB, 1200x1350px) Image search: [Google]
ano.jpg
250KB, 1200x1350px
>>57187104
pic
>>
```
#include <iostream>

class Loli
{
// :-)
}
```
>>
>>57187069
Lol, that's not me, Anon.

>>57187053
Your operator[] is O(log10 n), but could be O(1).
>>
<code>
#include <iostream>
</code>
>>
#include
>>
i--i'm going outside. - wish me good luck
>>
#include <iosteam>
>>
>>57187185
don't do it
>>
>>57187185
>>57187197
I'd consider going outside, but it's almost 3 AM and I don't feel like putting on a shirt.
>>
>>57187185
DO NOT FUCKING DO IT ANON

trust me


if you do, then good luck m8
>>
>>57186985
AGILE

SCRUM
>>
>>57186985
TRIVIALLY CONSTRUCTABLE
>>
Use a PrOxY or your IP will be know!!!
>>
This probably profoundly idiotic BUT can you read in any file in C/C++ byte by byte without an external libraries? Messing around with some silly encryption idea and wanted to try video and was curious if I could do it without any extra shit
>>
>>57187298
>without an external libraries
do you count stl
>>
>>57187298
syscalls
>>
>>57187298
I don't even.
>>
>>57187251
MONADIC
>>
>>57187298

http://en.cppreference.com/w/c/io/fread
>>
>>57187357
PHI
>>
Can anyone post one of those lists with programming tasks you can roll for? Thanks.
>>
>>57187406
0: Write a C++ compiler

Roll modulo 1
>>
>>57184417
int a = 1234;
int sum = 0;
while(a){
sum += a%10;
a /= 10;
}
>>
>>57187443
import os
os.system('g++ ' + input())


Uses g++ as a backend :^)
>>
>>57187474
Breathed audibly through my nose.
>>
>>57187406
Become a C compiler.
>>
File: richard stallman.jpg (903KB, 1366x768px) Image search: [Google]
richard stallman.jpg
903KB, 1366x768px
>>57187499
Your autism is appreciated here at /dpt/.
>>
>>57187474

>as a backend
And a frontend.
>>
>>57187474
// Lambdas at it's best!!!

template<typename T>
void sortShit(std::vector<T>& v) {
std::for_each(v.begin(), v.end(), [v](auto& cur) {
std::for_each(v.rend(), v::iterator(&cur), [cur](auto& b){
if(b < cur) {
std::swap(b, cur);
return b;
}
});
});
}
>>
somebody post the discord invite link please
>>
>>57186416
A in that font looks like a dick.
>>
This might be retarded but how stupid it is to try to learn two languages at once as a beginner?
I dabbled with Python a tiny bit and gave up because I'm lazy and have no discipline. I also read sometimes on /g/ that I will hurt myself if I start with high level like Python? Am I getting memed? I intent to learn something low level anyway, so I'm just asking if it's fine to learn Python first and then C?
Also I think C will benefit me after I learn Python since Python is written in C and I can read how a language is made.
>>
>>57187890
Forget Python. Just learn C.
>>
>>57187899
You mean assembly.
>>
>>57187839
https://discord.gg/24huy

>>57187857
It's secretly a dick emoji.
>>
>>57184673
>Execution time grows with the amount of work in a linear fashion.
assuming no outside influences like cache misses, synchronization overhead, etc.
>>
>>57188004
Got a new one?
>>
So, in XCB, why do all the examples copy the depth from the parent (XCB_COPY_FROM_PARENT), but use the visual from screen->root_visual. Since the parent is screen->root anyway, aren't these the same thing? Why the fuck aren't they consistent?
>>
>>57188004
Why the fuck do you keep using links that time out in 5 minutes?
>>
I'm learning to program solely by programming small challenges and searching in MSDN for features I didn't know, how bad is this?
>>
>>57188553
>MSDN
very bad
>>
>>57188553
>how bad is this?
Not.
>>
>>57188553
what language?
>>
>>57188553
You're learning, and that's good.
>>
Can anyone help me tell why this is happening?

I want to do directional light, so I have a single vector for the light source, in this example (1, 1, 1). But instead of every object getting the same light and dark parts, it behaves kinda like a point light source.

attribute vec3 aVertexPosition;
attribute vec3 aNormalVector;
uniform mat4 uModelView;
uniform mat4 uPerspective;
uniform mat4 uScaling;
uniform mat4 uTranslation;
uniform mat4 uRotation;
uniform vec3 uLightSource;
varying vec4 vColor;

void main(void) {
vec4 wSpacePosition = uScaling * uTranslation * uRotation * vec4(aVertexPosition, 1.0);
vec4 wNormVector = uRotation * vec4(aNormalVector, 1.0);
float light = max(0.0, dot(normalize(uLightSource), normalize(wNormVector.xyz)));
vColor = vec4(light * 0.8, light * 0.3, 0.05 - light, 0.0);
gl_Position = uPerspective * uModelView * wSpacePosition;
}


Here's the vertex shader. Can anyone see what I did wrong? uScaling, rotation and translation are unique to each rendered object. I apply the rotation matrix to the normal vectors, and then get the dot product of the light source and the rotated normal vectors. Shouldn't that be independent of the actual position of the object?
>>
File: whythough.png (32KB, 1567x574px) Image search: [Google]
whythough.png
32KB, 1567x574px
>>57188661
Forgot the damn picture
>>
>>57188626
t.Remove(r);

or
t.remove(r);

?
>>
>>57188676
it looks correct, just that the perspective is fooling you. like compare the colors of the bottom two triangles on each object
>>
>>57188626
I don't C++ but what's even going on here. You have a Remove (capital R) that takes 1 argument, and you're calling a remove (uncapitalized r) that takes 2 arguments.
>>
>>57188661
Lighting should be done in fragment shader. You get better quality. More importantly, you aren't rotating your normal vector correctly.
>>
>>57188701
But that's the problem, it should be directional lighting, which means they should all look exactly the same. But for some reason the light and dark parts are rotated or something.
>>
>>57188677
>>57188706
Yeah I realized I forgot to capitalize the r. Took way too long to realized for a stupid mistake.

It's a recursive function. I have an overloaded one with two arguments and that's being called where I forgot to capitalize the r.
>>
>>57188713
I want flat shading, I like how it looks. How do I rotate the normal vector right? What did I do wrong?
>>
>>57188661
Take this with a grain of salt, because I don't know the library you are using, but those few I used have had a light source assigned a vector per default a point light source.
>>
File: 1-point-perspective-city.jpg (38KB, 630x414px) Image search: [Google]
1-point-perspective-city.jpg
38KB, 630x414px
>>57188715
the COLORS are consistent because the LIGHTING is directional. the objects look "rotated" because of PERSPECTIVE.
>>
>>57188725
I don't use any library except for the actual webgl, so there are no light sources until I make them.
>>
>>57188722
See the discussion here: http://learnopengl.com/#!Lighting/Basic-Lighting (look at section One Last Thing)
>>
>>57188734
Well fuck me that actually sounds right. What do I have to do to make it look right?
>>
>>57188734
All the little mistakes in that picture trigger my OCD badly.
>>
>>57188746
maybe you want orthographic projection
>>
Can someone link me to beginners tutorials for coding?

It doesn't particularly matter which language, just want some very thorough tutorials that would be able to walk me through actually learning how to code in some language, if I had to suggest some I'd probably say C#, Javascript, Java, Python, Ruby/Rails.

I just want to learn it myself at home.
>>
File: isthatwrong.png (29KB, 1553x469px) Image search: [Google]
isthatwrong.png
29KB, 1553x469px
I don't even know if I can trust my eyes anymore...

Is that right? Would it look like that in the real world when sunlight shines on 3 objects? I just don't know anymore.
>>
>>57188871
google: [language] tutorial
https://wiki.installgentoo.com/index.php/Main_Page
https://www.reddit.com/r/learnprogramming/wiki/index
>>
>>57188909
I mean, I understand that the projection matrix to get it all into normalized coordinates would show more of the right side on the left ball, and more of the left side of the right ball, thus making one look darker than the other, but would it look like that in real life?
>>
>>57188913
Thanks, I was only asking in case anyone had some suggestions that they considered far above any other/most tutorials.
>>
>>57188922
C: the programming language, second edition
>>
>>57188871
https://docs.oracle.com/javase/tutorial/
>>
>>57188920
it depends on the field of view and how far away you're standing, for example if you stand in the middle of two objects it will be different compared to if you stand far away from them
>>
>https://www.tutorialspoint.com/about/about_team.htm

lol
>>
File: furtheraway.png (7KB, 504x213px) Image search: [Google]
furtheraway.png
7KB, 504x213px
>>57188949
Hmm, it does seem right when I move the camera further away.
>>
File: 1474317323238.png (1MB, 1280x720px) Image search: [Google]
1474317323238.png
1MB, 1280x720px
>>57188004
>>57187839
I took a nap and it expired
>>
>>57188949
also in first person games it's common to have a much wider field of view than what would correspond to reality because otherwise it would be like having tunnel vision if you could only see "through" your pc monitor or the tv
>>
>>57188952
shitskin ad infinitum
>>
>>57188952
Poo in code
>>
File: subhumans-shall-praise.png (323KB, 609x761px) Image search: [Google]
subhumans-shall-praise.png
323KB, 609x761px
# Relevant words in /wdg/
job, event, uhhnnnnfff, youtube, discover, look, open, source, modules, stateful, instead, plain, track, rails, ruby, path, depend, guides, eventually, apis, list, comfort, guide, choose, web, dev, approaching, vps, hosting, suppose, endless, western, choices, claims, setting, man, php, switch, divs
# Relevant words in /dpt/
we, result, less, wanted, amount, probably, methods, runtime, must, functions, once, without, retarded, book, talking, level, main, number, hate, live, made, program, total, high, java, wonder, public, low, point, return, such, extra, technically, barely, initial, cat, different, which, definition, love

Obviously /wdg/ is smarter.
>>
>>57189021
>no "monad"
Your algorithm doesn't work
>>
>>57189030
The "algorithm" is just:
(count_in_dpt - count_in_wdg) / count_in_both
>>
>>57189051
I still don't see any monads
>>
Beginner question

int *Array1;
Array1=(int*)malloc(Length1*sizeof(int));

What does (int*) do?
>>
>>57189314
cast the void* return from malloc to int*
>>
>>57189367
thanks m8
>>
>>57189021
looks like we actually post code
>>
>>57189314
in c you could probablty drop it
>>
Is there any good guide to xcb?
All I've found is "hello world" examples and auto generated api docs.
>>
was about to ask a question but answered it myself

what are you doing on such a nice day, guys ?
>>
>>57184616
SIMD instruction, exakt same ns
>>
>>57189021
>/dtp/: love
>/wdg/: divs
/dpt/ is kawaii as fuck.
>>
>>57189755
Also, we use the word "we" more often. Proof of our strong relationship. :^)
>>
Do you guys think Codecademy is decent for learning?
>>
File: 1471144078970.jpg (90KB, 563x675px) Image search: [Google]
1471144078970.jpg
90KB, 563x675px
>>57189021
>we must love
>we must live
>we must cat
>>
>>57189924
no
>>
>>57190003
what pronouns do you prefer people use when addressing you
>>
>>57190020
I'm a cute and conservative Japanese girl. And there are only two genders.
>>
>>57190006
Why?
>>
>>57190035
it's far too trivial and disorganized, and it doesn't introduce some meta things which are fundamental before you start programming

like using the terminal to run your code for example
>>
Does anyone know why after adding constraints to a button in xcode 7, the button doesn't work anymore?
>>
New thread: >>57190109
>>
>>57190063
Is there any other website you'd recommend that has a similar style? Where you "start a course" and teaches you via doing actual work, all in one place?
>>
>>57190063
>using the terminal
>not using an IDE
lol linux neckbeards
>>
>>57190163
Retard.
Thread posts: 325
Thread images: 20


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.