[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: 321
Thread images: 22

File: 1490058592795.jpg (203KB, 802x854px) Image search: [Google]
1490058592795.jpg
203KB, 802x854px
What are you working on, /g/?
>>
The only three programming languages you need to know are Scheme, Shen, and Idris.
>>
>>61843396
but muh scala
>>
The only three programming languages you need to know are C, x86 assembly, and Emacs Lisp.
>>
>>61843406
not scalable
>>
The only three languages you need to know are Rust, Rust, and Rust.
>>
redpill me on doing system technician degree.
>>
File: Carlos.jpg (220KB, 1280x720px) Image search: [Google]
Carlos.jpg
220KB, 1280x720px
>>61843419
>>
>>61843440
wtf is a "system technician"?
is it an assistant sysadmin role?
>>
>>61843453
It's really not, look at how slow compilation is for any medium-size scala project
>>
>>61843465
https://en.wikipedia.org/wiki/Information_systems_technician
>>
>>61843506
OK I see, this is probably the wrong thread for that
>>
Are there any reasons to use Python beyond "it's easy for people who don't have much experience programming"?
>>
>>61843562
it has alot of very optimized math/science libraries

other than that?
no, not really
>>
>>61843562
It's good at destroying the minds of innocent would-be programmers
>>
>>61843602
>Very optimized
>python
"World's fastest snail"
>>
>>61843656
the libraries are made in C
>>
>>61843678
>Snail contracts a cheetah to do all the work for him
>wow isnt the snail great
>>
>>61843693
pretty much
>>
Is "gradual typing" a useless meme?
>>
>>61843562
It reads like pseudocode, it has libraries for everything, and it's better than Bash scripting for complex tasks
>>
>>61843693
The Python is glue code you dip
>>
>>61843745
Haskell reads like pseudocode too.

Show me Python's equivalents of lens and mtl.
>>
File: 1496063149072.jpg (41KB, 500x383px) Image search: [Google]
1496063149072.jpg
41KB, 500x383px
>>61843412
>x86
drake.jpg

>>61843693
The snail is a genius.
>>
>>61843745
>Python reads like pseudocode
Python coders are pseudo programmers
>>
>>61843768
Are you seriously trying to imply that fucking Haskell, the language with no mutability, is better for scripting tasks than Python?

I like pure functional programming as much as the next autist but I'm not gonna use Haskell for scripting tasks

>>61843805
>Python coders are pseudo programmers

Gotta admit I kek'd
>>
>>61843678
Or Fortran, like numpy.
>>
>>61843819
>Are you seriously trying to imply that fucking Haskell, the language with no mutability, is better for scripting tasks than Python?
Yes. The language works with you a lot more than Python does.
>>
>>61843819
easily better
>>
>>61843826
>works with you a lot more than Python does
Fucking kek.
>>
>>61843845
Please elaborate, now you've got me interested
>>
>>61843851
It is easily better, because of the strong, pure type system.
You can limit exactly what scripts can do.
>>
>>61843826
>scripting
>immutability works with you
Have you ever sysadminned anything more than your GNU/Linux home network?
>>
>>61843864
Yeah static typing is nice
>>
File: 1500958474675.jpg (136KB, 850x616px) Image search: [Google]
1500958474675.jpg
136KB, 850x616px
>>61843964
>ancom
>>
So I'm trying to have python crop a jpg without any new compression on a really crappy raw image.
Is this even a possible thing with python? pillow is giving me shit.
>>
File: 1501118560603.jpg (145KB, 1200x674px) Image search: [Google]
1501118560603.jpg
145KB, 1200x674px
>>61843381
Just finished writing some scripts that simplify text for machine learning. Strips out all punctuation besides newlines and spaces, reduces everything to lowercase, then maps the cleaned-up words to integers. Feeding the software ints instead of raw text should reduce the amount of time it takes to learn spelling and common phrases. Hopefully the reduced complexity yields good results.

Also tinkering with a program that generates Ruth-Aaron numbers. The current record holder is only 3k digits long, so I'm hoping to beat that out by the end of the year. Doing it efficiently takes a surprising amount of thought, so it's a good exercise.

>>61843964
>>61843980
pls no fighting in the programming thread
>>
>>61843381
The fuck is this cringe inducing /b/ shit?
Stay the fuck in your containment thread
>>
>>61843396
dont shen and idris make eachother redundant?
And why the fuck would you ever need scheme?
>>
>>61844013
Scheme will be useful for programming emacs once it switches to being Guile-based
>>
>>61844070
But why would i ever use dynamic trash?
>>
>>61843562
Its good for things which would require bash/ shell

otherwise, its good at binding other programs together, do the work in C and the user facing shit in python
>>
>>61843381
So I picked up a python book a week ago.

never had any programming experience other than a little bit of javascript if you can count that. but that was years ago.

I am 30 pages into my second book on python now, but I feel like I am dabbling with forces beyond my understanding. Every example in the first book was just "import this module that does this neat thing and then modify the output a bit" .

I can already do the automation task I wanted to learn programing for (some one has already done most of the work), but I have a terrible feeling that I am doing every thing blind.

Reminds me of being a teenager and copy pasting things off the internet into the command line to solve problems.

This thread has made me feel even worse.
>>61843562
>>61843745
>>61843805

Should I start somewhere else?

I dont really want to work as a programmer, I just wanted to make my financial research easier. I am learning SQL next fall for work, but I dont want to be meme'd by all the IT guys for only knowing "babymode" languages.
>>
>>61844135
yes, try F#
>>
>>61844151
>F#
Ok, but Why?
>>
>>61844135
SQL is not a "babymode" language, but it's not much of a programming language either.

>Every example in the first book was just "import this module that does this neat thing and then modify the output a bit".
Yes, Python can be really bad for learning programming because of that, and as you describe in your post, such an approach doesn't teach much.
>>
File: DCGdRCMW0AQzwpW.jpg (15KB, 320x512px) Image search: [Google]
DCGdRCMW0AQzwpW.jpg
15KB, 320x512px
>>61842294
Thanks, anon. The docs seem to suggest that it's exactly what I need, so I'll try implementing it.
>>
>>61844070
>once it switches to being Guile-based
what's the eta on that?
seems like it's been "in the works" forever
>>
>>61844135
Me again.

I just ran 3 versions of a program that copied my entire hard drive into a zip file on the desktop concurrently.

One of them didnt go to desktop so now I am tracking it down.

Is there a way to test a program for syntax errors without actually running it?
>>
>>61844704
Use PyCharm Community Edition IDE, there is a debugger that should work.
>>
Directsound newbie here

//The point in the buffer at which Windows will read and play the sound buffer
DWORD play_cursor;

//The point in the buffer at which Windows will write what we want to the buffer
DWORD write_cursor;

//If allocation of this is successfull
//global secondary buffer is an LPDIRECTSOUNDBUFFER
if (SUCCEEDED(global_secondary_buffer->GetCurrentPosition(&play_cursor, &write_cursor)))
{
//do something
}



are we guaranteed to have &write_cursor > &play_cursor ?? since the buffer is cyclic its entirely possible to have it write it at lower values but its effectively ahead of the play
>>
should i memorize the C standard library?
>>
>>61844797
I am using it. let me find the debugger.
>>
>>61843396
functional baby detected
>>
>>61843412
>emacs lisp
>not common lisp
>>
>>61844973
this
>>
The only three lang you'll ever need:
C++ for actual aplications and speed
R if you need to make sense of data
Racket for fast development, creating dsls and theroetical stuff
>>
>>61845135
>C++
AHAHAHHAHAHAHHAHHAHAHAHHAHAHHA
Good joke.
>>
>>61844006
>Feeding the software ints instead of raw text should reduce the amount of time it takes to learn
But anon, ascii text is just a string 1 byte unsigend ints, if you change it to normal integers they probably become 4 byte ints on your machine.
>>
>>61845194
>doesn't know about Erlang's 8 bytes per char
>>
>>61845248
n-nani?
>>
>>61845248
>8 byte char

for what purpose?
>>
The only three languages you'll ever need
C
Assembly
WASM
>>
>>61845408
>using a bloated asm
>>
File: this_is_fine.jpg (198KB, 1572x800px) Image search: [Google]
this_is_fine.jpg
198KB, 1572x800px
>>61845408
Add Go to that list.
>>
>>61845144
If you want actual, marketable applications you pretty much have a choice betwen java and c++. I for sure won't sully my hands with java, if modern c++ is avalible
>>
>>61845611
>maketable applications
>not c

kek, keep deluding yourself
>>
>>61843562
Throwing together shit quickly.
>>
>>61845408
>not NASM
>>
>>61845402
Strings are a hack in erlang: they're lists of integers, and indistinguishable from lists of integers. The language authors didn't really care about them since erlang was designed as a dsl for telecomm.
>>
>>61845408
>not Java
>not C#
but what if you want to eat?
>>
>>61845671
Get a real job that doesn't involve being a sedentary failure if you want to eat.

Programming is just a hobby for you, right?
>>
>>61845689
>C
>Assembly
>WASM
>Programming is just a hobby for you, right?

kys
>>
>>61845668
So the same as C then?
>>
>op picture
Boycott.
>>
>>61845703
Why are you being so mean anon. Those are great hobby languages. Maybe not WASM, yet.
>>
>>61844838
You could. It's not big. You won't need most of it though.
Searching for it when you need it can be difficult though so when you find something put it in your memory.
>>
>>61844810
Check out day 7,8,9, 19 and 20
https://hero.handmade.network/episodes
>>
Hey /dpt/.
If you had a million arrays shared between functions in C, would you make them static and initialize them on main, or would you allocate arrays on the stack of main, make a singleton struct of pointers (and ints if no macros) to hold the info to iterate them, and pass the extra pointer to all functions?
>>
>>61845710
Personally, I'd probably put them on the heap and use enums to index into a static table of pointers, and to hell with the 16MB of malloc overhead. Most systems wouldn't give you that much stack anyway.
>>
I'm learning x86 assembly because I'm a retard and I hate myself.

Can someone explain to me how
pushl %ebp
pushl %esp, %ebp

is any different from
pushl %esp, %ebp

without the first line? I've been toying with it and it seems to essentially do the same thing.
>>
So i'm about to start a CS degree.

Could you guys pleas recommend me the best books and the best lectures(youtube/edx/etc)?

Most people recommend the Corme Algorithms books, but idk if this book is the best to start.

I'm already do some scripts and I've solved some problem on Project Euler using Python.
>>
I'm trying to access a certain key/value pair in a JSONarray, how the fuck do I parse the array with n amount of key/value pairs the most efficiently.
I am using java(android).

pls respond
>>
>>61846225
http://www.oracle.com/technetwork/articles/java/json-1973242.html
>>
Should I start learning Rust despite its community being made up of SJWs?
>>
>>61846297
The Rust community is far worse than SJW.
>>
File: haxxx(2).jpg (12KB, 373x304px) Image search: [Google]
haxxx(2).jpg
12KB, 373x304px
>>61843381
Working on a game in Unity.

Finished most of the code but just need to refine some parts (levels, RNG, etc.)

Also, none meme legit programming languages to learn? I've learned C, C++, C#, Python and starting with Java soon and looking into HTML.
>>
>>61846331
Also, none meme legit programming languages to learn?
To do what? Tools have purposes, strengths and weaknesses.
>>
>>61846377
>To do what? Tools have purposes, strengths and weaknesses.
When you put it that way, I guess I'm fine how I am.

I've found that C# is really good for developing apps and C++ is good for my other works so I guess I don't need to learn anything else unless it's for work or something.
>>
>>61846297

The "community" does not matter. If they bother you so much, you can start your own community of Rust programmers, or even make your own Rust compiler using GCC's backend instead of LLVM.
>>
Please post webm of loli sliding on the floor to the PC
>>
The only coding language i know is DarkBasic which basically means i need to kill myself
>>
>>61846566

Or, you know, learn a real language.
>>
>>61846579
I still have no idea which one to learn
>>
File: golang.png (124KB, 600x600px) Image search: [Google]
golang.png
124KB, 600x600px
>>61846600
Learn Go famalam.
>>
>>61846233
Thanks, was a good read.
>>
>>61846616
Learn Go the game as you learn Go the programming language. You'll become a techno zen master
>>
>>61846678
for fucks sake.
let's try this again
going through the little schemer
why did this cause my guile interpreter to hang, use 100% of one of my cores, and use up all my ram?
(define (insertL new old L)
(if (null? L)
'() ; this second ' is needed to get around shitty 4chan syntax highlighting. if it werent there, everything after this would be green
(if (not (null? (cdr L)))
(if (eq? (car (cdr L)) old)
(cons new (cdr L))
(cons (car L) (insertL new old L)))
(car L))))
>>
I can think for one good usecase for exceptions. When you have user inputted code and you wish to gently fail their execution by having the parts of the code they can touch be no-throw except for the error conditions that can occur.
What's wrong with this?
>>
>>61843381
>What are you working on, /g/?
a program to send terry davis emails from fake email addresses
[user@Homebase pycomail]$ python pycomail.py 
enter password for ((REDACTED))
Password:

send from ((REDACTED))
y/n:n

please enter from address
>[email protected]

Recipient?
>[email protected]
['[email protected]']

Please input subject.
>I Am The Cardholder

please input message. Ctrl-d for EoF
Mr Davis
We have watched your operating system gain popularity

We have watched your videos with your outright disdain towards our organization.
We are watching. We have destroyed many such as you many times before and we will do it again.

Do not think for a second that your are safe.

We are watching, we are waiting and when the time is right, we will strike.

No operating system is safe from our reach.

Se vis pacem, para bellum, Mr. Davis.

connecting to server...
sending messange now
success

>>
>>61846600

Realistically, start with C, then jump into whatever you have a taste for.
>>
>>61846725
>python
>>
>>61846600
C, C++, Python, Java, C# or Ruby are all good languages to learn and they'll all go a long way.

Take a pick, I'll even write a code for you to choose one.
>>
>>61846771
>complaining
go ahead and post your 'send fake emails to terry davis' program
>>
>>61846792
Didn't mean it like that, it just seem pretty odd for a spambot since I mostly see Javascript for that type of stuff.
>>
>>61846812
>it just seem pretty odd for a spambot since I mostly see Javascript for that type of stuff.
What.
Why would anyone have any preference between JS and python for spambots specifically?
Sounds more like it's reflecting the circles you're in.
>>
>>61846812
not really a spambot, I run my own domain and wanted to make an email client to send emails with.

while I was prog'ing it i though, 'hey, why not just add a function to use an arbitrary from address and then I can play pranks on people'

sadly, I have no friends or social life and so terry davis is the only person I have ever had the opportunity to send prank emails to

a few weeks ago I sent him an email seeminly from the pope telling him that he has accomplished a great work, but god demands networkings on temple os..

idk, i really have no life
>>
>>61846832
Force of habit, I just got used to seeing it.

>>61846858
>sadly, I have no friends or social life and so terry davis is the only person I have ever had the opportunity to send prank emails to

If you want, you can just go cruise through facebook or twitter for email addresses if you want a bigger mailing list since a lot of people just leave their email out in the open.

>idk, i really have no life
Preaching to the choir.
>>
>>61846695
First of all, your function has a ton of problems, but I think your specific woe is on:
>(cons (car L) (insertL new old L)))
Where you have an infinite loop.
Look at it closely. The call to insertL is identical to the first line. If none of the parameters change in a tail call, then it's going to loop forever.
>>
>>61846898
its not that I dont see potential with this, but I dont use facebook at all, not even a fake account for browsing. I disagree with facebook on some sort of ethical/moral level and just stay away from it completely.

just out of curiosity tho, what could I send facebook/twitter users emails about that wouldnt be malicious but win oriented? I mean, its not like I could get pictures of nice titties with email right? dont most girls now do the whole text message or snapchat thing?

im up for suggestions to lively up my life by all means
>>
>>61846898
i mean realy, what do I do?

send an email to some camgirl from blacked.com like "I want you to send titty pics to this address so we can evaluate you for a new role?"
>>
>>61846947
>just out of curiosity tho, what could I send facebook/twitter users emails about that wouldnt be malicious but win oriented? I mean, its not like I could get pictures of nice titties with email right? dont most girls now do the whole text message or snapchat thing?

Just send some bogus but legit sounding email like le old chain letters of early message boards and Youtube comments.

Like say some new disease is spreading or there's a new virus going around and see how many morons actually fall for it.
>>
>>61846991
kek, idiots would actually fall for this
>>
>>61846695
>>61846945
Here is the code you probably want:

(define (insertL new old L)
(cond ((null? L)
'())
((eq? old (car L))
(cons new (cdr L)))
(else
(cons (car L) (insertL new old (cdr L))))))


#;1> (insertL 'peenus 'weenus '(my xenis weenus of course :D))
(my xenis peenus of course :D)


Notice how (cdr) is used in the tail call rather than the predicates section. In recursive functions every part is treated like a whole unto itself.
>>
File: 1500912617828.png (165KB, 517x353px) Image search: [Google]
1500912617828.png
165KB, 517x353px
>>61843381
>>
>>61843480
Scala is more suited to a different workflow where you compile much less frequently and use functional purity along with the very powerful type system to prevent bugs and guarantee correctness.
>>
The only three programming languages you need to know are Forth, K and x86
>>
>>61846054
Hey, how about you go fuck yourself? Go with the pointers.
>>
>>61846054
In that extreme case it sounds like you want globals desu.
Sadly you can't scope those well in C so you suffer a little but if you really needed to you can write a checker that just checks where they're used and if it's allowed.
>>
The only three programming languages you need to know are HTML, CSS, and Scratch
>>
Not really coding anything per se, but installing Audacity on Arch right now so I can get some basic recordings going again.
>>
Recommend books on optimization, defensive code and portability.
>>
Absolutely nothing, I'm on holiday.

I don't want to do anythin technology related, it's far too hot, and I'm not at work. Where's my beer....
>>
>>61847375
>optimization
useless
>defensive code
coq is the best tool
>portability
that's not hard, just read the documentation and do not bind your code to unspecified behavior
>>
>>61847400
I want to work on something but can't motivate myself because it's the holidays.
>>
>>61847417
It's okay anon, let the lazy flow through you, and eventually out of you. Be so lazy you'll miss work. Works for me.
>>
File: 8e8.png (8KB, 509x619px) Image search: [Google]
8e8.png
8KB, 509x619px
>Got rejected in second round
>...<
Someone pls suggest me a good movie to watch I am on suicide mode.
>>
>>61845710
>8 byte chars vs 1 byte chars

Yeah same as c dumbfuck
>>
>>61843381
whats the best way to stay focused on learning code
>coke? adderal? lab grade meth?
bad adhd and i just can seem to focus on the lesson
>>
>>61847375
>Recommend books on optimization
hacker's delight
the art of computer programming
the every computer performance book
designing data-intensive application
the performance engineering section on MSDN
>>
>>61847434
>le sad reddit man
You definitely should take suicide into serious consideration.
>>
>>61847434
The Thin Red Line
>>
I have a C socket application where I write stuff to a buffer of type uint8, then send it over the network. On Windows, compiling in debug mode produces the correct results. But with all optimizations on, it seems the buffer does not even get written. Like, I write a number to the buffer, then try to print it but it still seems to be zero.

The way I write stuff is this:
uint8 buf[512];
uint8 *mem = buf;

*(uint8*)mem = message_type_id;
mem += sizeof(uint8);
*(int32*)mem = some_value_to_send;
mem +=s sizeof(int32);

Could it really be the optimizations of MSVC that's doing this?
>>
>>61847647
>*(int32*)mem
Casting a pointer like that is invalid.
>>
>>61847647
> *(int32*)mem
Isn't it UB?
>>
>>61847434
Go watch Dunkirk, it's pretty funny.
>>
>>61847474
willpower
just bee urself :^)
>>
>>61847674
Does it matter if it's UB if it works on every platform under the sun?
>>
>>61847694
That's fucking retarded. Your program should NEVER contain UB, despite if you think you know better than a compiler. A compiler is free to assume that UB never happens and can optimise based on that.
I wouldn't be surprised if that's what's fucking you up.
>>
>>61847647
Regardless of whether this works or not, I'd suggest doing something like this instead.

#include <stdio.h>
#include <stdint.h>
#include <string.h>

struct message {
uint8_t type_id;
int32_t value;
};

int main(void)
{
uint8_t buf[512];

struct message msg = {0};
msg.type_id = 0x20;
msg.value = 0x50;

memcpy(buf, &msg, sizeof(msg));

// On the other side
struct message new = {0};
memcpy(&new, buf, sizeof(msg));

for (int i = 0; i < 5; ++i) {
printf("%x ", buf[i]);
}
printf("\n");
}


Usual disclaimers about padding, endianness, portability and all that.
>>
>>61847739
>struct message new = {0};
No just
>struct message new;
You set all the bytes of new just after. DO no set it to 0, it's fucking useless.
>>
Whats the best resource to learn C, anything out there with good structured path and good fundamentals?

My mind is shit, I need good structure or I will wander off the path. Also my mind thrives on the how and why, not just "take my word for it and do this" which is why im struggling I guess.
>>
>>61847647
Wrap the cast in an additional parenthesis, because I'm not sure what takes precedence.

uint8 buf[512];
uint8 *mem = buf;

*((uint8*) mem) = message_type_id;
mem += sizeof(uint8);
*((int32*) mem) some_value_to_send;
mem += sizeof(int32);


Also, I'm unfamiliar with the uint8 and uint32 types, are those MS versions of uint8_t and uint32_t ?
>>
>>61847739
What if the message has arbitrary sized values in arbitrary order? How it is properly done in this case?
>>
>>61847801
Oh, int8 and int32 are just my typedefs for stdint's uint8_t and int32_t.

What's weird here is that this works in debug builds, but not in optimized versions. Even when I declare everything volatile.
>>
>>61847805
Not him, but either define a maximum message size, or use dynamically sized structs (which is pain on the receiving end, as you must read the size first).
>>
>>61847852
You need to post the actual code, because I'm suspecting that the issue is not in the simplified part you posted, but rather something else.

Compiler optimisations should not remove memory writes just like that.
>>
>>61847739
You can't do that. If a struct looks like this:
struct s
{
uint8 num_a;
int32 num_b;
};
...most compilers will align the first uint8 to be 4 bytes long (meaning sizeof(s) is in fact 8). And yet, nothing guarantees that's the way it will be on another platform.
>>
>>61847865
I guess that's why he added the "usual disclaimers about padding, endianness, portability and all that" sentence below.
>>
>>61847805

II suppose you mean for example a message that may have a length as part of some header. You would separate out the header (which will pretty much be guaranteed to be fixed, because its a header) and read the dynamic part separately.

>>61847865
Correct, hence why I stated to consider padding, endianness etc. You could use the `packed` attribute in gcc and that, but even that has issues as far as I'm aware on platforms which don't handle unaligned access for you like x86 does.
>>
Why does autotools break backwards compatibility?
Why do the gnutls developers break the ABI?
Why can't I compile the same codebase with a newer version of GCC?
Why is everything full of compiler warnings?
>>
>>61847861
>Compiler optimisations should not remove memory writes just like that.
Actually, when you violate strict aliasing, they can.
void fn(int *i, float *f)
{
*i = 10;
*f = 0;
return *i;
}

It's perfectly valid for a compiler to optimise this as
void fn(int *i, float *f)
{
*i = 10;
*f = 0;
return 10;
}

even if you're a stupid fuck who might call the function like
int i;
fn(&i, (float *)&i);
>>
>>61847891
>void fn
int fn I mean.
>>
>>61847891
>when you violate strict aliasing, they can.
Good point.
>>
>>61844838
Not memorize, but if you want to know it read the glibc manual. It covers the standard library, most of POSIX and some GNU only stuff. Has a lot of examples too.

https://www.gnu.org/software/libc/manual/html_node/index.html
>>
>>61847861
Its spread over pretty far out but I can scrape up the pieces:

struct byte_buf_t
{
uint8 *mem;
int num_bytes;
int max_bytes;
};

#define BBUF_INITIALIZER(mem, max) {(mem), 0, (max)}
#define BBUF_FREE_SPACE(buf) ((buf)->max_bytes - (buf)->num_bytes)

static inline void *
bbuf_reserve(byte_buf_t *buf, int num_bytes)
{
if (BBUF_FREE_SPACE(buf) >= num_bytes)
{
uint8 *ret = &buf->mem[buf->num_bytes];
buf->num_bytes += num_bytes;
return (void*)ret;
}

return 0;
}

typedef uint8 swmsg_type_t;
#define SWMSGTSZ sizeof(swmsg_type_t)

#define WRITE_SWMSG_TYPE(mem, val) \
*(wsmsg_type_t*)(mem) = (swmsg_type_t)(val); \
(mem) = (uint8*)(mem) + sizeof(swmsg_type_t);

#define WRITE_UINT8(mem, val) \
*(uint8*)(mem) = (uint8)(val); \
(mem) = (uint8*)(mem) + sizeof(uint8);

typedef struct
{
uint8 result;
} swmsg_init_data_reply_t;

#define SWMSG_INIT_DATA_REPLY_SZ sizeof(uint8)
#define SWMSG_INIT_DATA_REPLY 7

static inline int
swmsg_init_data_reply_write(byte_buf_t *bbuf, swmsg_init_data_reply_t *s)
{
uint8 *mem = bbuf_reserve(bbuf, SWMSGTSZ + SWMSG_INIT_DATA_REPLY_SZ);
if (!mem) return 1;
WRITE_SWMSG_TYPE(mem, SWMSG_INIT_DATA_REPLY);
WRITE_UINT8(mem, s->result);
return 0;
}

/* Then the actual code: */
swmsg_init_data_reply_t rs;
rs.result = 1;

uint8 mem[SWMSGTSZ + SWMSG_INIT_DATA_REPLY_SZ];

byte_buf_t rb = BBUF_INITIALIZER(mem,
SWMSGTSZ + SWMSG_INIT_DATA_REPLY_SZ);

assert(swmsg_init_data_reply_write(&rb, &rs) == 0);

printf("%u\n", (uint)mem[0]); /* This prints "0" here with optimizations on, and 7 in debug mode. */
>>
>>61847950
clang, gcc and tcc all give me 7 with and without optimizations for this code.
>>
>>61847950
Have you printed out the pointer addresses in release and debug builds?

Add a
printf("addr=%p\n", mem);
between each statement in swmsg_init_data_reply_write
>>
>>61848006
It works for me on GCC. Juts not on MSVC (Visual Studio 2015).

>>61848018
I haven't, could try that.
>>
>>61848030
>MSVC
Why the hell would you use that?
>>
>>61848064
Because its a cross-platform application and while debugging, even the server runs on a Windows machine because that' easier.
>>
File: thinkpython2.jpg (32KB, 250x328px) Image search: [Google]
thinkpython2.jpg
32KB, 250x328px
>>61844135
Wich book did you read?
I highly recommand you the "Think Python 2e" book, it's free and the exercices are really fun if you like maths : http://greenteapress.com/thinkpython2/thinkpython2.pdf
>>
>>61848086
Just target clang or some shit for your winmeme needs.
MSVC is a horrible C compiler that doesn't even have proper C99 support.
>>
>>61848030
>I haven't, could try that.
What's the result of this?
>>
>>61848102
Well, its just the compiler that's installed on all of the uni PCs.

>>61848110
It seems as if the whole inline function that does the writing gets left out, because adding prints inside it just prints nothing (even before the if-statement that makes it return early.)
>>
>>61848185
Actually, it was probably just me being idiotic. The function is called inside an assertion, so...
>>
>>61848185
>It seems as if the whole inline function that does the writing gets left out, because adding prints inside it just prints nothing (even before the if-statement that makes it return early.)
Of course, because you're calling it from within an assert statement, which is by default left out in Visual Studio release builds, whereas clang and gcc requires you to set the NDEBUG macro in order to leave out asserts.

Move the call to outside an assert and it will work.
>>
>>61847647
>>61848197
Yeah, that was it, the function was never compiled because it was called as a parameter of assert(). Brb, kyssing. Thanks for the help.
>>
>>61843439
Fgt detected
>>
File: what_did_they_mean_by_this.png (261KB, 1000x820px) Image search: [Google]
what_did_they_mean_by_this.png
261KB, 1000x820px
What did they mean by this?
>>
>>61848635
O_DIRECT behaves differently on Linux than it used to do, which is why manual flushing and access advisement are needed.
>>
>>61846725
nice messange bruh
>>
>>61843381
has anyone read How to Design Programs? I am thinking of reading it before SICP, since I am afraid I won't get as much as I could from SICP if I read it right now.

is it going to get too repetitive reading both? or is it unnecessary to read HtDP and should I just take my time and "forcefully" learn SICP the "hard way"?
>>
is this valid bash?
cmd=echo "test"
$cmd
>>
>>61848728
i would say htdp is more focus on methodology while scip is more focus on abstraction
>>
>>61848728
Just one hint kiddo. Your program must be optimized for only one thing: debugging/maintenance. Each time you have to made a decision, chose the side that made debugging/maintenance easy.
>>
>>61848751
Yes but the first line doesn't do what you think. It calls the command "test" with environment variable cmd=echo.
>>
>>61848771
How do I assign "echo something" to cmd then? add spaces around the `=` ?
>>
>>61848810
cmd="echo foobar"
>>
>>61848810
cmd=echo\ test
cmd="echo test"
>>
>>61848819
>>61848829
fuck, so simple.
>>
>>61848839
Just to point out, this is probably the wrong way to go about that. You probably want to use a function.

thing() {
echo test
}
thing


An array also works and allows you to use expansions and variables without worrying about word splitting.

cmd=(echo "$(foo bar)" "${var##quux}")
"${cmd[@]}"
>>
>>61848676
Why did they change it?
>>
>>61848927
Because POSIX semantics is poorly designed
>>
>>61848918
What if the array is too big? Won't the console complain it's over 250?
>>
>>61848918
Simply put I just want to shorten a hardcoded command to a shorter version because less work to refactor.
I guess an alias might actually be better for this usage?
>>
>>61848967
I'm not sure what the limit is in bash, I'd assume at the very least 2^16.

>>61849010
If you want, although aliases are mostly used for the case of alias foo='foo ...', where a function would be recursive. I'd go with a function.
>>
I love C++. I can write so much amazing impenetrable shit. It's truly a blessing for a NEET like me.
>>
>>61849189
Instead of jerking yourself off, why don't you show some examples? Post some repos.
>>
Ok I can write programs like a stupid calculator and shit, how do it make it a actual software outside the IDE? Like a actual executable with a cool icon and shit.
>>
>>61847647
>I have a C socket application
I'm so sorry
>>
>>61849236
try the release build instead of debug?

>>61849146
ah I forgot something, the 2nd part of the command is always different, so I'd have to use parameters for that function right?
>>
>>61849261
Writing with sockets in C is easy though.
>>
>>61849281
The API is massive disgusting hack.
>>
>>61849276
How do I do that? I just realized all these years I've just been writing code but never actually releasing a actual build. It's not as simple as "Save as .html" right?
I wanna actually help people with software already.
>>
>>61849276
Yes, if you're new to bash don't let the function() syntax fool you. The parameters are in $1, $2, ... or as a whole in the array $@.
>>
>>61849299
it's clean, simple and well-designed
I don't understand what your problem is
>>
>>61843876
Immutability has nothing to do with whether or not a language is good for scripting, what are you smoking?

Laziness by default on the other hand can be somewhat annoying. But a strict Haskell (using the strict pragma or using a language similar to haskell like purescript) can do scripting just fine.

In fact, testing becomes a lot easier when side effects are encapsulated in monadic types because its a lot harder to screw up the script if it has to typecheck. Since sysadmin script have significant side effects on your computer, testing them before you run is often impractical, so getting some compile time guarentees is nice.

Something tells me you haven't tried it.
>>
>>61849670
laziness isn't really a problem for scripting
>>
File: 1502421754234.jpg (107KB, 1241x931px) Image search: [Google]
1502421754234.jpg
107KB, 1241x931px
>>
C fags please help

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
char *INT_MAX_STR = "2147483647";
char *intstr = "2147483648";

if (strcmp(intstr, INT_MAX_STR))
puts("intstr is less than max!");
return 0;
}


Why is the if statement evaluating to true? '8' comes after '7' in ascii, shouldn't it evaluate to false?
>>
>>61849829
Because strcmp returns a number of differences, and since the strings are different, you get a non-zero value which evaluates to true.
>>
>>61849829
Look up what value strcmp returns.
>>
>>61849847
The man page on what strcmp returns is extremely ambiguous.
It's not helpful at all.
>>
>>61849865
> It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2.
Seems clear to me.
>>
>>61849865
strcmp(x, y)
is almost the same idea as
x - y
so < 0 means x < y
= 0 means x = y
> 0 means x > y
>>
File: nano.webm (1MB, 1370x948px) Image search: [Google]
nano.webm
1MB, 1370x948px
>nano
what the fukk
>>
>>61849914
>20 year old software written in C is bugged
wooo
>>
>>61849894
>>61849896
Sorry, it isn't clear not one bit.
A string being "greater than" another string does not make a whole lot of sense, and it can be interpreted in multiple ways.
>>61849829 is completely right for thinking strcmp returns what he thinks it returns and in fact it lines up better with what >>61849896 said than what >>61849845 said.
>>
>>61849939
>>61849914
I see now it might be the //*model on line 226
such is life when you use regular expressions to highlight syntax
>>
>>61849951
"less than or greater than" are admittedly unclear, but there's nothing ambiguous about "returns an integer equal to zero if s1 is found to match s2". However you understand less than and greater than, it is clear that non-matches return nonzero.
>>
>>61849951
>and it can be interpreted in multiple wa
No.
>>
>>61849829

immutable string INT_MAX_STR = "2147483647";
immutable string intstr = "2147483648";

( to!long(intstr) < to!long(INT_MAX_STR) ) ? "intstr is less than max!".writeln
: "intstr is not less than max!".writeln;


But why are you using strings?
>>
>>61849829
strcmp(3) returns 0 if the strings are the same. What you want is if (!strcmp(...))
>>
>>61849972
No fucking shit retard. That's not what we're talking about here.
We're talking about what EXACT value strcmp will return when the strings don't match.

>>61849978
Yes it can, idiot.
>>
>>61849980
>using a ternary except to select a subexpression's value
>calling a function with side effects without using parens
absolute garbage style
>>
>>61849996
That's unclear but it's also irrelevant. Match gives you zero, nonmatch gives you nonzero. For this purpose that's all that matters.
>>
>>61849998
Ternaries are cleaner and nicer to read, though my formatting got fucked.
>calling a function with side effects without using parens
nani?
>>
>>61847434
jfc, rejections shouldn't affect you this much
collect them like badges of honor, get hundreds!
>>
>>61849845
>>61849847
>>61849951
>>61849980
>>61849981

Thanks for all fast replies, got it now ty.

>>61849980
>Why strings

I'm trying to write a function that safely gets int input from stdin, only way I can think is to first read a string to avoid overflows.

_Bool readint(int *num, const char *prompt)
{
const char *INT_MAX_STR = "2147483647";
size_t len = 0, capacity = strlen(INT_MAX_STR);
char str[capacity + 1];
char c;
_Bool reading = 1, input_error = 0;
int negative_multiplier = 1;

fputs(prompt, stdout);

c = getchar();
if (c == '-')
negative_multiplier = -1;
else
ungetc(c, stdin);

while (reading)
{
c = getchar();

if (c == '\r' || c == '\n' || c == EOF)
{
c = '\0';
reading = 0;
}
else if ((c < '0' || c > '9'))
input_error = 1;

if (len <= capacity)
str[len++] = c;
}

if (input_error)
return 0;

if (strlen(str) < capacity)
{
*num = negative_multiplier * atoi(str);
return 1;
}
else if (strlen(str) == capacity)
{
if (strcmp(str, INT_MAX_STR) <= 0)
{
*num = negative_multiplier * atoi(str);
return 1;
}
return 0;
}
else
return 0;
}


Is there a better way?
>>
Why the fuck would you ever write something like the Hydrus Network in fucking Python?
God it's so fucking slow.

I bet it would be orders of magnitudes faster if it was written in C++.
>>
>>61850061
Define "safely"
>>
>>61850092
it'd be even faster in plain C
>>
>>61850061
_Bool read_int(int *num, const char *prompt)
{
return sscanf(prompt, "%d", num) != 0;
}
>>
>>61850061
int x;
scanf("%d", &x);
>>
>>61850100
No it'd either be the same speed or slower.
>>
>>61850094
If user types a number higher than int max or lower than int min, user fucks up and types letters instead, I don't want to program to crash, and I want to be able to know if the user fucked up (return a bool).
>>
>>61850100
Negligible difference between C++ and C while a huge difference between Python and either.
>>
>>61850100
Oh god, imagine the bugs.
>>
>>61850108
That's not working for me

>>61850113
see >>61850117
>>
void upload_and_draw(..., glm::mat4 * MVP, ...)
{
...
glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &((*MVP)[0][0]) );
...
}


void main()
{
//this works when MVP is of type glm::mat4 (and not a pointer)
//glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &(MVP[0][0]));

//pass to function instead
upload_and_draw(..., &MVP, ...);
}


so is my interpretation of this to mean
>pass the value of the memory location of MVP to the function
>...
>&((*MVP)[0][0]) )
>dereference it for a variable of type glm::mat4
>pass on the memory location of the matrix' first element

more or less the right way to understand it?
>>
>>61850117
strtol
>>
>>61850165
What was the point of this post?
>>
>>61850108
Fail.
_Bool read_int(int *num, const char *prompt)
{
printf(prompt);
return scanf("%d", num);
}
>>
>>61850190
Converts string to int with check for invalid input and corresponding return value on failure
>>
>>61850197
?
>>
>>61850197
>_Bool
Cfags will defend this
>>
>>61850226
I'm just using the function signature from the code given
>>
>>61850222
If you actually bothered reading the given code, prompt is the prompt to be printed before getting input from stdin, not the input itself
>>
>>61850253
Oh alright.
>>
>>61850197
That doesn't handle overflows
>>
>>61850226
_Bool is the actual data type that has been a part of c since C99, there is a header you can include thats part of the standard library <stdbool.h> that basically just defines it as bool, useless bloat though.
>>
>>61850262
>glm
>nice shell

post a scrot of your desktop pls

i wanna see what you're working on
>>
>>61843381
>OP pic isnt the same stupid anime picture i see almost every day
Thank you based Terryposter
>>
>>61844009
>he doesnt recognise the creator of TempleOS, the most secure OS known to man
>>
>>61850262
_Bool read_int(int *num, const char *prompt)
{
long long niggertits;
printf(prompt);
if (scanf("%lld", &niggertits) && niggertits >= INT_MIN && niggertits <= INT_MAX)
{
*num = (int)niggertits;
return 1;
}
return 0;
}
>>
>>61850339
I don't really know what you're communicating to me
>>
>>61850339
That glm is just >>61850156 in the background
>>
>>61850400
>not using https on 4chan

really?
>>
>>61850463
He is but some resources aren't loaded over HTTPS so there's the warning icon. Firefox will bitch unless *every* element on the website (including third party resources) uses SSL.
>>
>>61850369
Cool thanks, im just learning c and want to be able to get safe input, I thought applying the same way I got input for a string of any length was a good idea but I didn't know how to use scanfs return values.
>>
I've got a question to those of you with actual programming job.
Do you do code reviews?
Is there some process or do you randomly just have a look at someone's commit?
Do you use any tools?
>>
>>61850369
But how would you do this if you wanted to input a long long?
>>
>>61850628
Reconsider your problem instead.
>>
how passionate do you have to be to have a programming career
>>
>>61850763
You have to be pretty autistic, being interested in math helps because you will naturally study ahead, and you need to study ahead in CS because everybody else is.
>>
>>61850800
so if i'm picking it as a 'least painful option' and making myself learn it rather than having learned it for fun without any sense of responsibility it's probably not a good choice then?
>>
Do people us __rdtsc for performance debugging? how reliable is it

also how random is it, can i use them for RNG
>>
File: herbrand.png (44KB, 828x618px) Image search: [Google]
herbrand.png
44KB, 828x618px
what the fuck when do we make the video games?
>>
>>61850957
?
>>
>>61850849
>performance debugging
Depends on scale. For small functions I wouldn't trust any timer because the oscillations can be fuckhuge (oops, a clock interrupt took half of the time we spent overall, oops our thread got preempted, et cetera).

In more normal cases profilers (gprof, callgrind) or just the normal time functions (std::chorno::high_resolution_clock or whatever) averaged over a sufficiently large number of iterations should suffice.

>also how random is it, can i use them for RNG
They're usually centered around the same value with some large outbursts, so I wouldn't do that. Just use rand() if you don't need security and just need some sort of randomness.
>>
>>61850763
>>61850800
>>61850841

I went into CS because I had programmed a little before and I knew it was going to be easy. I hardly went to class in college but I did the homework. I had a bad gpa so I was nervous about getting a job but I have been promoted a lot since then.
My advice is to realize that it is very hard to know if a programmer is doing good work, so watch a lot of TV shows that have programmers in them and just shamelessly imitate the mannerisms of the best ones.
>>
>>61850957
Try not using Prolog.
>>
File: help.png (55KB, 813x616px) Image search: [Google]
help.png
55KB, 813x616px
>>61850957
send help
>>
>>61851092
Couldn't you do

mult(s(x), y, z) :- mult(x, y, u), add(u, y, z)
>>
>>61850957

Try taking an elective for making video games.
>>
>>61851033
the thing is I'm pretty sure it suits me better than any other field. but I'm not passionate about it. Like i'm not the type of person who was learning to program for fun in free time, or, assuming I get a programming job, will program a ton on his days off. Obviously this disqualifies me from being particularly competitive and ever getting a high level position. i'm just wondering if it's viable to do teh bare minimum and get a mediocre programming job that pays the bills
>>
File: python 35 pip.png (67KB, 703x401px) Image search: [Google]
python 35 pip.png
67KB, 703x401px
>"python setup.py egg_info" failed with error code 1
Can someone tell me why I'm not able to install anything? I have tried to change the permission of Python35 folder but that didn't fix the situation and everybody else say "just pip install X, it will fix everything" which I can't because the setup file seem messed up.
>>
>>61846154
I kind of figured this out, but I'm starting to wonder if there's a point in learning raw x86 more than the bare basics.
>>
>>61851863
install setuptools first
>>
Should I learn python or c if I want to fiddle with machine learning?
>>
>>61851900
python
>>
>>61851092
Wait I have seen these slides...

Professor from Germany?
>>
>>61851900
Python for sure.
>>
File: 1.png (42KB, 670x364px) Image search: [Google]
1.png
42KB, 670x364px
>>61851890
Already have it up to date but doesn't seem to self this problem, could it be related to my antivirus ?
>>
>>61851990
well did you try disabling it and trying?
>>
>>61852003
Still getting same error.
>>
>>61852040
well good luck then
>>
>>61851888
No point unless you want to design compiler optimizations
>>
cpp

while (true)
{
int x = 10;
}


shouldn't this create memory overflow?
>>
>>61852182
x goes out of scope when the block ends so it's automatically freed
lrn2 raii
>>
Been making a discord bot with discord.py, my first programming project I've ever done besides playing around with web development.
>>
>>61852199
>raii

so compiler will instead do

int x;
while (true)
{
x = 10;
}


because x is only used inside the loop, basically recycling the old pointer?
>>
>>61852182
>
int x = 10;

This is a stack-declared variable. It's declared on the stack by pushing forward the stack pointer 1 int.
If we do a naive compile of this this changes the stack pointer back and forth and sets the value to 10 in that stack address.
>>61852199
That doesn't address the issue at all. This has NOTHING to do with RAII.
>>61852223
No the variable doesn't exist outside the scope.
>>
>>61852223
the while is not special, and tricks like that aren't necessary. Consider this snippet.
int x;
{
int y;
}
x += y; // won't compile, y is out of scope

y is in a scope of its own, and when you exit that scope everything local to that scope gets cleaned up. The stack grows when you enter the scope to allocate the y and the stack shrinks automatically when you exit that scope.
>>
>>61852229

>stack go back and forth

does cpp have garbage collector? i am asking them to keep allocating memory for my variable.
>>
>>61852285
Please just learn C, for the time being anyway. It's clear that you don't have any idea what C/C++'s memory model looks like and just learning C is the easiest way to understand that.
>>
>>61852285
>i am asking them to keep allocating memory for my variable.
If you want that you'd do
>>61852223
int* x;
while (true)
{
x = new int; //this leaks memory
}

Look at something like this for an understanding of stack allocations
https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap

If you just want the short story the stack declared variable is "freed" at the end of the scope, the while loop is scoped. Even
while (true)
int x;

is scoped, despite not having a block.
>>61852337
No he doesn't have to. If he has reasons to learn C++ he should learn C++.
>>
>>61852365
>>>61852223
This wasn't meant to be here.
>>
>>61852365

alright, its pretty obvious i dont have that deep understanding of c/c++ but its so hard to look up this stuff outside of snippets of comments in stackoverflow and knowing beforehand what to look for

any recommendations?
>>
So uh, I guess /dpt/ would be a place for this question.

I've got an AGPL-licensed server. Its a game server but I don't want to release the game's content - just the source code of the engine. Is it OK to license the server's code with AGPL, but make it so that the Lua scripts that will be used on my own server will not be public (if the server is still runnable without those scripts, just not with the same content)?
>>
>>61852389
>any recommendations?
Learn the terminology, make notes even. Helps you search well. I can't do any book recommendations because I haven't read a C++ book since before c++11.
>>
I wrote x86 vector routines but can't test avx512 because my cpu does not run these instructions, and neither can the free x86 emulators (tried Valgrind, QEMU).
Can someone who has avx512 compile and run my test program? I would be extremely thankful.
https://gist.github.com/anonymous/b35f3f4ecd33e2801174a7ab1d31a0dc
>>
why the fuck is this a segmentation fault?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>

int main()
{
DIR *d;
struct dirent *dir;

size_t nfiles = 0, capacity = 8;
char **filelist = malloc(sizeof(char *) * capacity);
char *tmp;

d = opendir("/home/nick/Pictures");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
if (nfiles == capacity)
{
capacity *= 2;
filelist = realloc(filelist, capacity);
}

if (dir->d_type == DT_REG)
{
tmp = dir->d_name;
filelist[nfiles] = malloc(strlen(tmp));
strcpy(filelist[nfiles], tmp);
//printf("%s\n", filelist[nfiles]);
nfiles++;

}
}
}

for (size_t i = 0; i < nfiles; i++)
printf("%s\n", filelist[nfiles]);

//Free allocated memory
for (size_t i = 0; i < nfiles; i++)
free(filelist[i]);
free(filelist);
return 0;
}
>>
>>61852495
What line?
>>
The first project on freecodecamp (static page with an image, link and some text).
>>
>>61852502
The last two for loops.

The commented out line in the middle which prints the filenames works, but the for loop which prints out the filenames segfault before it is printed.
>>
I have a .txt file with grades of various students and I need to calculate the average and say if they're approved or not.
The file is something like this:
201171003 6.6 4.3 PETER

Which means, in order: ID, grade 1, grade 2, name.

If the average of the grades is greater than 7, the student is approved and I need to print this in the terminal.

The problem is that I have no idea how to do this in C++. I come from a C background and the teacher just expect us to do this using C++ and all that std:: crap.
>>
>>61852495
>malloc(strlen(tmp))
strlen doesn't include the terminating \0 character
>>
>>61852524
>the laws two for loops
The entirety of them segfaults at once?
Wow you've got some serious issues then.
>>
>>61852554
Still segfault.
>>
>>61852597
Comment out the frees.
>>
>>61852495
You're not being consistent with malloc/realloc.
>>
>>61852495
>malloc sizeof(char *) * capacity
>realloc capacity
>>
>>61852495
Never use strlen and strcpy.
>>
>>61852644
Why?
>>
>>61852640
I feel like you are trying to make a point???
>>
>>61852625
still segfault, c is fucking trash, also it's not even letting me post my code here, says connection error when I try to post the code, fuck /g/ too
>>
>>61852700
See >>61852640
And user errors happen in any language.
You don't even check which line your segfault is at. Not wise.
>>
>>61852700
Look at this >>61852631 comment. Your call to realloc isn't doing what you think it's doing.
And this one >>61852554 is right as well.
>>
>>61852700
>c is fucking trash
we all know that. your fault for not listening to us.
>>
New thread:

>>61852783
>>61852783
>>61852783
>>
I'm learning cryptography to write cool programs that use it.
>>
>>61852544
>I come from a C background and the teacher just expect us to do this using C++ and all that std:: crap.

Why in the world do you think this is easier in C than C++?
>>
>>61853335
The solution is obvious to me in C, I wouldn't know what parts of STL I'm supposed to use.
>>
>>61853362
Your task is literally trivial using any language's base libraries. The C way of doing this is clunky and tedious.

Consider the following:

File.ReadAllLines(muhFilepath)
.Select(x => x.Split(' '))
.Where(x => x.Skip(1).Take(2).Select(double.Parse).Average() > 7)
.ForEach(x => WriteLine(x[3]));
>>
>>61853455
C++ can do this?
>>
>>61853483
C++ has similar constructs similar to C#'s LINQ using lambdas to do set comprehension. You can seek out those things, but start by breaking your problem down. "Read file as list of strings C++", "split by whitespace C++", etc.

I just wanted to demonstrate that there is a world beyond C that allows you to almost think tasks into existence, due to base class libraries being so robust these days.
>>
>>61853536
Anon unless a library is really nice. Like what you've shown. The C way of doing things is very easy and intuitive because every building block is simple to understand.

But you're not helping him buy posting a nice example from another language. He doesn't praise C in any way he's just saying he doesn't know how this is done in C++.
>>
>>61853568
Using a phrase like "all that std:: crap" indicates that the anon already has a preexisting mental block to fully understanding how to use C++'s libraries. It also indicates that he sees C++'s libraries as a bad thing, rather than a tool to help him be more efficient.

This mentality is a cancer on /dpt/ these days. So much C elitism, and they look at more convenient tools and brush them aside as too complicated.
>>
>>61853646
>"all that std:: crap" indicates that the anon already has a preexisting mental block to fully understanding how to use C++'s libraries.
I wouldn't interpret it that way. I interpret it as "I don't know this new stuff and I'm pretending to be John Henry"
>It also indicates that he sees C++'s libraries as a bad thing
Many of them have terrible API. Like std::map for instance. It's laughably bad. You can't productively write efficient code with it. Things like that makes people dislike C++. Many times C is simpler and about as good.
Another problem with C++ is how you can't know the dialect of your coworkers. If you're solo you're free to use anything and stop using anything. If you're a team (like most software developers are) you're in a deeper hole when things go awry. There's many reasons to dislike complex things that don't work close to perfectly.
To say "well just don't use the bad bits" is not productive. You don't know what the bad bits are until you have A LOT of experience.
Thread posts: 321
Thread images: 22


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