[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: 313
Thread images: 42

File: 1481654229907.jpg (264KB, 1440x1080px) Image search: [Google]
1481654229907.jpg
264KB, 1440x1080px
What are you working on, /g/?

Old thread: >>61939273
>>
>>61946558
>>61946568
so much for muh portability
>>
File: penginkr.png (65KB, 369x350px) Image search: [Google]
penginkr.png
65KB, 369x350px
original penguin please steel
>>
Is this true?

>>>/v/387401257
>>
>>61946738
Nope.
>>
>>61946735
why is that book backwards? the cover is on the back.
does it symbolize how backward linux and the cult of c are?

really makes you think.
>>
>>61946744
>>>/v/387401646
>>
>>61946757
I'd just like to interject for a moment. What you’re referring to as Penguin, is in fact, Japanese anime penguin, or as I’ve recently taken to calling it, Nippon penguino.

Japanese read backwards.
>>
>>61946777
Enable collaboration.
>>
>>61946738

"small shell scripts" is about the last place you'd want to be using C. This is stupid.
>>
http://igoro.com/archive/gallery-of-processor-cache-effects/
This was a very good read. I recommend it to newbies.
>>
File: rknignep.png (64KB, 369x350px) Image search: [Google]
rknignep.png
64KB, 369x350px
Specially for pedantic anon
>>61946757
>>
can I still make money as a programmer if I live in a shitty rural area?
>>
>>61946777
>it's easier to write a C compiler than a C++ one
>every language on this earth can use C libraries
>>
File: pepe_HQ.jpg (41KB, 640x633px) Image search: [Google]
pepe_HQ.jpg
41KB, 640x633px
>>61946823
>making money as a programmer

How are you gonna undercut Pajeets writing code for $2/hr?
>>
>>61946840
>>it's easier to write a C compiler than a C++ one
That's irrelevant if you just want to use the language. It only matters if you're compiling for some extraordinarily obscure architecture.
>>every language on this earth can use C libraries
extern "C"
>>
>>61946823
sure. ask local businesses to replace their shared excel and access files with a solid software.
>>
>>61946862
In Ukraine 2$/hr is a decent job.
>>
>tfw /v/ knows more about programming than /dpt/
>>
>>61946876
>extern "C"
>have to make sure you capture every exception it might throw
>can only export valid C prototype
At that point you might as well be programming in C.
>>
>>61946906
Just because the interface is C doesn't mean the implementation can't benefit from C++ features.
Even Microsofts C library is implemented in C++, lmao.
>>
>>61946906
How do you expect to achieve C ABI compatibility except by exporting symbols that are C functions?
The point is that you can write whatever you like in the body of the code, but the interface remains portable.
>>
>>61946934
you're clearly not webscale enough to know the future of abi compability is not with c, but with wasm.
>>
>>61946925
>>61946934
Do you not realize that interfaces are pretty much the essence of programming styles?
Once you extern C you've committed the user of your library to either write some boilerplate to have them write something other than C in their interactions with your code. And on your library side your entire interface must boil down to C code. It's a very large constraint.
>>
>>61947009
>And on your library side your entire interface must boil down to C code
Yeah and? it's just the interface, which is a tiny part of your library.
It's not hard to efficiently translate between C and C++.
>>
>>61946862
dumb frogposter
>>
>>61947025
>it's just the interface
That's what people who write bad interfaces often say. The interface is a major guiding factor in developing a library.
>>
>>61947052
or.. you could provide a flat api. (incomplete example because its highly dependent on if you use pimpl and opaque pointers, and what the "target" language will be, if you need to extern "C" or not.

// include/foobar.h
#ifndef __cplusplus
#include "flat/foobar.h"
#endif

#ifdef __cplusplus
#include "detail/foobar.hpp"
#endif
>>
>>61947111
This is a great way to make people dislike your library. People tend to assume that one of these are an afterthought. Any flaw will be attributed to that. If someone doesn't like your dialect of C++ they will assume the C++ api is secondary to the C api. And you quickly gain the reputation for only supporting C. But go ahead. It's an attempt at a solution. If people ended up leaning that way you probably didn't lose much.
>>
I'm trying to debug my program but I get random shit at the end of it.
int main(int argc, char *argv[])
{
int a[] = {5, 2, 4, 7, 1, 3, 2, 6};
size_t isize = sizeof(a) / sizeof(a[0]);
size_t i;

for (i = 0; i < isize; i++)
printf("%d, ", a[i]);
printf("\n");
fflush(stdout);

insort(a, isize, sizeof(a[0]), icmp);

for (i = 0; i < isize; i++)
printf("%d, ", a[i]);
printf("\n");
fflush(stdout);

return 0;
}

This is the random shit.
(array)
(sorted array), -794678248, 32766, 1, 0, 4196800, 0, -308193232, 32692, 0, 0, -794678248, 32766, 0, 1, 4196464, 0, 0, 0, 1190345096, 492821133, 4195760, 0, -794678256, 32766, 0, 0, 0, 0, 66271624, -492668087, -89966200, -499777201, 0, 0, 0, 0, 0, 0, 1, 0, 4196464, 0, 4196912, 0, 0, 0, 0, 0, 4195760, 0, -794678256, 32766, 0, 0, 4195801, 0, -794678264, 32766, 28, 0, 1, 0, -794672176, 32766, 0, 0, -794672164, 32766, -794672153, 32766, -794672136, 32766, -794672114, 32766, -794672020, 32766, -794672000, 32766, -794671984, 32766, -794671961, 32766, -794671944, 32766, -794671909, 32766, -794671877, 32766, -794671859, .... etc.

I'm not sure how the code prints more than I told it to.
>>
>>61947189
Maybe insort overwrites too much of the array and corrupts the stack (the stack is where isize and i are).
>>
>>61947189
You don't need to flush after printf a \n
What is insort?
>>
>>61947212
I don't think so since isize has the correct value after insort and i is initialized to 0.
>>
Is this true?

>>>/v/387403049
>>
>>61947224
Are you sure? Also, what is icmp?
>>
>>61946541
Informatics
>>
>>61947233
icmp is just a simple comparison function. The whole code is here. I'm still trying to debug the insort function to work correctly.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void insort(void *base, size_t n, size_t size, int (cmp)(const void *, const void *))
{
void *tmp = malloc(size);
char *b = base;
int i, j;

for (i = 1; i < n; i++) {
memcpy(tmp, b + (i * size), size);
for (j = i - 1; j >= 0 && cmp(b + (j * size), tmp) > 0; j--)
memcpy(b + ((j + 1) * size), b + (j * size), size);
memcpy(b + (j * size), tmp, size);
}
free(tmp);
}

int icmp(const void *p1, const void *p2)
{
int v1 = *(int *) p1;
int v2 = *(int *) p2;

if (v1 < v2)
return -1;
else if (v1 == v2)
return 0;
else
return 1;
}

int main(int argc, char *argv[])
{
int a[] = {5, 2, 4, 7, 1, 3, 2, 6};
size_t isize = sizeof(a) / sizeof(a[0]);
size_t i;

for (i = 0; i < isize; i++)
printf("%d, ", a[i]);
printf("\n");
fflush(stdout);

insort(a, isize, sizeof(a[0]), icmp);

for (i = 0; i < isize; i++)
printf("%d, ", a[i]);
printf("\n");
fflush(stdout);

return 0;
}
>>
Does anyone have experience with linux / ROS?
I am making an application that gathers all the separate parts into a single application.
I am launching the applications using the linux API similar to
http://www.microhowto.info/howto/capture_the_output_of_a_child_process_in_c.html
and then basically redirect all stdout and stderr to a string which I then can grep on to see if a program is ready or dead (aside from just see if it is running).
But ROS output is different somehow as I don't get the same output in a terminal as I get in my own application (I don't get any output).
It works fine when I take a simple program like ping, but either it is because ros spawns different programs itself or it is because ROS output is not being logged.
Anyone have an idea to where to start debugging this?
>>
>>61947137
Well, when everything uses the cpp/hpp extension except the flat/*.h they'll be dumb to assume its not C++. As for C and other FFI, it is secondary :^), only a convenience for them.

But you're right, providing a FFI interface for C++ is rather annoying. All the solutions for doing a non C-ABI "object model" have turned out to be ass cancer. COM, D-bus, CORBA, KParts, SOM, XPCOM, etc.

One solution would continue to be an island (only providing a C++ interface). Another laughable one would be to require any "clients" to use the C++ name mangling conventions, C++ function call conventions and the C++ vtable (and maybe deal with multi-inheritance w.r.t to the vtable).

Or to not use "C++ as C++" but rather extern "C" everywhere.
>>
File: 1502386263119.png (152KB, 600x729px) Image search: [Google]
1502386263119.png
152KB, 600x729px
>>61946869
>>61946925
Sh..shut your mouth. I love C.
>>
Is C11 the best choice if you want to write a fast game 2D/3D game engine and port it to:

>Linux/Mac/Windows (already there)
>Android
>iOS
>PlayStation
>XBox
>handheld gaming consoles
>wasm
>>
>>61947276
>>61946869
samefag
>>
File: 1500728546323.jpg (299KB, 1400x1400px) Image search: [Google]
1500728546323.jpg
299KB, 1400x1400px
>>61946541
Writing a universe simulation. Currently a small intelligent form of life called the Cromuloids have sprouted in the Omega system. It's cute to see them try to walk on the land.
>>
>>61947301
Shill lord, you guessed wrong.
>>
>>61947308
post link to source or webm demo
>>
>>61947251
Use j+1 in your last memcpy
>>
>fatal error C1060: compiler is out of heap space
this is best part of compiling c++ with msvc
lets see your gcc run through 32GB+ compiling code :^)
>>
File: ljfs.png (146KB, 500x375px) Image search: [Google]
ljfs.png
146KB, 500x375px
>>61947320
>>
>>61947308
How are you building It?
>>
>>61947348
language/frameworks/libraries/work_environment/project_duration?
>>
>>61947348
How come that's a screenshot of spore?
>>
>>61947326
Ah, thanks that worked. Do you know why it was fucking up and adding all the extra crap?
>>
File: sljfs.png (139KB, 450x197px) Image search: [Google]
sljfs.png
139KB, 450x197px
>>61947408
what no!
>>
>>61947426
>anon accidentally recreates spore
Shame. You're now in copyright violation. Go directly to jail.
>>
>>61947435
At least it isnt a loli kidnapping simulator
>>
>>61947446
You can groom and kill children in spore
>>
My latest javascript framework that nobody asked for and nobody needs. I call it C-biscuit :3
>>
>>61947227
I have read some game engines source code and they all seem to reimplement their own allocators and containers at least.
Not sure if there's any point in that because they have never published benchmarks of their own implementations vs the STL containers.
>>
File: concentratedautism.jpg (764KB, 608x3248px) Image search: [Google]
concentratedautism.jpg
764KB, 608x3248px
>>61947449
get informed newfag
>>
>>61947426
Can you actually make it good this time?
>>
>>61947297
gnu11 or at least the parts that are also supported in clang.
>>
>>>/v/387404534

Really?
>>
>>61947446
No that would be fine but don't mess with EA.
>>
>>61947473
I know what that is you fucking faggot, now what does that have to do with what I said?
>>
File: anime_stare.jpg (354KB, 1920x1080px) Image search: [Google]
anime_stare.jpg
354KB, 1920x1080px
Do you consider this me readable than this >>61947251
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void insort(void *base, size_t n, size_t size, int (cmp)(const void *, const void *))
{
void *tmp = malloc(size);
char *b = base;
int i, j;

for (i = size; i < n * size; i += size) {
memcpy(tmp, b + i, size);
for (j = i - size; j >= 0 && cmp(b + j, tmp) > 0; j -= size)
memcpy(b + j + size, b + j, size);
memcpy(b + j + size, tmp, size);
}
free(tmp);
}

int icmp(const void *p1, const void *p2)
{
int v1 = *(int *) p1;
int v2 = *(int *) p2;

if (v1 < v2)
return -1;
else if (v1 == v2)
return 0;
else
return 1;
}

int main(int argc, char *argv[])
{
int a[] = {5, 2, 4, 7, 1, 3, 2, 6};
size_t isize = sizeof(a) / sizeof(a[0]);
size_t i;

for (i = 0; i < isize; i++)
printf("%d, ", a[i]);
printf("\n");
fflush(stdout);


insort(a, isize, sizeof(a[0]), icmp);


for (i = 0; i < isize; i++)
printf("%d, ", a[i]);
printf("\n");
fflush(stdout);

return 0;
}
>>
>>61947499
Your comment makes you seem like a retarded kike who isn't aware of anything.
>>
>>61947422
You were corrupting the value stored before the array. Probably isize.
>>
File: dpt programming advice.png (6KB, 433x91px) Image search: [Google]
dpt programming advice.png
6KB, 433x91px
>>61947518
Oh, so you're a newfag on his first road trip out of /pol/, you probably saw those /dpt/ posts on r/4chan
>>
>>61947510
Or is this more readable?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define pos(index, size) ((index) * (size))

void insort(void *base, size_t n, size_t size, int (cmp)(const void *, const void *))
{
void *tmp = malloc(size);
char *b = base;
int i, j;

for (i = 1; i < n; i++) {
memcpy(tmp, b + pos(i, size), size);
for (j = i - 1; j >= 0 && cmp(b + (j * size), tmp) > 0; j--)
memcpy(b + pos(j + 1, size), b + pos(j, size), size);
memcpy(b + pos(j, size), tmp, size);
}
free(tmp);
}

int icmp(const void *p1, const void *p2)
{
int v1 = *(int *) p1;
int v2 = *(int *) p2;

if (v1 < v2)
return -1;
else if (v1 == v2)
return 0;
else
return 1;
}

int main(int argc, char *argv[])
{
int a[] = {5, 2, 4, 7, 1, 3, 2, 6};
size_t isize = sizeof(a) / sizeof(a[0]);
size_t i;

for (i = 0; i < isize; i++)
printf("%d, ", a[i]);
printf("\n");
fflush(stdout);

insort(a, isize, sizeof(a[0]), icmp);

for (i = 0; i < isize; i++)
printf("%d, ", a[i]);
printf("\n");
fflush(stdout);

return 0;
}


>>61947536
That seems weird because I was checking isize outside the function and it was the correct size, plus wouldn't isize in the function be a copy?
>>
>>61947552
I was there anon, including all the times he's resurfaced to show progress.
>>
>>61947555
How did you check it? Do you use gdb?
>>
>>61947572
I printed it out with printf in main after the insort function.
>>
>>61947601
Maybe it's am optimization and the compiler inline the value of isize. Look at the assembly code anon.
>>
File: nico_nico_nee.gif (735KB, 500x280px) Image search: [Google]
nico_nico_nee.gif
735KB, 500x280px
>>61947620
I don't think clang would optimize it since I didn't explicitly specify any optimization flags. I guess I'll have to look at the assembly. Thanks.
>>
>>61947635
Why do you use clang?
>>
>>61947647
I like it because the error messages are better.
>>
>>61947662
No comments.
>>
File: have you ever had sex.jpg (31KB, 680x383px) Image search: [Google]
have you ever had sex.jpg
31KB, 680x383px
>>61946541
C = Computer plumbing
Lisp = Computer science

Agree?
>>
>>61947673
C++ = industry, money and bitches.

Agree.
>>
Is this a bad practice?
int& returnByReference()
{
static int x = 5; // static ensures x isn't destroyed when it goes out of scope
return x;
}

int main()
{
int value = returnByReference(); // case A -- ok, treated as return by value
const int &cref = returnByValue();
}
>>
>>61947673
Python and Java are probably more popular in the field of CS than either of those
>>
>>61947688
ignore case A
>>
>>61947688
Getting a reference to a temporary is generally a bad idea unless you're doing stuff with move semantics. But I don't know what you're doing, this is a contextless example.
>>
>>61947691
Because they've finally cribbed all the features Lisp pioneered.
>>
>>61947672
before gcc 6 (and 5 desu), gcc (g++ mostly) had absolutely shitty errors. here's an approx line number. then clang showed that you can also have a column, and then even point to the identifier / binding thats the actual compile error.
then clang showed that errors messages could be actually helpful.
static int foo (int a, int b) { return a + b; }
int bar (int a) { return foo (a (4 + 1) * 2); }
// gcc
foo.c:2:33: error: called object 'a' is not a function or function pointer
foo.c:2:1: error: too few arguments to function 'foo'

// clang
foo.c:2:33: error: called object type 'int' is not a function or function pointer

then with gcc 6 they copied a lot from clang. and then with gcc 7 they copied the actual informative errors.

..and then with msvc 2017 they added in the "caret" dianostics from clang 2 / gcc 5
whats wrong with that?
>>
>>61947688
It seems useless. What are you trying to accomplish here?
>>
Here's the functionof converting into base-60 in some made up BASIC dialect.
STRING FUNCTION TO60 (INT A)
INT POS, MULT, ANEW, I
STRING RESULT

POS = 0
MULT = 1
RESULT = ""

WHILE (A < POS)
POS++
MULT *= 60
END WHILE

POS--
MULT /= 60

WHILE (POS != 0)
ANEW = A / MULT
RESULT = RESULT + ANEW

FOR I = POS DOWNTO 0
RESULT = RESULT + "'"
NEXT

A -= ANEW * 60
POS--
MULT /= 60
END WHILE

RESULT = RESULT + A + "°"

END FUNCTION
>>
>tfw to much of a brainlet too write haskell in practice
>>
>>61947688
make it return "const int &" so no one tries to fuck with it. it's generally an OK practice if you deal with large structs that are too cumbersome to copy to pass them by value.

I guess it's a simplified example but I'm not too sure about what a good optimizing compiler could do here. Like storing x in a read only memory page. So you really want to prevent any changes to that. (const it)
>>
>>61947842
Do a tiny module at a time, lad.
>>
>>61947691
more popular. but way less fun.
>>
>>61947842
>haskell
>practice
chose one m8
>>
>>61947856
Python is very fun for me. Much more fun that C. Together they work quite fine.
>>
>>61946541
Isn't the user passing a void to the function? Why is it being read as a ' '?
>>
>>61946823
yes. work for yourself and sell your software on the internet. every retard can earn at least $2000 a month with some shitty shareware. if you're in a rural area $2k is enough to live off.

work for 3 months, then spend the rest of the year shitposting on 4chink. repeat every year. the good life.
>>
>>61946925
does MSVC support C99 yet?
>>
>>61947875
yes, python can be very fun. if you've got a chromosome too many.
>>
>>61947906
default parameter
>>
>>61947927
>resorts to name calling
Enjoy your dead useless language, I guess.
>>
>>61947946
>oh no, I accidentally put a \t instead of 2 spaces. now my program's behavior is undefined. if I'm lucky it will error out.
t.pythonfag
>>
How true is this?

>>>/v/387406805
>>
>>61947959
Are you shilling C++ to /v/? That's the most retarded way to kill your time
>>
>>61947959
OOP is awful. Use FP instead.
>>
>>61947957
Indentation levels are checks at compile-time.
>>
>>61947986
python is an interpreted language
>>
How do I edit strings in C?
>>
>>61948006
Yotsuba is cute!
>>
>>61947995
There exist both interpreters and compilers. I haven't heard of transpiled one yet, though.

Also, a language can't be interpreted/compiled. Implementation can.
>>
>>61947959
It's bullshit, stack allocation is best
>>
>>61948016
>language can't be interpreted/compiled
No it can, hence why you can interpret/compile python.
>>
>>61948006
>how do I into arrays in c
>>
>>61948006
strdup() is your friend
>>
>>61948006
you just found the shittiest part of C, congrats
http://en.cppreference.com/w/c/string/byte
(or use a third party string library..)
>>
>>61947959
>gaymen
yeah, stop linking to those mental midgets
>>
>>61948006
Say you want to trim a string, just change the pointer to the string to point to the new first element.
>>
>>61948032
A programming language is just a way to express logic.

It can be the either compiled (translated directly to machine code) or interpreted (compiled into bytecode which is interpreted by a virtual machine) or transpiled (translated into a different programming language).

C can be interpreted language too.
>>
>>61948065
next time, if you want to be a smart ass, at least get your smart assing right.
>>
>>61948058
Not him, but why not a function that dereferences the second last pointer, sees if it's an \n and if so, turns that character into \0?
>>
>>61948016
>>61948065
>When a python toddler tries to fit in
haha
>>
>>61948088
I am right.

>>61948079
Different tools for different jobs.
>>
>>61948101
shoo shoo
>>
>>61948124
no u
>>
File: 009.jpg (335KB, 869x1238px) Image search: [Google]
009.jpg
335KB, 869x1238px
Warm reminder that C will always be with you, no matter what.
>>
>>61948041
Char arrays are read-only, aren't they?
If I want to concatenate strings, I need to reallocate memory because new string won't fit old string, don't I?

>>61948048
Thanks, I've looked for this site but I forgot how it was called.

>you just found the shittiest part of C, congrats
At this point I am considering of switching the language of my choice.

>>61948042
I don't see such a function.
>>
>>61947673
no sorry
>>
>>61948195
T-thanks, Ritchie-sama
>>
>He needs more than one x86 instruction to code
Lrn2asm faggot
https://github.com/xoreaxeaxeax/movfuscator
>>
>>61948217
>>61948195
Fuck, I should really switch to C++, this is embarrassing. No wonder that the industry is leaving C and weebs behind.
>>
How true is this one, /g/?

>>>/v/387409576
>>
>>61948195
This image is comfy.

C is not an acceptable general purpose language, though.
>>
>>61948336
I'll give it an 8/10. Missing some concessions that show that there are a few cases where C is preferred.
>>
>>61948250
You will die
>>
>>61948336
It hurt a little.
>>
File: template_name.png (1MB, 1024x768px) Image search: [Google]
template_name.png
1MB, 1024x768px
>>61948250
>>
>>61948336
That thread is literally a clone of this one
>>
>>61948232
oh god
>>
The fuck!?

So this is where I drop VS Code. That shit reminded me of wincuck 10.
>>
>>61948488
Should have installed Gentoo + emacs
>>
>>61948488
>don't show again
>>
>>61948488
>No option for no
keke
>>
>>61948205
if you're on linux or similar, you can do
>man 3 string
>>
>>61948488
Should of installed Gentoo + yi
>>
>>61948488
dropped
>>
File: 1502975142536.png (154KB, 2048x1536px) Image search: [Google]
1502975142536.png
154KB, 2048x1536px
Does this prove Pajeet cannot be trusted?
>>
>>61948488
>
int
main()


mongoloids O U T
>>
>>61948488
Kate doesn't have this problem
>>
>>61948526
spotted the nu-male webdev
>>
>>61948526
The fuck are you on about?
>>
>>61948540
separating the function type and name with a new line
>>
>>61948553
Yes, what's wrong with it? People have written code this way before your birth.
>>
>>61948523
> 4 * pi * r * r
>>
>>61948557
its wasteful and not needed.
>>
>>61948523
>Reading iShit in the first place
>>
>>61948563
How the fuck is that wasteful, stupid webshitter? It literally compiles to the same binary size
>>
File: 055.png (134KB, 720x331px) Image search: [Google]
055.png
134KB, 720x331px
hey guys what do you think of my code?
>>
>>61948526
Question for those who use this style. How do you declare a function returning a char* and how do you declare a char* within a function?
>>
https://pastebin.com/raw/PDjZiSm1
the horror
>>
>>61948506
Well, thanks.
>>
>>61948585
char*
fn()
{
static char* result = 'i';
return result;
}
>>
>>61948585
char *
foo(char* bar);

why do people use this? perhaps its so they can grep for ^name without needing to know the return type?
>>
>>61948624
It's because some people don't want to break 80 character per line standard
>>
>>61948594
triggered

>flattenFilter xs = fromJust $ sequence $ filter (\x -> isJust x) xs
flattenFilter = fromJust . sequence . filter isJust


>map toError $ map (\... -> ...)
map (\... -> toError (...))


>Right configValues -> pure $ Right configValues
>Left err -> pure $ Left err
completely redundant case! just use pure
>>
>>61948594
>>61948659
toError :: (Key, Maybe Val) -> Maybe Key
toError (key, (Just val)) = Nothing
toError (key, Nothing) = Just key

toError (key, m) = m *> Just key

could probably do
uncurry ((<*) . Just)
>>
>>61948659
also flattenFilter exists in Data.Maybe as catMaybes
>>
>>61948646
well, if your function declarations are reaching 80 chars, maybe you should split your parameters on to multiple lines..

my reasoning for grepping is quite valid, since you can find declarations but won't find invocations/calls (unless you don't indent the body of the functions..) with just ^identifier. quite helpful if you aren't using a modern ctags, or are building simple documentation with sed or perl or similar.
>>
>>61948659
>ConfigValues {nick=nick, ident=ident, realname=realname}
RecordWildcards

ConfigValues{..}
>>
Thanks, auto
#include <functional>
#include <iostream>
using namespace std;

int
add(int& x, int& y)
{
return x + y;
}

int
main()
{
int a = 14;
int b = 212;

auto fn = add;
// instead of function<int(int&, int&)> fn = add
cout << fn(a, b) << endl;

return 0;
}
>>
>>61948740
auto fn = [](auto& a, auto& b) { return a + b; };
>>
>>61948444
I told you 90% of /g/ is just /v/ crossposters
>>
>>61948740
Does this create a function pointer or a std::function?
>>
>>61948798
What's the difference anyway
>>
File: 1502974177551.jpg (612KB, 1791x2048px) Image search: [Google]
1502974177551.jpg
612KB, 1791x2048px
>coding a puter
hahahahaha nerds go touch a boob
>>
>>61948798
function pointer
>>
>>61948841
Cool, that syntax is awful.
>>
>>61948852
C++ is awful
>>
>>61948798
functor (g++ with no optimizations produces this:)
; fn = add
mov QWORD PTR [rbp-8], OFFSET FLAT:add(int&, int&)
lea rcx, [rbp-16]
lea rdx, [rbp-12]
mov rax, QWORD PTR [rbp-8]
mov rsi, rcx
mov rdi, rdx
call rax

; directly calling add
lea rdx, [rbp-16]
lea rax, [rbp-12]
mov rsi, rdx
mov rdi, rax
call add(int&, int&)

at higher optimizations it makes them exactly the same.
>>
>>61948583
it's alright
>>
File: 1502077222282.png (38KB, 890x670px) Image search: [Google]
1502077222282.png
38KB, 890x670px
>>61948961
What's your opinion on this one then?
>>
>>61948883
also whats neat is that
template<typename T, typename U>
auto add_1(T t, U u) {
return t + u;
}

template <typename T, typename U>
auto add(T t, U u) -> decltype(t +ub) {
return t + u;
}

auto add = [](auto a, auto b) {
return a + b;
};

int add(int a, int b) {
return a + b;
}

auto add(int a, int b) -> int {
return a + b;
}

when used with an int will all produce the same code
(the top 3 will work with anything that defines a + operation (and follows SFINAE))
(the 3rd one will make a function pointer, but can be optimized out).
>>
>>61949001
#2 should be decltype(t + u). whatever.
>>
>>61949001
>(the 3rd one will make a function pointer, but can be optimized out).
wrong
>>
>>61949177
thats at file scope, btw. in a method it wouldn't.
>>
>>61946735
Why does the cover look like a retard scaled it in MS Paint?
>>
>>61949281
Does this use a function pointer too?
struct 
{
auto operator()(auto x, auto y) { return x + y; };
} adder;

int main()
{
adder(1, 2);
}
>>
What is the equivolent of this book for other languages?
>>
>>61947518
/pol/, please stick to your containment board.
>>
>>61949390
Head First Java for Java.
>>
>>61947308
I tried to do this and I've almost died
>>
So what pragma should I use to emit the current function name in C++?
>>
Would you say Dennis Ritchie was a beautiful man?
>>
>>61949384
I actually had to check on that one. nice.
but no, it doesn't. and you were right, a lambda at file scope is treated like your struct. (I've always used MSVC which treated lambdas like std::function and a lot of instances like std::bind .. so I guess it was a bug in their implementation).

# your adder
mov r8d, 2
mov edx, 1
lea rcx, adder[rip]
call _ZN3._0clIiiEEDaT_T0_

# c function pointer to an int (int, int);
# int (*foo)(int, int);
# foo = &add;
# foo(1,2);
lea rax, _Z3addii[rip]
mov QWORD PTR -8[rbp], rax
mov rax, QWORD PTR -8[rbp]
mov edx, 2
mov ecx, 1
call rax

# same thing, but assigning it to auto
# auto bar = &add;
# bar(1,2);
lea rax, _Z3addii[rip]
mov QWORD PTR -16[rbp], rax
mov rax, QWORD PTR -16[rbp]
mov edx, 2
mov ecx, 1
call rax

I learn something new every day about C++.

because you proved me wrong, senpai: :(
.lcomm adder,1,1
.text
.globl _Z3addii
.def _Z3addii; .scl 2; .type 32; .endef
.seh_proc _Z3addii
_Z3addii:

.lcomm add,1,1
.align 2
.def _ZN3._0clIiiEEDaT_T0_; .scl 3; .type 32; .endef
.seh_proc _ZN3._0clIiiEEDaT_T0_
_ZN3._0clIiiEEDaT_T0_:

# and
# yours
mov r8d, 2
mov edx, 1
lea rcx, adder[rip]
call _ZN3._0clIiiEEDaT_T0_
#lambda
mov r8d, 2
mov edx, 1
lea rcx, add[rip]
call _ZNKUliiE_clEii

(sorry for the delay, got lunch..)
>>
File: sufjan_illnoise.jpg (131KB, 960x960px) Image search: [Google]
sufjan_illnoise.jpg
131KB, 960x960px
>>61946791
kek
>>
>>61949565
Depending on your compiler, but the __FUNCTION__ macro should work. Some have decorated/annotated names. Look in your compiler documentation for predefined (standard and custom) macros..
>>
How mature is winforms on mono? It looks like a potentially very comfy option for cross-platform development.
>>
File: 1479844678727.jpg (106KB, 554x439px) Image search: [Google]
1479844678727.jpg
106KB, 554x439px
>/dpt/ is abandoned for the sake of thread on /v/
>>
>>61949756
Use Qt
>>
>>61949756
It should be feature compatible/complete with Windows Forms 2.0 (minus the Microsoft / Windows stuff, of course). But both have been deprecated...

You should probably look into Xwt. It sits above WPF, but can use a Gtk# engine on Windows, Gtk# on Linux and Cocoa or Gtk# on macOS. And it actually has gotten updates in the last 10 years..
>>
File: 1502644677821.png (572KB, 563x706px) Image search: [Google]
1502644677821.png
572KB, 563x706px
>>61949798
i claim this thread in the name of the anime posters of /dpt/!
>>
>>61949835
fuck sepples
>>
>>61949857
>fuck sepples
>lets use rebranded java instead
current state of /g/
>>
>>61949867
lets use strongly typed FP instead
>>
>>61949844
HANG
YOURSELF
STUPID
ANIMEPOSTER
>>
>>61949887
>autistic meltdown
>>
>>61949887
kys newnigger
>>
File: 1492865665232.png (18KB, 744x247px) Image search: [Google]
1492865665232.png
18KB, 744x247px
>>61949887
>>
Why is desktop GUI development in compiled languages so annoying? Either you're locked into platform-specific options for Apple or Microsoft, or you're stuck with one of the cross-platform toolkits where QT on sepples seems to be the least terrible option.

Python + PyQT seems to be the simplest option overall for quickly pumping out a decent GUI, and you can iterate on a design very quickly. But then I'm using a dynamic scripting language which makes projects annoying to maintain, and it makes deployment more complicated.
>>
>>61949887
dumb frogposter
>>
File: 1480509338888.png (177KB, 424x335px) Image search: [Google]
1480509338888.png
177KB, 424x335px
>>61949887
>>
>>61949957
But without Qt/C++ you wouldn't have PyQt. Whats wrong with the C++ API (ignoring moc and all the Qt-isms like making their own STL)?
>>
>>61949756
>>61949957
Eto is decent.
https://github.com/picoe/Eto

It's currently maintained, it produces reasonably native GUI's, and you can use it from F# if you like strong static typing.
>>
File: 1500261898309.jpg (197KB, 935x799px) Image search: [Google]
1500261898309.jpg
197KB, 935x799px
Why aren't you learning the beautiful language, anon?
>>
>>61950144
Why did you post that pic
>>
>>61950168
he's from /v/
>>
>>61950061
>F#
lmao, even C# is slower than Java
>>
>>61950144
M'onad
>>
>>61950144
Because I already know it reasonably well, and I'm not currently working on a project where I get to use it.
>>
>>61950144
Why is Haskellwojak so much more based than the other ones?
>>
>tfw when had weird error while learning python
>couldn't get numpy.arange() to work, kept complaining it didn't exist
>finally realize i'd been mis-spelling it as numpy.arrange() this entire time
kill me
>>
File: 1428374232739.jpg (24KB, 480x360px) Image search: [Google]
1428374232739.jpg
24KB, 480x360px
>C does not provide an automatically-managed string type
Well, fuck.
Should I switch to C++?
>>
>>61950230
C is not an automatically managed language
>>
>>61950230
skip directly to Rust
>>
>>61950230
Use Rust and you even get an UTF-8 encoded string
>>
>>61950182
top kek
>>
>>61950230
Rust is actually superior to C++. I'm only using C++ because I want to see Qt quick's potential.
>>
>>61950230
Use Boehm GC if you care so much
>>
>>61950230
Yes.
>>
>>61950230
Don't expect the C++ standard library strings to be much better, they are utterly retarded. You'll probably end up using a third part library for strings either way.
>>
>>61949798
N I N E T Y P E R C E N T
>>
>>61950247
>O(n) string indexing
Though I guess a Ctard would be used to O(n) strlen
>>
>>61950230
Don't listen to the Rust shills. Rust is an SJW language.
>>
>>61950268
Use C style string for O(1) string indexing then
Oh wait
:^)
>>
What's the programming equivalent of this?

https://www.youtube.com/watch?v=9JDzlhW3XTM
>>
>>61950245
>>61950247
>>61950251
You won't get me, Rust shill squad
>>
>>61950269
C has it's place, I'm saying he should use Rust because C++ is self imploding
>>
>>61950281
But a char* does have O(1) string indexing.
>>
>>61950290
No, I'm telling you to skip to Rust to avoid C++.
You could also learn OCaml, Haskell, C#, etc.
>>
>>61950265
>S O U R C E : O U T O F M Y A S S
>>
>>61950296
but he wants managed string
>>
>>61948205

>char arrays are read-only aren't they?
Not really. I mean, if you make a pointer to a string literal, it will probably be placed into read-only memory, but if you make an array or malloc a block of memory, and let that contain your string, it's perfectly fine to write to that all you want.

>If I want to concatenate strings, I need to reallocate memory because new string won't fit old string, don't I?
Yes, although something you can do is to allocate more memory than you need, and just keep a variable around for length and capacity. When you append a new string, if the lengths of the two strings do not exceed the capacity, you can copy bytes over without reallocating anything. And that's kind of how C++'s string and vector classes work.

typedef struct {
char *data;
size_t len;
size_t cap;
} GrowableString;
>>
>>61950330
>size_t len;
that's just a placebo, it won't return the number of characters
>>
>>61948205
>If I want to concatenate strings, I need to reallocate memory because new string won't fit old string, don't I?

How do you think more abstract languages handle vectors and other kind of containers that seem to expand and expand and you don't have to deal with the memory limits? Not everything is a linked list when you want fast indexing.
>>
>>61950230
>Should I switch to C++?
Unless you have a good reason not to...
>>
>>61950370
it will if you only update the struct through the appropriate functions.
When it's all done what you will have looks like a class, except without access control or lexical scoping. But remember, OOP is evil :)
>>
>>61950370
..in your string_new(), string_grow(), etc you set the len to the right size..
>>
>>61950247
But UTF-8 is absolutely disgusting. Just like newlines without a carriage return.
>>
File: 1407729269212.jpg (85KB, 456x306px) Image search: [Google]
1407729269212.jpg
85KB, 456x306px
>>61950306
I knew I'd find you on here. My old rival.
>>
File: arraycopy.png (55KB, 908x389px) Image search: [Google]
arraycopy.png
55KB, 908x389px
I was testing out the arraycopy method and IntelliJ inserted "i:" and "i1:" beside the parameter for the starting positions (shown in pic). What do these symbols represent and is it just something Intellij does?
>>
>>61950370

The point is that you write your own string manipulation functions that will work on the len and cap fields, in addition to the data field.
>>
>>61950519
probably the names of the parameters in the function definition
>>
>>61950493

Except UTF-8 is the only acceptable way to do unicode.
>>
>>61950539
And UTF-8 is the only acceptable way to do strings.
>>
>>61950539
Unicode is trash and is only good for Americans.
>>
>>61950534
Thanks, that was it.
>>
>>61950555
Which is what Rust strings are.
>>
>>61950595

>is only good for Americans
Don't you mean the other way around, since the alternative to using unicode is ASCII?
>>
Hey, uh, I guess some of you guys didn't catch the memo. /dpt/ has been moved to /v/. I know it's kinda sudden, but we hope you understand. Thanks.
>>
File: make.gif (449KB, 1255x741px) Image search: [Google]
make.gif
449KB, 1255x741px
>>61946541
try to understand the API
>>
>>61950721
Are you making a starcraft bot?
>>
>>61950772
no. actually not. i am just fucking around. how they did things and so on.
>>
>>61950772
blizzard released a bot api for sc2 recently, to compete with bw-api in the ai / university relevance space
>>
>>61946541
Am I pleb for like Intellij 1000x more than Eclipse?
>>
>>61950823
i know, that is the reason i try things. i dont want to bother wird c++ thats mainly the reason
>>
>>61950880
Eclipse is trash. I haven't used intellij but I already know it's better than eclipse.
>>
File: smug_hassabis.png (246KB, 480x360px) Image search: [Google]
smug_hassabis.png
246KB, 480x360px
>>61950721
>>61950823

how long do you think until SC2 gets BTFO?

A few days ago a DOTA 2 bot beat the pros 1v1 for the first time.
>>
>>61950892
>I haven't used intellij but I already know it's better than eclipse.
Peak /g/
>>
>>61950892
Typical shitbrians shills
>>
>>61950901
>>61950903
Eclipse is just a cluster fuck to me and I enjoy the shortcuts of IntelliJ and the interface.
>>
>>61950894
Why do people keep thinking 1v1 means anything?
Call me when a proper match is done, and bots can deal with bait and ganks.
>>
>>61950932
Excuse me are you trying to steal my identity?
>>
Is this true, /g/?

>>>/v/387423026
>>
File: thick pepe smug.png (7KB, 420x420px) Image search: [Google]
thick pepe smug.png
7KB, 420x420px
>>61946541
Misato is best girl
>>
>>61950941
CONDUCTOR, WE HAVE A PROBLEM OVER HERE
>>
>>61950894
>after about 50 matches

wow thank god we have this super advanced ai. Nothing like doom or quake bots, no sir.
>>
>>61950949
i'm sure it'll help you develop a deeper connection to what you're building and will probably help the dilemma where nearly every fucking game today feels the same no matter the art style and plot.
>>
>>61946541
What's Misato working on in that image?
>>
>>61950949
The people buying indie games don't care what language the game was written in and how efficiently the cpu is being utilized
>>
>>61950980
Some win32 stuff.
>>
>>61950980
Leading the team.
>>
>>61950956
>Nothing like doom or quake bots, no sir.

the difference is this bot taught itself how to play from simulating matches against itself. it learned non-obvious strategies like creep pulling without having to be programmed to do it.

doom bots are just hardcoded. totally different algorithm.
>>
currently I'm learning java and I aim to be a backend web dev. after I finish this java course I'm doing which would be better to learn: spring + hibernate or spring boot + jhipster? if there is a better combo you /g/ents could recommend it to me
>>
>>61950823
Yeah they need to get in on that university student tournament scene fast or their game is doomed.
>>
>>61946541
what is the difference between
Player(std::string n, Weapon& w) : name(n), hp(125), wep(w) {}

and
Player(std::string n, Weapon& w) : name{n}, hp{125}, wep{w} {}
>>
I'm trying to make a C program to open a file whose name was inputed by the user, but i can't make this simple thing work:

 
#include <stdio.h>
void main(){

FILE *myFile = NULL;
char txtName[255];

strcpy(txtName, "my");
strcat(txtName,"example.txt");
//i actually need this (or some sort of) concatenation...

myFile = fopen(txtName, "w");

fprintf(txtName, "I dont know why i am not working!");

fclose(txtName);

}



it compiles and creates the txt on the same directory, but it doesn't run or modify the myexample.txt
>>
>>61951208
replace txtName with myFile in fprintf and fclose
>>
>>61951186
In ATS I think you would specify type information inside the {}, for example only accepts natural numbers over certain and such.
But that seems sepples so nobody knows.
>>
>>61951232
kek, i'm really stupid
>>
>>61951186
In most cases there is none.
Some special classes like vectors initialize differently with () and {}, and POD structs without constructors can only be initialized with {}. But they're only edge cases.
>>
Learning Scala. I'm liking it so far. It's Haskell for brainlets, so it's perfect for me.
>>
>>61951208
>it compiles
Are you sure?
>>
File: 1388798379.png (154KB, 509x506px) Image search: [Google]
1388798379.png
154KB, 509x506px
Trying to get this Hasklel product to talk to kubernetes API
>>
>>61951325
yeah, it compiled on gnu gcc on code blocks (windows)
>>
Any of you guys capable of writing good raw machine code by yourself?
>>
Dynamic typing sucks and macros are a hack.
>>
>>61951327
Couldn't match expected type CuteGirl
with actual type NotThatCuteGirl
In the expression Just Sayaka :: Maybe CuteGirl
>>
>>61951524
dynamic typing sucks but macros are the best thing ever.
>>
File: 1497870738208.png (13KB, 499x185px) Image search: [Google]
1497870738208.png
13KB, 499x185px
>>61951327
>>61951531
>>
learning javascript helped me understand how exactly python classes work under the hood.

isnt that crazy?
>>
File: 1502990617.png (14KB, 419x138px) Image search: [Google]
1502990617.png
14KB, 419x138px
>>61951531
>>61951580
bad taste in magical girls I see
>>
File: 1502988017855.png (104KB, 1600x500px) Image search: [Google]
1502988017855.png
104KB, 1600x500px
>>61948488
hello sir you we have examined your telemetry report okay? now please do the needful and shill our product to everyone
>>
>>61951616
lmao wtf
>>
>>61951580
Proof that Rust sucks.
>>
>>61951616
how do people allow this?
>>
>>61951580
btfo
>>
File: l0Iy3ypKiRbGIj6Eg.webm (1MB, 480x394px) Image search: [Google]
l0Iy3ypKiRbGIj6Eg.webm
1MB, 480x394px
Brainlet here, how competent do I have to be to do some freelance work?
>>
>>61951812
Senior level.
>>
>>61951865
shit
>>
>>61951812
Find people willing to pay you to write systems you know how to write. If you don't know much, guess what.
>>
File: papa-roach-jacoby.jpg (185KB, 650x366px) Image search: [Google]
papa-roach-jacoby.jpg
185KB, 650x366px
i have a txt file

seahawks 20, patriots 24
colts 45, broncos 17
browns 23, seahawks 16


im still a noob....how would i find out how many unique teams there are and how many games each team won?
>>
>>61952024
what are you struggling with? In what language are you trying to do your homework in?
>>
>>61952024
open the txt file and count
>>
New thread:

>>61952079
>>61952079

>>61952079
>>61952079

>>61952079
>>61952079
>>
>>61952070

i can either use php or python im using php at the moment. Idk...at first i tried making it all into a string, then removing the commas, then converted it into an array by dividing by spaces. Key values. But...doesnt look right. If a team has spaces in their name it gets messed up. Basically i havent gotten very far
Thread posts: 313
Thread images: 42


[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.