[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: 319
Thread images: 24

File: Daily-programming-thread.asuka.2.png (535KB, 1023x858px) Image search: [Google]
Daily-programming-thread.asuka.2.png
535KB, 1023x858px
What are you working on, /g/?

Previous thread: >>61454112
>>
muslims
>>
Asuka worst girl
>>
>>61461859
>tfw asuka will never peg you while you program together
>>
Is there anything specific that you need to consider when designing a program that intends to have multiple frontends? For example something like transmission-bt, it has a cli, coacoa, gtk, qt, web, and maybe more frontends. Is this just a result of having fine grained functionality in the core library?
>>
>>61461859
I just installed a syntax highlighting vim file, but the syntax rules don't automatically load when I open the shader source.

I put
au BufNewFile,BufRead *.frag,*.vert,*.geom setf glsl

In my .vimrc

Doing
:set syntax=glsl
works though.
>>
File: haha.webm (20KB, 58x126px) Image search: [Google]
haha.webm
20KB, 58x126px
>>61461885
>>
>>61461886(you)
>>
fn why(s: String) -> String {
s.split('\n').join('\n')
}

error: no method named `join` found for type `std::str::Split<'_, char>` in the current scope
--> main.rs:2:16
|
2 | s.split('\n').join('\n')
| ^^^^


this is retarded
>>
File: lol.jpg (44KB, 481x600px) Image search: [Google]
lol.jpg
44KB, 481x600px
>>61461859

trying to get this regex to work (C++11)

complex_integer = std::regex("(-)?([0-9])+(\+|-)+([0-9])?(i)+");


regex_error caught: regex_error

The expression contained mismatched brackets ([ and ]). // no it fucking doesn't


it works on regexr.com
>>
>>61462452
escape your '-'?
>>
>>61462442
What did you expect from a language that makes even the most simple things overly complicated?
>>
>>61462963

didn't work
>>
File: 1388903446260.jpg (11KB, 226x239px) Image search: [Google]
1388903446260.jpg
11KB, 226x239px
What's the standard way to do this in C++11?
Cloudflares protection is a peice of shit and won't let me post this inline.
https://ghostbin.com/paste/4pgfs

That only works in gcc.
I have a bunch of constant chars that I just want to turn into a constant string (const char*) during compile time so that it's embedded in the binary. Looking for any standard way to turn constant chars into a constant string, I'm going crazy with this.
>>
>>61462452
>>61462963
>>61463169
Going to try to walk through this with you cuz I'm bored as fuck.

First things first, you don't want ([0-9])+, you probably want ([0-9]+), unless you want capture groups for every individual integer.
>>
Struggling through the K&R book.

I'm writing a recursive version of 'reverse(string)',
/* EXERCISE 4.13 - Write a recursive version of 'reverse(s)',
which reverses a string, s, in its place */
#include <string.h>
#include <stdio.h>

void r_reverse(char* s, int ind, int end_ind)
{
char temp = s[ind];
if(ind != end_ind)
{
int other_ind = strlen(s) - ind - 1;
printf("S[ind] = %c\t", s[ind]);
s[ind] = s[other_ind];
s[other_ind] = temp;

printf("S[ind] = %c\t\n", s[ind]);

r_reverse(s, ind+1, end_ind);
}
}

void reverse(char* s)
{
r_reverse(s, 0, strlen(s) / 2);
}

int main()
{
char input[] = "Reverse Me!";
reverse(input);

printf("%s\n", input);
}


This code runs fine and works as is, but when I do
 char* input = "Reverse Me!"; 

I get
 Bus Error: 10 


What's going on?
>>
>>61463249
String literals are not modifiable.
Use
char input[] = "Reverse Me!"; 
to make a new string that you can actually change.
>>
>>61462452
>>61463210
alright...

we're talking about a complext integer, having a form a+bi

I'd probably recommend capturing negative a's within the first group.

(-?[0-9]+)


next, there will be a single operator, + or -

([-+])
(I like having an operand character class than your or because it's cleaner. Why you were allowing for multiple operands, I'm not sure.

next is the imaginary number

which is same as above, but with a necessary 'i'
(-?[0-9]+i)


yielding:
(-?[0-9]+)([-+])([0-9]+i)


if you want an optional imaginary component, then:

(-?[0-9]+)([-+])([0-9]+i)?


you follow?
>>
>>61463193
In what way is a string literal not what you want here?
>>
>>61463249

Stop writing buffer overflow-prone code. Ideally use a decent modern language invented after memory protection, but if you have to use C, then check the boundaries of your fucking strings for crying out loud (send the size as an argument).
>>
>>61463348
Thanks

>>61463292
So... Is the difference between char* and char[] that one's a string literal?
>>
>>61463340
I don't know how you mean. I want whatever will work, essentially I just need to compose a constant string from character constants.
>>
>>61462452
>std::regex
>>
>>61463335

that one compiled but didn't work

I'm pretty sure this fucking std::regex shit is broken
>>
>>61461859
Why's is that generic looking lesbian anime girl doing a backflip? What does she got to do with programming?
>>
>>61463348
stop posting this, it's not even completely correct.

>>61463375
for what input?
>>
>>61463394
Who are you quoting?
If you don't tell me who you're quoting I'm going to have to ask you to leave.
>>
ADTs are superior to classes because there's nothing you ever need a class for whose purpose wouldn't be more easily served by sticking enums, unions, tuples, data structures, and wrappers together like legos, and ADTs are pretty much that, except the syntax for each such layer of type sophistication is less idiosyncratic, and also they're conceived in terms of functions over type rather than in terms of language built-ins
>>
>>61463360
>So... Is the difference between char* and char[] that one's a string literal?
String literals live in read-only, static storage.
When you assign a string literal to a pointer, think of it like you're doing this:
static const char __hidden[] = "Reverse Me!";
char *input = (char *)__hidden;

But when you assign it to an array, it makes a new local copy which you can do whatever you want with.
static const char __hidden[] = "Reverse Me!";
char input[strlen(__hidden) + 1];
strcpy(input, __hidden);
>>
>>61463415
What is the point of this shitpost?
>>
I fall in love with visual studio code a little more every day. Those fuckers finally did something right.
>>
>>61463361
Maybe I'm missing the point of your example, but a string literal is literally a constant string of characters. Why the macro?
>>
File: On the House.jpg (248KB, 1334x750px) Image search: [Google]
On the House.jpg
248KB, 1334x750px
>>61463432
That makes a lot more sense.

Thanks!
>>
>>61463442
I'm trying to format __DATE__ and __TIME__ like this and it's killing me.
#define TIMESTAMP { __DATE__[7], __DATE__[8], __DATE__[9], __DATE__[10], '-', MONTH[0], MONTH[1], '-', __DATE__[4], __DATE__[5], '-', __TIME__[0], __TIME__[1], '-', __TIME__[3], __TIME__[4], '-', __TIME__[6], __TIME__[7], '\0' }


I need the timestamp to be in there at compile time and in that format. MONTH is defined elsewhere but it just takes them month portion of __DATE__ and turns it into a decimal represented as a 2 char string "01"-"12".
>>
>>61463433
I'd like to kindly ask you to leave this thread
Bullying belongs in >>>/b/
>>
>>61463501
>>61463442
I should have stated the format
YYYY-MM-DD-HH-MM-SS
2017-07-19-07-34-00
>>
>>61463415
Stop shitposting please, onegai desu ne
>>
>>61463601
>onegai desu ne
cringe
>>
>>61463501
This seems like a gross misuse of the C preprocessor. Just use strftime and strptime.
>>
>>61463625
y-yamete!! Bok..watashi wa kakoii desu ne
>>
>>61463633
I need the resulting string to be built into the binary, so it has to be there at compile time, I can't do it at runtime.
>>
>>61463633
those would be runtime timestamps, not compile-time ones
>>
File: Screenshot_2017-07-19_18-42-58.png (15KB, 314x242px) Image search: [Google]
Screenshot_2017-07-19_18-42-58.png
15KB, 314x242px
rip Akari boobs, gone but not forgotten
>>
>>61463360
>So... Is the difference between char* and char[] that one's a string literal?
No, you can assign it to either.
The real difference is that a char [] is a statically allocated buffer of known size and the memory it points to lives and dies with the function where it was declared, whereas a char * is just an address, with no information available as to the size of the buffer pointed to, where and how it was allocated, or if there even is one (as opposed to being a "dangling pointer" into nowhere).
>>
>>61463532
Isn't it simple enough just to write it as a constant character array?

eg. const char timestamp[] = { '1', 2', '3', '\0' }
>>
>>61462442
fn why(s: String) -> String {
let lines: Cow<[_]> = s.split("\n").collect();
lines.join("\n")
}[\code]

It is dumb. Alternatively, check out the itertools crate which has what you're looking for.
>>
>>61463687
You would feed it into strptime(__DATE__" "__TIME__, "%b %d %Y %T", tm) or whatever, and then write whatever format you want using strftime.

>>61463681
Is there any reason you need that particular format?
Also, I'm curious as to how you possibly got MONTH completely at compile time.
>>
>>61463798
this would incur a runtime overhead for no real reason
>>
>>61463404

all input
>>
>>61463724
That works but it's not what I need, I need a pointer to a constant string, not a constant character array. When I use an array the compiler is complaining about unresolved external symbols, I'm trying to export the timestamp as a data object on a dynamic library.

>>61463798
I'm aiming for the ISO standard format, this dash format is just for example as it's close enough.

#define MONTH (\
__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? "01" : "06") \
: __DATE__ [2] == 'b' ? "02" \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? "03" : "04") \
: __DATE__ [2] == 'y' ? "05" \
: __DATE__ [2] == 'l' ? "07" \
: __DATE__ [2] == 'g' ? "08" \
: __DATE__ [2] == 'p' ? "09" \
: __DATE__ [2] == 't' ? "10" \
: __DATE__ [2] == 'v' ? "11" \
: "12" \
>>
failing at sql....

combine tables a, b, c
select a specific attribute from a column.
Then do a second query that combines them again
selects a different attribute from the same column.
Then ultimately returns a list of those that have matching sub attributes....
>>
>>61463886
post a couple examples, anon, just to make sure.

I gcc'd with the -std=c++11 and it's working for me

If you know of a c++ code bin thing, I'll post source. 4chan is giving me fits about it.
>>
>>61463689
It was fucking garbage
>>
>>61464018
jdoodle.com/a/4sJ
>>
>>61463887
>I need a pointer to a constant string
>not a constant character array

There's no difference between those two things.

Your actual problem sounds like the symbol isn't being exported from the library, which is inherently gonna be a compiler-specific problem. Also bear in mind if you make it a macro (which is inline) the date will be the compile date of the code using the header, not the compile date of the dynamic library.
>>
Hello /dpt/
Does anyone have any good resources to learn the basics of C memory management? I slept through most of that chapter in my programming class.
>>
>>61463887
As much as I hate recommending non-standard shit, a possible solution you could do is
#define _XOPEN_SOURCE // for strptime
#include <stdio.h>
#include <time.h>

/*
* We use separate storage, so we can modify the timestamp in the constructor,
* but not through 'timestamp' itself
*/
static char timestamp_[32];
const char *const timestamp = timestamp_;

__attribute__((constructor))
static void set_timestamp(void)
{
struct tm tm;
strptime(__DATE__" "__TIME__, "%b %d %Y %T", &tm);
strftime(timestamp_, sizeof timestamp_, "%FT%TZ", &tm);
}

int main()
{
printf("%s\n", timestamp);
}
>>
>>61464246
read the chapter?
>>
>>61464308
>implying I bought the book
>>
rate this list

java
- kotlin
python
haskell
swift
>>
>>61464335
/t/?
>>
>>61464018

I am doing it like this

https://pastebin.com/sNc0awyw
>>
Is there a way I can use C without the cluster fuck dumb shit C preprocessor?
>>
>>61463963
This is my terrible attempt at this, using a somewhat contrived dataset.

http://sqlfiddle.com/#!9/48057/1

So what I would want to do is compare houses in two cities ('lorum' and 'ipsum' in this specific case) and return only those where the 'color' and 'roof' match.

This would be a correct response (no particular order)
100, fubar, lorum, black, steeple
562, fubar, ipsum, black, steeple
104, fubar, lorum, orange, flat
564, fubar, ipsum, orange, flat
>>
>>61464551
Not without making things a thousand times more complicated
>>
>>61464592
Is there like a version of C that is like Go but without gc?
>>
>>61464551

Realistically, the only parts of the C preprocessor that you actually need for practical use are #include and the #ifndef guard. C macros are something you can do without.
>>
>>61464628
>and the #ifndef guard
Not even that.
>>
>>61464628
Yeah, but macros make C seem like a hacked together piece of crap because you have to process a file multiple times.
>>
>>61464107
>There's no difference between those two things.
There must be some difference, the linker gives me an error when using an char array vs a char*. I export a version string that's static enough to be an actual literal
const char* Version = "0.1.0";
if I were to do
const char Version[] = {'0', '.'...};
that won't export. Specifically I get this as a linker error: "unresolved external symbol Version".
I have Version exported via a .def file
Version = Version DATA

It works as expected in external programs when I use a string literal and I want the same functionality but with a build timestamp.
>Also bear in mind if you make it a macro (which is inline) the date will be the compile date of the code using the header, not the compile date of the dynamic library.
I don't understand, wouldn't the header always be out of date since it's using the __DATE__ macro? As long as that's true the build date on the library should be correct when I build it, no?

>>61464278
Unfortunately it has to be standard, I intend to migrate to another compiler later.
If I could use non-standard things the original example works fine in gcc
https://repl.it/J9no/0
^This is exactly what I need but done standard.
>>
>>61464600
Why not just use cgo, writing Go for the majority and C where you need to manage your own memory.
>>
>>61464669

#ifndef is part of the C standard
#pragma once is not

If you want to make a header file that will be reused across multiple files, it is necessary that you use the preprocessor to prevent it from being included twice by the same file. The correct way to do this is with #ifndef.
>>
>>61463438
Except handling updates. I get each update twice.
>>
>>61464400
trying to help, but I'm having trouble with getting this to jive with my GCC and I don't want to downgrade to 4.

The regex I gave you should be right, though. Have you tested the link I gave on you machine?

jdoodle.com/a/4sJ
>>
>>61464743
Why does someone just make a more modernized version of C? Like, C with some modern conveniences, like packages/modules.
>>
>>61464774
>Why doesn't someone just do the right thing
Stop that.
>>
>>61464766

It worked

idk mane
>>
>>61464759
What are you smoking? I did not mention #pragma once anywhere.
>>
>>61464818
The only alternative to #ifndef guards is #pragma once. You did not need to mention it for it to be implied.
>>
>>61464860
The only alternative to #ifndef guards is not using them at all as you probably do not need them.
>>
>>61464759
>If you want to make a header file that will be reused across multiple files, it is necessary that you use the preprocessor to prevent it from being included twice by the same file.
That can be done by hierarchizing your headers to prevent cyclic inclusions. This is the case in the Plan 9 libc. I do that too in my personal projects. It's piss easy to do, and it saves compile time.
>>
>>61464871
Also by using incomplete struct declarations.
And C11 allows repeating typedefs of the same thing.
>>
>>61464871

Just because you don't include it multiple times doesn't mean that others using it won't. As a general rule of thumb, every header MUST have an #ifndef guard.
>>
So I'm going into my third year out of 4 for my comp sci degree. They've literally only taught me java (I know discrete math and data structures and shit though), and after this year I'll know C and Assembly and will have taken classes on Hardware and Operating Systems, maybe even Compilers or Databases. I really wanna get an internship next summer, but I was looking at a lot of them and it seems like that won't be enough, I'll need to learn more stuff on my own to get an actual, meaningful internship. I know a bit of C++, but aside from that, that's pretty much it. In a perfect world, I'd become a Games Developer, but I'm also interesting in Security and Application Development. What should I learn in my free time? SQL? PHP? CSS/HTML? Python? I have no idea desu.
>tl;dr: What languages and shit should I know to get an internship? I only really know Java at this point.
>>
suicidal thoughts are normal right
>>
>>61463438
>doing a lab in cpp class
>professor is an old fart who worked at bell labs for like 40 years
>get an error, raise hand, ask professor what I should do
>"eh that's just visual studio. It's just so terrible, honestly. I mean, if we were using Unix, there would be no problem at all! Microsoft are terrible at making products."
>makes me log off the lab computer and rewrite my code in another one because apparently that's the only way to fix it
>digresses about how great unix is every single lecture, I shit you not
>>
how do you stress test a program or a web app?
>>
>>61465041

Actually they aren't, but it is becoming increasingly more normal with each passing year. Why are you suicidal, Anon?
>>
>>61465072
Why were you on Visual Studio to begin with if the lab required you to use a Unix machine?
>>
>>61465072
Not sure what he's on about. Aside from the msvc optimizer the Cpp side of the compiler is ok. They're slow to get on the latest features though
>>
>>61465072
>actually using botnet studio
kys faggot
>>
>>61461886
shit taste
even moot likes asuka
>>
>>61465072
I'm talking about Visual Studio Code, a free editor microsoft released for mac and linux.

It sounds ridiculous, like the time they release IE for linux, but it's pretty fucking awesome.
>>
>>61465087
dunno
i feel like a fat piece of garbage who is constantly re-realizing what a fat piece of garbage he is, reconsidering solving the problem of his existence by ending it, giving up on the idea and forgetting until next time which tends to come five minutes later
it's like dory from finding nemo but if she was a lazy slob and hated herself
programming used to help ignore the thoughts but now they won't even let me program
doing anything to change or improve is of course out of the question because that would be a tremendous demand on my capacity for self reflection and motivation which seems to be woefully limited to kicking myself in the mental groin just to remember it hurts
>>
>>61465072
He's right, you knowl
>>
>>61465107
it didn't require us to use a unix machine
all the lab computers use windows 10 though
>>
>>61465072
>not just using tmux, vim, make, and valgrind as your ide
>>
>>61461859
vim
vi
virgin
>>
>>61465255
>implying
wrong, I'm no virgin
my dad made sure of that when i was 6
receiving counts right?
>>
Does anyone have any sources on strategies for synchronizing threads? For example, how rust uses and implements the Arc type? Info that's useful for posix threads would be nice but I'll take pretty much anything.
>>
>>61465192

>i feel like a fat piece of garbage who is constantly
Do you want to not be a fat piece of garbage? Cut soda and other heavily sugary beverages from your diet. Drive less, take the bus and walk more, and consider going to the gym if you have time.

>it's like dory from finding nemo but if she was a lazy slob and hated herself
If you are a lazy piece of shit, there's an app for that:
https://habitica.com

(the backend is even FOSS, so you can't pull a Stallman/botnet excuse)

>programming used to help ignore the thoughts but now they won't even let me program
Hey, remember what I said earlier about hitting the gym? That's gonna get some endorphins kicking around that'll actually make you feel good after a while.

>that would be a tremendous demand on my capacity for self reflection and motivation
Don't think; do.

>which seems to be woefully limited to kicking myself in the mental groin just to remember it hurts
No pain, no gain. Life is trying to make you its bitch. You need to make it YOUR bitch.
>>
>>61465235

At my previous university, all of the lab machines ran both Windows 10 and Ubuntu on a dual boot setup. Is this not the case at your university?
>>
>>61465084
google "how to stress test web app"
>>
>>61465337
what's the difference between college and university?
>>
>>61465084

pls respond
>>
>>61465379
see >>61465344

you're asking questions that could be easily solved if you googled it
>>
File: vsc.png (36KB, 770x463px) Image search: [Google]
vsc.png
36KB, 770x463px
>>61465189
this shit comes in the box.

it makes it so much easier to pick up a new lib and go
>>
File: 1481798820582.jpg (599KB, 1000x1000px) Image search: [Google]
1481798820582.jpg
599KB, 1000x1000px
>>61465192
That sucks. For me it helps to remember that pleasure is the sweetest after pain. Your goal should be to accept the pain and try to balance it with the pleasure. Not to mention that pain is it's own kind of pleasure.

>>61465337
Not him, but at my college we have thin clients that pretend to run windows 7.
>>
>>61465404
>what's a language server
>>
>>61465330
i appreciate it but we've done this song and dance before
no point in replicating it
only reason i keep coming back here and bitching about it is because it's constantly on my mind and i spend a lot of time here anyway so it kind of just keeps coming loose
all i really need is to be patient, once we're into the fall i'll finally be in a situation where i can just not eat and there won't be anyone who cares about me hanging around to make me feel guilty about it
>>
>>61465406
we had a mac lab, a linux lab, and a main windows lab.

the point of cs isn't to teach you how to use a thing, it's to teach you how to figure out how to use arbitrary things.

most classes that required writing non-trivial code used a language throughout. sometimes, or in other classes, the prof would just be like "do this in... I don't know... python"
>>
>>61465437
So how would you set this up in Vim?

I think the best part is they took the good stuff from IDEs, but kept it a text editor.
>>
>>61465463
>how would you set this up in Vim?
https://github.com/autozimu/LanguageClient-neovim
>>
>>61465484
For rust
https://github.com/rust-lang-nursery/rls
>>
>>61465443
>all i really need is to be patient, once we're into the fall i'll finally be in a situation where i can just not eat and there won't be anyone who cares about me hanging around to make me feel guilty about it
This is a really fucked up way of thinking and you should probably see a shrink because laziness seems to be just the tip of the iceberg with you.
>>
Reminder to stay hydrated and talk to girls sometimes.
>>
>>61465337
nope
I'm taking summer classes at a shitty local community college
the computers are at least like 5 years old and it takes fucking 3 minutes to boot up visual studio and 5 minutes to boot up in general.
But even at my real university, which is actually a nice one, they don't have that
>>61465351
in america, there is none pretty much
a college and university are the same thing
a community college is cheaper and less prestigious (for poor people and dumb people) and only offers 2 year degrees, not bachelors degrees
>>
>>61463404
>it's not even completely correct.
Remind me to never use your C code.
>>
>>61465484
looks ok

I guess my point is how great I found the experience without a learning curve or configuration. I don't have to fuck with rc files and esoterically/poorly documented modules.

Hey, coding in react? Click the extensions button and type react. Your JSX editor is ready. When I did it on vim, it just wasn't that easy.

It also comes with some good basics. Like the first time I opened a folder, it had by git tree right there with easy management.

You can get vim to fit you like a glove, but I'm just saying vsc is pretty comfy out of the box, or especially for people who fall more on the atom/sublime side of the fence.
>>
>>61465446
I do agree that learning how to learn and solve problems is important. But I also believe that the tool can affect the user. It reminds me of something Dijkstra said:

"It is not only the violin that shapes the violinist, we are all shaped by the tools we train ourselves to use, and in this respect programming languages have a devious influence: they shape our thinking habits. This circumstance makes the choice of first programming language so important."

And in that sense I find it important to
>teach you to use a thing
Instead of just
>teach you how to figure out how to use arbitrary things
Although I'd imagine that general problem solving would be more important than your language, the language still matters.
>>
Just finished a programming test for a job I'm looking at.

One of the questions was how to swap two numbers without using a temp var.

Another question was: Why are manhole covers round?

Browsing /g/ is why I got these right.

Surprised I didn't get a fizz buzz.
>>
>>61465612
>Why are manhole covers round?
What the fuck?
>>
>>61465612
ez
swap(a, b)
>>
>>61465589
You're right, and of course the language matters.

But I'd stick to two points:

1) if someone provides constraints on framework/libraries/dependencies, you better be able to figure them out

2) without trying a lot of languages, it can be difficult to really figure out what you like/dislike and want/need from a language. Given a problem and knowing you could nail it in a particular language.

>One of the questions was how to swap two numbers without using a temp var.
use a language that supports that sugar, like ruby: x,y = y,x

>Why are manhole covers round?
Because it's impossible for a round manhole cover to fall down the manhole it's covering. If it was rectangular, you could turn it and accidentally drop it down.

>>61465644
It's a filter question to test reasoning skills.
>>
>>61463348
>check the boundaries of your fucking strings for crying out loud (send the size as an argument).
literally why not just rely on the fact that strings are always null terminated without exception and anything that isn't null terminated isn't a string and is therefore invalid input to anything that takes a string and therefore whoever passed in a non-string to your string function is the one who's at fault for the resulting undefined behavior
>>
>>61465711
He's basically saying strlen is unsafe and is suggesting to introduce another source of overflow error by relying on your own code to provide the string length.

He also sperged at the idea of using a global max length.

He's just some guy that doesn't like C.
>>
>>61465682
>Because it's impossible for a round manhole cover to fall down the manhole it's covering. If it was rectangular, you could turn it and accidentally drop it down.
That's a cheap trick. They're expecting you to infer that if manhole covers weren't round then manholes also wouldn't be round. Turning a square manhole cover diagonally won't fit it down a round manhole.
>inb4 if you try to answer the question assuming the manhole itself would still be round then you're even dumber because the cover wouldn't stay on
Not so. The design would be as follows: as much of the hole is square as the depth of the cover, and the rest is round. That is to say, there's a groove at the top. This might actually be a superior design to the more familiar round manhole cover.
It may sound like I'm stretching the question to fit my gripe with it, but not so. The aforementioned image -- one of a square manhole cover in a square groove at the top of an otherwise round manhole whose diameter is equal to the square's side length -- is the one my mind immediately conjured as an alternative to round manhole covers when I read the question "why are manhole covers round." It was my natural and immediate inclination to come up with that scenario. Therefore, I don't understand why they failed to account for it -- a possibility that seems so obvious and has nothing wrong with it.
Maybe I'm just weird.
>>
>>61465682
I agree with that too. Were we even disagreeing on anything to begin with?

>>61465711
As long as your input isn't from the internet that's tolerable.
>>
Nth for C#
>>
>>61465821
trash
>>
>>61465463
>I think the best part is they took the good stuff from IDEs, but kept it a text editor.
This is literally the appeal of an extensible text editor, Vim and emacs are the IDE you make yourself. Want code completion? Add it, Want some other bullshit? Add it. Half the shit you want is probably built in too and can be autistically configured to fit your needs the same way your buttplug does. You can tack on as much bullshit as you want without any of the extra bullshit.
>>
>>61461859
Who here >comfy?<

Rate my kode
(define neighbors (lambda coords
(map (lambda (e) (map + e coords)) '((1 1 1) (0 1 1) (-1 1 1) (1 0 1) (0 0 1) (-1 0 1) (1 -1 1) (0 -1 1) (-1 -1 1) (1 1 0) (0 1 0) (-1 1 0) (1 0 0) (-1 0 0) (1 -1 0) (0 -1 0) (-1 -1 0) (1 1 -1) (0 1 -1) (-1 1 -1) (1 0 -1) (0 0 -1) (-1 0 -1) (1 -1 -1) (0 -1 -1) (-1 -1 -1)))))
>>
>>61465873
>(define neighbors (lambda
0/10
>>
>>61463689
did the dev stop trying to fix it?
>>
>>61465612
>Why are manhole covers round
This is a bullshit question
https://en.wikipedia.org/wiki/Manhole_cover
Manholes can be square or triangular.
>>
>>61465819
>Turning a square manhole cover diagonally won't fit it down a round manhole.

I'm guessing you meant square hole with square cover, in which case I would refer you to Pythagoras.

>>61465820
no, just shooting the shit and expounding. I'm bored.

>>61465858
You're right, but I'm too fucking lazy to "make my own IDE" out of emacs or vim. I was always just happy with syntax/bracket highlighting. I never had a lot of need for yanking three words, or remembering some 4 key incantation to wrap something with quotes or braces. I guess if I was the best fucking coder in the world, and didn't need to think before I type, vim is the obvious choice. I'm still open to it, and I still try it, but it's never really clicked. Sit for a minute thinking about what I need to do, than ahah! And then I get to save 2 seconds by 4dw or something.
>>
>>61465891
Would you prefer
(define (neighbors . coords)
?
>>
I still giggle everytime I see the word "manhole". Or Coq
>>
>>61465940
You can remap binds to be whatever you want.
>>
>>61465940
>I'm guessing you meant square hole with square cover, in which case I would refer you to Pythagoras.
No, I mean round hole with square cover.
See rest of post
>>
Should I learn D, Rust, or Nim? All three look promising.
>>
>>61465965
I get it.

The point of the question is to reason that a round cover can't fit inside what it's covering. Had you gone off on that tangent in your answer, I'm sure it would have been acceptable. Maybe even better. Or possibly worse. It might show you over complicate relatively simple problems or ignore obvious solutions.

>>61465978
I hear Rust talked about more than the others, if that's worth anything.
>>
>>61465978
D is dead, Nim was never alive and was always a kind of frankenstein's monster, Rust is painful with all the memory handlign
>>
>>61466013
>D is dead
Fug, I was leaning hardest toward it because it looked the most similar to my main language C++. Didn't the compiler just get open-sourced and an implementation of D get merged into gcc? How is the language dead?
>>
File: Untitled.png (13KB, 346x326px) Image search: [Google]
Untitled.png
13KB, 346x326px
I am working in C++ on Windows. What is the best way for me to invoke another .exe? I need to do this in two ways. First I want to invoke one, await its exit code and do something based off of that, then I want to invoke a second one and exit the current process without halting that one.

Context: I had to make an installer because of some stupid Nvidia setting that fucked up my rendering engine's performance.
>>
File: 1497522985083.jpg (63KB, 1000x726px) Image search: [Google]
1497522985083.jpg
63KB, 1000x726px
>>61465940
Honestly I'm bored too. What a shitty way to spend my life. Fuck this place; I'm only gonna post or lurk here when I have progress on a project.
>>
>>61466046
Look for job postings for D or community activity. What does it compare to in demand?
>>
>>61466046
Nobody really uses it
Maybe after being merged into gcc it'll be more popular, and I suppose it's better than C++, but it's not really worth learning
>>
>>61466010
What even teaches you that? I tend to think I'm pretty logical/reasonable but this just seems like geometry trivia. I'm assuming this question is mostly asked in jobs where graphics play a role.

My honest answer would have been "probably some esoteric standard that someone did originally and now everyone has to follow it, or it's easier to manufacture". My mind went to "the city is always cheap and stagnant when it comes to construction work" immediately.
>>
>>61466084
I've learned a few things, I've laughed a few times, I've helped a few people.

Honestly, it's not the worst way to kill time, desu
>>
>>61465941
Not so much a matter of preference as efficiency
>>
>>61466127
It's just to see how you reason.

Like how some people wonder how the deer know to cross where they put of the "deer crossing" signs, instead of recognizing that they simply put them were concentrations of people hitting deer occur.

I've had to explain that to more than one person.
>>
>>61466046
Because it's not dead, obviously
>>
>>61466168
You think I would have gotten a lower mark with my answer?
>>
>>61466064
>I am working in C++ on Windows
>>>/v/
>>>/trash/
>>
File: dBqo9Gt.png (130KB, 396x381px) Image search: [Google]
dBqo9Gt.png
130KB, 396x381px
>>61466230
So NASA is /v/? Cool, anon.
>>
>>61466251
dumb frogposter
>>
>>61466085
I guess so, but by that metric every language except JS, C/C++ and Java are "dead".

Keep in mind that I'm just learning a new language as a hobby.
>>
>>61466229
I don't know. I guess it depends on what they're looking for.

The question might have been truly meaningless.

Your answer might have shown you could overthink things or miss obvious solutions. Occam's razor type shit.

Or it could show that you think out of the box.

The best answer depends on their needs.
>>
>>61466064
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
Use DETACHED_PROCESS t exit without killing the child process.

>>61466230
Epin
>>
File: 20170607064915_1.jpg (38KB, 450x450px) Image search: [Google]
20170607064915_1.jpg
38KB, 450x450px
>>61466288
I'd found that function when googling, but I wasn't sure whether I should use that, system() or one of those fancy new C++11 ways. Thanks, anon!
>>
>>61466273
I think there's a future in Elixir. Functional stuff is fun to learn, too.
>>
>>61466308
Don't use system() unless you absolutely need to, I think the only reason you ever would is to call builtin interpriter functions.
The C++ ways probably wrap the WinAPI anyway but it wouldn't hurt to use them anyway if you ever plan on porting your application. Otherwise CreateProc is the current way to do it on Windows/winapi.
>>
File: calendar.png (81KB, 1278x1052px) Image search: [Google]
calendar.png
81KB, 1278x1052px
Wouldn't it be nice if the calendar was simpler? 6-day weeks would be nice too.
>>
>>61465978
Rust is a pain in the ass to work with
D and Nim are nice. Nim has nice hygenic macros and a better GC than D.
D is quite comfy and it's more stable. Nim hasn't reached v1.0 just yet.
>>
I want to get into machine learning and specifically image classification. It's such a big field, does anyone have any ideas on places to start? I hate python so I'll probably be doing most of the programming in either C or C++.
>>
>>61466517
>and a better GC than D.
eh
>>
>>61465072
>>"eh that's just visual studio. It's just so terrible, honestly. I mean, if we were using Unix, there would be no problem at all! Microsoft are terrible at making products."
True

>>makes me log off the lab computer and rewrite my code in another one because apparently that's the only way to fix it
What's a mail?

>>digresses about how great unix is every single lecture, I shit you not
He sounds like a bro.
>>
>>61466556
https://forum.nim-lang.org/t/1779
>>
>>61466591
That was debunked ages ago, as you dont write D like C++, actually installed nim myself to try it.
Nim is going to be good though, as they seem to like control over just about everything
>>
Write a program that finds brackets/parenthesis in proper order:
>>>abc (def ijk(alm) aecs(dia))
Should print
1. alm, dia
2. jik(alm) aecs(dia)
3. (def ijk(alm) aecs(dia))
4. abc (def ijk(alm) aecs(dia))
>>
>>61461859
I'm working on a robot that can stream to twitch and be controlled by twitch chat.

a few people here watched me finish the soldering on the chassis last time.

twitch/fmdud
>>
>>61466699
Is that a SICP parser exercise?
>>
Donald Trump is going to end IDRIS once and for all
>>
So I'm new to Swift

Fuck auto layout and everything else. I can't even put a goddammed button on the screen without it resizing and floating all over the place. Adding constraints makes it worse.

This is the worst
>>
I'm the dude who was designing a TCG framework in a previous thread. Progress: basic UI is coming along, you can drag cards around and stack them. Still working out some of the details. I haven't written graphical code in a long time...

Implementation is in C++ with SFML. <optional> is fucking great.
>>
>>61466866
What's your plan for card interactions?
>>
>>61466730
cat has made an appearance on stream
>>
>>61466886
It's a framework, so the game rules are entirely programmable. Cards can interact however you want
>>
>>61466866
Post github link.
>>
>>61467239
https://gitla.in/iitalics/opentcg/tree/cplusplus
>>
>>61466836
There are plenty of issues with swift and its ecosystem but the layout strategy is pretty powerful. It's a lot to take in at once but it's the product of an unimaginable number of developers hammering on every unexpected usecase you can think of.
>>
D vs Nim vs Go

which is best?
>>
>>61467581
Nim = D > trash > Go
Seriously, Go is embarrassing
>>
>>61467598
>>61467581
C is better than all of them.
It combines D's imperative capabilities with Go's intelligent decision not to include generics.
>>
>>61467581
>>61467598
>>61467707

D is a meme, C is great if you're making money in it, Go is easy and fast and teaches OK programming practice with the added benefit of being able to write useful software in it
>>
>>61467707
>It combines D's imperative capabilities
And D can call C while not being C so it wins.
>>
>>61466866
What are you going to use for scripting the rules? You better choose Scheme.
>>
>>61467745
No, D can call C while not being C, therefore it has everything C has plus more, therefore it has too much because C has the objectively perfect quantity of things and anything more is too much. So C wins
>>
>>61467745
Fucking everything can call C. C was designed to be easy to call.
>>
>>61467762
>its the "my language doesnt have it so its bloat" argument
Like clockwork
>>
>>61467746
Yes, it's going to be a restricted subset of Scheme!
>>
>>61467777
If they have to do more than import a lib/module its trash.
>>
I just like C for its simplicity.
I don't fault anyone for wanting to program in another language; I just simply can't wrap my head around most of them.
>>
>>61467793
Why would you bother restricting it? Scheme's already minimal. That would just make your engine less flexible.Just throw a whole implementation in.

And it's a card game engine so performance isn't a super key priority.
>>
>>61461859
.NET based LAN file sharing thing. UI mostly works. It can detect other machines and send / receive files. So far I have gotten speeds around 35-49MB/s. I guess I was going for speeds faster or around USB so its not too bad. Code is abstract enough to change protocol from TCP to anything else. Any suggestions?
>>
>>61467813
Performance is definitely not a priority. But it's serverless so both clients need to run code in sync, so I don't want to have many features that could cause nondeterminism. I'll likely end up with most of scheme anyways, sans inexact floating point numbers, PRNGs (there will be a few primitives for synchronized random numbers), and maybe some mutation. Does standard Scheme include hash tables and sets?
>>
File: bg2.jpg (146KB, 600x869px) Image search: [Google]
bg2.jpg
146KB, 600x869px
>>61461859
At my wits end here, can someone smarter than me lend their brain? Trying to make a circle that moves around based on the keys you press. Here is my code.
public class Circle extends Figure {
private int x;
private int y;
private int diameter;

public Circle(int x, int y, int diameter) {
super(x,y);
this.diameter = diameter;
}

@Override
public void draw(Graphics graphics) {
graphics.fillOval(x, y, diameter, diameter);

}

}

public class DrawingBoard extends JPanel {
private Figure figure;

public DrawingBoard(Figure figure) {
super.setBackground(Color.WHITE);
this.figure = figure;
}

@Override
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
figure.draw(graphics);
}

}

package movingfigure;

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class KeyBoardListener implements KeyListener {
private Component component;
private Figure figure;

public KeyBoardListener(Figure figure,Component component) {
this.component = component;
this.figure = figure;
}

@Override
public void keyPressed(KeyEvent e) {
int pressed = e.getKeyCode();
if(pressed == KeyEvent.VK_LEFT || pressed==KeyEvent.VK_A)
figure.move(-5, 0);
if(pressed == KeyEvent.VK_RIGHT || pressed==KeyEvent.VK_D)
figure.move(5,0);
if(pressed == KeyEvent.VK_UP || pressed==KeyEvent.VK_W)
figure.move(0,-5);
if(pressed == KeyEvent.VK_DOWN || pressed==KeyEvent.VK_S)
figure.move(0,5);

component.repaint();
}

@Override
public void keyTyped(KeyEvent e) {
}


@Override
public void keyReleased(KeyEvent e) {
}

}


(1/2)
>>
>>61467707
>Go's intelligent decision not to include generics.
>t. brainlet
>>
File: 4 - O75QOx7.gif (24KB, 640x400px) Image search: [Google]
4 - O75QOx7.gif
24KB, 640x400px
>>61467943
public class UserInterface implements Runnable {

private JFrame frame;
private Figure figure;


public UserInterface(Figure figure) {
this.figure = figure;
}

@Override
public void run() {
frame = new JFrame();
frame.setPreferredSize(new Dimension(500, 800));

frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
createComponents(frame.getContentPane());

frame.pack();
frame.setVisible(true);
}

private void createComponents(Container container) {
DrawingBoard drawingBoard = new DrawingBoard(figure);
container.add(drawingBoard);
frame.addKeyListener(new KeyBoardListener(figure,drawingBoard));

}

private void addListeners() {
}

public JFrame getFrame() {
return frame;
}
}

(2/2)

Figure is just an abstract class with the move(x,y) methods and all that
>>
>>61467740
>C is great if you're making money in it,
That'd be Java, thanks
>>
>>61467783
>Like clockwork
Yes. Exactly like clockwork, because clockwork is also bloat when you could be using subatomic moving parts instead of macroscopic ones. Very good analogy.
>>
>>61467962
C is bloated, use brainfuck
>>
>>61467953
Whats the issue here lad so im not just blindly looking for problems?
>>
>>61467971
This
>>
>>61467971
Brainfuck is bloated though, use ASM.
>>
>>61467971
I prefer to type straight into binaries.
>>
>>61468000
checked.
C bloatfags BTFO
>>
File: wow its a fucking circle.png (5KB, 500x500px) Image search: [Google]
wow its a fucking circle.png
5KB, 500x500px
>>61467982
>Whats the issue here lad so im not just blindly looking for problems?
Ah yeah, that would probably help. Well, everything seems to work properly but the circle drawn (pic related) doesn't move when keys are pressed. I used System.out.println() to print out the key, it is indeed reading the pressed keys correctly, I set it to redraw every time a key is pressed, so I can't understand why it isn't updating at all.
>>
>>61467875
>standard
No. SRFI 69 has hash tables, and SRFI 1 has some set operations. You better have SRFI 1 in your implementation. Luckily you can implement most of it yourself very easily.

Hash tables aren't really a priority for your purpose though. Just use alists.

Sets: https://srfi.schemers.org/srfi-1/srfi-1.html#SetOperationsOnLists
Alists: https://srfi.schemers.org/srfi-1/srfi-1.html#AssociationLists
Hash tables: https://srfi.schemers.org/srfi-69/srfi-69.html

The simplest way get rid of floating point numbers and random number generation from a scheme is to just
(define (cos . args) (error "You aren't allowed to use floating point number operations"))
>>
>>61466730
>>61466908
What are you using the raspberry for?
>>
>>61467762
>that mental gymnastics
>>
>>61468016
easy way to debug is to print out its coordinates.
If they arent updating its a keyboard logic problem, if they are and its not moving you have a render problem.
>>
>>61468007
All these brainlets can't even hello world without their fancy compilers.
>>
There should be a physical lambda calculus compiler that works by maneuvering a robotic arm to build or rearrange a circuit that solves the computational problem independently of any kind of CPU
And then you would bootstrap it by implementing that same arm structure in lambda calculus and compiling it to build and activate an arm which would then tear down the original arm for resources and take its place as the peripheral
And then once it's bootstrapped you could write a kernel in pure lambda calculus and compile it with the resources thus obtained
And then have the arm remove itself from the computer and plug itself into that physical kernel instead
And bam you have a new kind of computer that's functional instead of imperative and runs programs by modifying its own hardware
>>
>>61468000
Binaries?
Bitch please.
Machine language is bloat.
I write my programs by physically sequencing them on a breadboard.
My programming environment is so unhosted you don't even need a CPU. You just plug it in and it runs.
It just werks
>>
>>61468020
Hm. Are you suggesting I use an existing implementation (Guile?) and try to prevent the user from using floats?
>>
>>61468039
Ah yeah, sorry meant to say I did that also. The coordinates are indeed being changed as expected, so the problem is rendering. The question is why/
>>
>>61468038
C people are mentally ill
>>
>>61468056
Get a hold of this guy!
>breadboard
When I really want to optimize my machinery I enjoy configuring my analytical engine based on Babbage's design.
>>
>>61468020
In MIT Scheme this is just
(define-syntax delvar
(syntax-rules ()
((_ var)
(unbind-variable (the-environment) (quote var)))))
(delvar cos)
>>
>>61468065
Whats your main loop look like?
>>
Anyone here has some android custom ROMs experience?

I fell for the Xiaomi meme and I don't like this miuiu shit. How hard is to port lineage OS to new unsupported phone?
>>
>>61468036
streaming to the mac from the camera, hosting the irc bot that takes input from chat, and sending data to the arduino via serial.
>>
>>61468063
Yeah. Though my scheme distro to shill is chicken.

Just bind over all the floating point number generators and make any tie ins to the networking check for exact numbers, then make sure the full numeric tower is enabled so overflowing numbers become bignums rather than floats.

>>61468119
Well obviously you could make a macro. Though I think specifically saying why it's disabled is helpful. Is MIT scheme actually useful? It seemed so stripped down, just an interpreter to go with the book.

(define-syntax disable (syntax-rules () ((_ proc ...) ((set! proc (lambda args (error "You cannot use floating point operations or non-engine random number generators")))...))))
>>
>>61468111
>engine
Bloat.
Generics are bloat.
An engine is generics.
It's also I/O, which is evil.
To briefly explain why engines (and also CPUs) are both generics and I/O:
>you have to tell it what to do (input)
>it's capable of doing it even though what exactly it is that it has to do has been dynamically specified (generics)
>the result of what it's done has to go somewhere (output)
This is why plain circuits are far superior. No input or output; parameters, result, and process are all embodied together in the very structure of the thing. No ugly bloated generics; it can only do what there is for it to do, because that's what it was made to do, and there's nothing you can do short of re-"write"-ing it that can change that.
For a similar design concept in mechanical engineering, try Rube Goldberg machines on for size.
>>
>>61468154
I've used Chicken before to create standalone programs, it was very nice, but never used it embedded in C or C++.
Also you can still use floating point literals and basic numeric operations on floats... Maybe I'll just put a disclaimer warning to never use IEEE floats (I doubt you'd ever need to use floats ... it's a gotdamn card game).
>>
>>61468119
>(unbind-variable (the-environment)
What the fuck?
What the FUCK?
NO!
You can't fucking DO that!
WHAT THE FUCK!
...
I'm never touching Scheme again. It's ruined. It's fucking ruined. That's it, it's done, I'm done, fuck it, no more Scheme.
>>
>>61468172
>Goldberg machines
no thanks david
>>
>>61468205
I mean you could create floating point literals. But all you have to do is make it clear not to use floats.

Hell if you really wanted to, you could find the part of the parser that interprets floats and replace it with an error call.

I fucked up my macro. That's what I get for writing it in a comment rather than a repl
(define-syntax disable
(syntax-rules ()
((_ proc ...) (begin (set! proc (lambda args (error "I'm afraid I can't do that."))) ...))))
>>
Why is Ruby so /comfy/?
I can't believe Ruby isn't as popular as other languages like Python.
>>
>>61468274
I never got the comfiness factor.
And rails ironically killed it.
>>
>>61468274
Idris is simply the superior choice mine frendo
But I will give Ruby credit where credit is due for being the only implementation of POO I've ever seen that isn't disgusting street shitter garbage
>>
>>61468245
In Racket you can redefine datum, by reimplementing the macro #%datum, it's pretty neat.
>>
>>61468274
Shut up. This is like the 4th time you're posted this.
Ruby is shit, and nobody likes it or him.
>>
Why is C so /comfy/?
I can't believe C isn't as popular as other languages like C++.
>>
I still hold a firm belief that C is the comfiest language alive.
>>
>>61468341
C is the more popular language though.
The Sepples shit eaters just meme harder.
>>
>>61468345
>header guards everywhere
>casts everywhere
>*****'s everywhere
>printf in general
>pre-prop ugliness

C is one of the ugliest languages desu.
>>
>>61463501
Why don't you just generate it using sh/python/whatever during your build and pass it using the -D compiler switch?
>>
>>61468359
>printf in general
What's wrong with printf?
>>
>>61468359
>>casts everywhere
No? Casting is very uncommon in C.
>>*****'s everywhere
Not everybody is so stupid that they can't understand double indirection.
>>printf in general
printf is magic, anon.
>>pre-prop ugliness
It's better than having no preprocessor at all, like many languages.
>>
>>61468385
Most casting I've seen is using from int to float casts and void*s to what you need.
>>
>>61468381
Theres no simple way to just print a variable when everything in C is a formatted print.
@61468385
>malloc is very uncommon in C
(You)
>>
>>61468341
>>61468345
Idris is comfier
>>
>>61468065
Have you tried following your repaint calls down to draw to see if they actually happen, and if x/y were updated properly?
>>
>>61468392
>int to float
Unnecessary most of the time.
>void*s
There is literally no good reason to cast void pointers in C. That is pure C++ retardation.

>>61468395
>>malloc is very uncommon in C
As stated above.
>>
>>61468396
Even though i love them, functional languages have a high-learning curve before they become comfy. You do a lot more stumbling and feel like youre lost compared to a regular language.
>>
>>61468395
>No simple way to just print a variable
puts()?
>>
Haskell program to count the number of possible tic-tac-toe outcomes:
main :: IO ()
main = print $ games False $ listArray (1,9) $ Nothing<$[1..9]

games :: Bool -> Array Int (Maybe Bool) -> (Int,Int,Int)
games turn arr = fromMaybe play $ score arr
where play = foldr add (0,0,0) moves
add (a,b,c) (x,y,z) = (a+x,b+y,c+z)
moves = map doMove $ filter (isNothing . (arr!)) $ [1..9]
doMove i = games (not turn) $ arr // [(i,Just turn)]

allIs :: Eq a => [Maybe a] -> Maybe a
allIs (x:xs) = x >>= fold
where fold y = foldlM eq y xs
eq b a = a >>= \v -> if b==v then Just b else Nothing

score :: Array Int (Maybe Bool) -> Maybe (Int,Int,Int)
score arr
| isNothing result && not nomoves = Nothing
| otherwise = Just (eq $ Just False, eq $ Just True, eq Nothing)
where eq x = if x == result then 1 else 0
nomoves = all isJust $ elems arr
result = asum $ allIs . map (arr !) <$> streaks
streaks = [1,5,9]:[3,5,7]:rows++cols
where rows = [[i..i+2] | i<-[1,4,7]]
cols = transpose rows

Shows (X wins, O wins, ties):
$ runghc ttt.hs
(131184,77904,46080)
>>
>>61468435
limited support, how about for non chars?
>>
>>61468395
How the fuck isn't printf "simple"?
>everything in C is a formatted print
Ignoring the fact that puts exists, that is a good thing.
>>
>>61468395
What exactly do you think other languages are doing when you randomly pass it a variable in the print command?
>>
>>61468460
printf would be perfect if it had optional formatting.
>>
>>61468456
>non chars
>C is bad because I cant easily print twitter poop emojis!
>>
>>61468472
>optional formatting
What the fuck are you talking about?
>>
>>61468476
Actually, UTF-8 will pass through basically all of the C string functions with absolutely no problems.
>>
>>61468471
I know abstracted formatting still happens, just speaking about higher level ease of use.
>>61468482
printi(x,y,z);
Instead of
printf("%d %d %d", x, y ,z);

when order isnt necessary.
>>
>>61468359
>header guards
Simple and pretty elegant solution to a problem

>casts everywhere
Pretty much the only time I ever see casts is going between floats and ints

>pointers
It's exclusively your problem if pointer and address manipulation hurts your tiny brain

>printf in general
Better to have it than let all the retards print raw object reference values because they can't be bothered to use formatting in their managed languages

>pre-prop ugliness
How is that a bad thing whatsoever?
>>
@61468506
>
#ifndef <token>
// stuff
#else
// stuff
#endif


>pretty or elegant
(You)
>>
>>61468503
>printi(x,y,z);
What's the fucking point? Why would the be useful?
>>
>>61468503
That's not a very realistic use case, even for personal projects print statements are almost always accompanied by descriptions of what the value is.
So it's more like
print("Triangle angle degrees: "+ x + " "+ y + " "+ z

vs
printf("Triangle angle degrees: %d %d %d",
x, y, z);


That is unless you decide to use a formatted print in the first language, in which case its exactly the same.
>>
>>61468519
How is that inelegant?
>>
>>61468519
>Hey whats an easy way to make this codebase portable?
#ifndef _WIN32
// set specific windows stuff
#else
// set specific linux/unix stuff
#endif

>Hey thanks bill, that's pretty fucking simple isn't it!
>>
>>61468525
>That's not a very realistic use case
I dont know, i do it a lot.
>>61468530
Because modules exist.
>>
>>61468544
>Because modules exist
What? How is that even remotely related to what we're talking about?
>>
>>61468036
>>61466908
>>61466730

Last time on the stream, we soldered the battery and motor contacts and finished assembling the robot

this time on the stream, we got streaming from the raspberry pi camera working (down to 5-6 second delay which will be hard to beat on twitch). Also, we wrote the arduino program that accepts a string through `Serial` that controls both camera servos and both motors!

Next time on the stream: Re-writing the simple IRC bot that controls the robot over twitch chat

Next next time on the stream: Writing a web app that averages the input from multiple people

Next next next time on the stream: Allow donation givers to control the robot solo at $1 per 5 minutes!
>>
File: 1483521292478.png (3KB, 306x269px) Image search: [Google]
1483521292478.png
3KB, 306x269px
>>61468525
I have no idea why the second snippet has a newline in it.

>>61468544
>i do it a lot.
I'm not gunna say you're wrong because that's a subjective use case, but unless its a very small script or program most print statements aren't just raw data, because that's very hard to read or make useful in most cases.
>>
>>61468506
>Simple and pretty elegant solution to a problem
that only exists because of C's build architecture
>Pretty much the only time I ever see casts is going between floats and ints
pointers get cast all the time in C, especially to/from void pointer but also between other types. It's not uncommon to make "dereferenceable" structs that contain a pointer as their first element, too, which necessitates a cast.
>Better to have it than let all the retards print raw object reference values because they can't be bothered to use formatting in their managed languages
no need to make up some half baked retarded solution as if that's how other languages work. he's suggesting a better solution than dynamically popping values off the stack based off a string when you already know the types you're printing with at compile time
>How is that a bad thing whatsoever?
you can break the syntax in arbitrary ways and have to look at preprocessor output to really see what's going on
>>
>>61468542
Meanwhile
version(Windows)
{

}

version(Posix)
{

}

version(Debug)
{

}
>>
>>61468547
>>61468544
Oh wait, I thought you were replying to my other post about printi.
Nevermind.

Anyway, the preprocessor does a lot more than just that sort of shit.
>>
>>61465315
Is this what you're looking for? https://doc.rust-lang.org/stable/book/second-edition/ch16-03-shared-state.html#atomic-reference-counting-with-arct
>>
>>61468561
>that only exists because of C's build architecture
Yes, and it's still miles ahead of most other languages methods of checking and determining for that kind of bullshit. So that's really just another brownie point for C.

>pointers get cast all the time in C, especially to/from void pointer but also between other types
Yeah, and the people doing it are generally completely fucking retarded. Void casts should be rarer than you getting pussy. A bad programmer will do shit wrong in any language, no matter how retard-proof you make it (see: ruby, python, C#, java)

>no need to make up some half baked retarded solution as if that's how other languages work
If you're not paying attention that's the case in virtually all OOP languages.

>you can break the syntax in arbitrary ways
Fair, although that arguably still just comes back to the individual rather than the language.
>>
>>61466013
>Rust
> Handholding
More like it grabs your ass and starts literally wipping you with the borrow-checker until you get in shape or give up.
>>
>>61468635
Dont forget the part where it also apologizes for being rude and compliments you on your NON_STANDARD coding style.
>>
>>61468437
> eq b a = a >>= \v -> if b==v then Just b else Nothing

using MonadComprehensions and operator sections

eq b = (>>= \v -> [ b | b==v ])
>>
>>61468617
>Yes, and it's still miles ahead of most other languages methods of checking and determining for that kind of bullshit. So that's really just another brownie point for C.
I fundamentally disagree, but I have to go to sleep now so I'm giving up on this

>If you're not paying attention that's the case in virtually all OOP languages.
virtually all OOP languages have tostring methods that make it so you can print objects automatically. The only circumstances that you get pointers are when you printed something that doesn't have a tostring implementation (often because it doesn't make sense or may have unintended side effects). In Java it's toString, Python it's __str__, ruby it's to_str, and so on.
>>
>>61468635
No, I said handling.
It's painfully awkward, I'd rather use C++ with raw pointers atm.
(and I use Haskell)
>>
>>61468705
>virtually all OOP languages have tostring methods that make it so you can print objects automatically
Yes but if you have to call toString methods then you're not better off than just calling a formatting print function to begin with, which is my point.
>>
>>61468654
*SLAP*
I'm so sorry anon
*WAPASH*
I may be kind, but -
*SWISH*
You're
not
allowed
to mutate
that
*WAPASH*

> Your ass is tender now
>>
>>61468744
>violence
Nah, theyd get a non-stern talking to about the dangers of being too imaginative with their programming.
>>
>>61468706
Huh, desu most of the time I don't do pointer arithmetic, so i'm not sure where you're coming from.
>>
File: 54657129_p0.png (481KB, 777x777px) Image search: [Google]
54657129_p0.png
481KB, 777x777px
Guys guys~
Today I was learning at Codeacademy and I was asked to set codes to deal with stock problems

def compute_bill(food):
total=0
for key in food:
if stock[key]>0:
total+=prices[key]
stock[key]-=1
return total

This way I can't sell stuff after it's out of stock. But it seems to me this formula only deals with situations in which you buy one fruit at a time, and I was thinking of more complex math equations.
For example, If I was to input that I want to buy 8 bananas but there's only 6 in stock, will the program still work and count the right price?
Are computers supposed to work this way?
>>
>>61461886
Shit taste.
>>
>>61468693
That's a good idea, thanks. Following on that route, but with a slight change so it doesn't need language extensions:
eq b = (>>= \v -> listToMaybe [b | b==v])
>>
>>61468728
but you don't have to call them, which is my point. they're called implicitly
>>
>>61468763
> Not having the experience of being wipped by borrowk
Looks like someone has only been reading and not coding...
>>
>>61468788
>they're called implicitly
Not always, which is my point.
>>
>>61468791
Rust will never touch my machine outside of the playpen. I feel dirty enough just having ffox installed
>>
>>61468766
It's not pointer arithmetic I'm complaining about
>>
>>61468798
okay, I'm not sure we're on the same page here.
can you name a language you're referring to that doesn't implicitly call tostring (but has it built into its object model/type system)?
>>
>>61468805
Keep your chaste ass then, but don't bother whining about rust until you tasted it's borrow checker.

And that involves more than just pissing on the playground for lulz
>>
>>61468812
Java and C# are the most common offenders, Ruby and Python if the person doesnt know what they're doing.
If you haven't specifically implemented a toString method in non-standard objects then it defaults to printing the inherited Object.toString method, which usually just means "print the type and its reference"

And even if you HAVE implemented a toString method, at least in C# (iirc), it doesn't implicitly call it. It defaults to the Object.toString
>>
>>61468811
What is it then? Lifetimes? Borrowing?
>>
>>61468868
yes, that whole thing
>>
>>61468874
Ah, my sympathies then.
>>
Twitch /naysayer88
Q&A, programming related with Jonathan Blow
>>
>>61468886
ill just wait for the youtube upload.
Is it all QA or is he doing something interesting?
>>
>>61468886
>Jonathan Blow

Why do people hold this guy's opinion so highly?
>>
>>61468855
okay, then I understand where we disagree. that's what I was saying though, obviously you have to define the tostring method for it to give useful output for any given object. and I can't imagine c# reaching up the inheritance tree and calling object's tostring instead. https://stackoverflow.com/questions/18219273/explicit-vs-implicit-call-of-tostring

anyway I've got to go to sleep
>>
>>61468947
because he's opinionated and has a big mouth
>>
>>61468947
He's wildly overrated as a game designer, but hes actually okay to watch as a programmer even if some of his opinions are shit. And theres really no one else as e-famous working on a language. If you have anyone though, id love more people to watch.
>>
>>61468886
Fuck off nv
>>
>>61468914
It's not a demo. It's just a QA after a game programming stream.
>>61468947
Because he's proven to be a good programmer.
And he gets attention for doing passion projects in games that are highly revered in addition to being quite radical compared to the hordes of programmers who have been supporting OOP for decades.
>>61468976
I don't agree. As someone who likes puzzle games I find it difficult to think of serious competition.
>>
The only times I ever write C is when I need void pointers, pointer arithmetic, weird casts, etc. I would use a different language if I wanted to do regular application programming.
>>
>>61468993
>I find it difficult to think of serious competition.
Are you joking?
the talos principle BTFO TW in every single regard.
TW is just pure logic puzzles while TTP actually has 3d elements and time as well. And the puzzles actually do well to explain themselves unlike blow thinking everyone will just implicitly get it.
>>
>>61469003
>Void pointers
Ok?? That's not a context though..
> Application Programming
I don't follow
>>
>>61468993
>jonathan blow fan is an anti-OOP shitter
how surprising
>>
>>61469045
JBlow isnt even anti-OOP as Jai has POO. Hes just anti-sepples.
>>
>>61469066
he says he doesn't like OOP, but fuck knows what OOP means exactly
>>
File: 1497133960332.jpg (57KB, 339x272px) Image search: [Google]
1497133960332.jpg
57KB, 339x272px
>Want to get into graduate school
>Every time I discuss anything with anybody I walk away feeling like an idiot
I should just give up and be a code monkey shouldn't i
>>
>>61469088
Go to sleep and get off 4chan faggot, start with that. Then study.
>>
>>61469088
>Oooooh, nooooo, I will always have room for improvement, and accidentally showed this obviously human fact to strangers. I should just give uppppp

Man up, fag
>>
File: Problem 42 Project Euler.png (62KB, 1010x295px) Image search: [Google]
Problem 42   Project Euler.png
62KB, 1010x295px
this was easy

#!/usr/bin/python3

def get_triangle(n):
return int(0.5*n*(n+1))

fname = "p042_words.txt"

max_sum = 0
for i in range(1, 27):
max_sum += i

triangle = []
for i in range(1, max_sum+1):
triangle.append(get_triangle(i))

with open(fname) as f:
content = f.readlines()

count = 0

for word in content[0].split(','):
tmp = word.split('\"')[1]
tmpsum = 0
#print(ord(tmp[0])-64)
for i in range(0, len(tmp)):
tmpsum += int(ord(tmp[i])-64)
if tmpsum in triangle:
count += 1


print(count)
>>
>>61469088
>graduate school for programming
why would you go into academia in programming
there's billions of dollars in the private sector just up for grabs, it's never been a better time to not be in the public sector
>>
new
>>61469216
>>61469216
>>61469216
>>
>>61469021
>talos principle
I just found that one too simple. Some of it was neat. Like the level with the pyramid.
But that's not the common case. TW has that all over.
>>
>>61469282
>I just found that one too simple.
Really? How far you'd get?
Because i felt the same for TW.
>>
>>61469296
I finished it and completed most of the bonus content.
TW really shines in its side content though.
Thread posts: 319
Thread images: 24


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