/dpt/ - Daily Programming Thread

Old thread:

Attached: 1520807254507.jpg (557x800, 193K)

Other urls found in this thread:

stackoverflow.com/questions/8114008/when-should-we-use-asserts-in-c
github.com/fmtlib/fmt
github.com/mpark/patterns
bugs.archlinux.org/task/58487
greenlab.di.uminho.pt/wp-content/uploads/2017/09/paperSLE.pdf
codefights.com
dl.acm.org/citation.cfm?doid=3136014.3136031
twitter.com/SFWRedditGifs

I hate C so much

> variables in the initializer list are not initialized in the order that they are specified in the initializer list. Instead, they are initialized in the order in which they are declared in the class.
What if this ordering is altered by the compiler to reduce padding? Consider I have this:
#include

struct Seq
{
float a;
bool b;
double c;

Seq(int i)
: a{ i++ }
, b{ i++ }
, c{ i++ }
{}
operator std::string() const
{
return "a = " + std::to_string(a) + " b = " + std::to_string(b) +
"c = " + std::to_string(c);
}
};
Also, what could the std::string() operator look like in C++11 trailing return type form?

>What if this ordering is altered by the compiler to reduce padding
What if you become good looking, rich and famous person?
Yeah, shit can't happen.

I'm richer than my friends tho

Your only solace?

>std::string() std::to_string() std::to_string() std::to_string()

wow you must be a super cool std::hackerman since you don't use a namespace!

Quantum of solace

what did he mean by this

What's the best way to do "sanity checks" in C?
Like verify if an argument is positive, if it's an integer and not a double... this kind of thing?
Right now I do a bunch of if statements but it feels like those "CS graduate" memes

>unironically suggests using using namespace std;

Attached: explain yourself.jpg (478x333, 116K)

assert

but "std" is a namespace and he's quite obviously making use of it in his code...

>C
>Sanity
C tribe grug no understand this. C tribe make assert, grug understand, assert grug happy.

Attached: 1525692750228.png (3033x2200, 2.03M)

audible kek

I was doing a bunch of if statements and calling abort() when it was an ill situation.
Should I replace all of these by asserts?

Ah, C++
The birthplace of AIDS

Attached: DeepinScreenshot_select-area_20180509123436.png (406x238, 15K)

Not all - asserts disappear in release build.

Assert is useful in development, but usually you put a special flag which makes the compiler ignore the assertion.

Is C++ dying?

>C++-beginner channel
barely 100 active
>C++-general channel
1000 active

>Rust beginner channel
900 active
>Rust general channel
1200 active

std::thinking(&mut self)

Attached: thinkingAkari.png (265x265, 104K)

Hey nerds, freelancing question.

I just started learning Solidity and writing smart contracts on Ethereum, and before I even set up my Upwork profile, one of my Linkedin connections apparently wants to hire me to write a custom token for him and do an ICO.
So awesome, my first project, but aside from making sure it won't fuck up once launched, I'm just wondering how I should handle the deal as a virgin contractor.

I'll write up a thorough document to quote him my hourly rates and estimates, specifications etc., but for one thing if he ends up wanting me to handle the frontend integration for the crowdsale payments on his website, I don't have JS experience or anything in that regard. Pretty much strictly writing the ethereum contract and deploying it on the network.

Should I just recommend he try & find someone else for webshit? Will that look bad when I quote him?

Also, it looks like we'll just handle this thing between the two of us. Now being my first gig I honestly don't care if he takes my work & runs without paying (although I trust him enough to not do so) but is there any chance of my shit getting fucked up if he doesn't like my work and sues me or something?

Just never done this before professionally and don't want to get JUSTed.

Attached: Etherium-1[1].jpg (640x427, 12K)

The type of people who start to learn C++ don't do it to join a social club, they advance far past beginner before wasting time in an IRC filled with neets.

The thing I am writing will not be released but just out of curiosity, how should I handle a user choosing inconsistent parameters? (a negative mass or something like that)

>Now being my first gig I honestly don't care if he takes my work & runs without paying (although I trust him enough to not do so) but is there any chance of my shit getting fucked up if he doesn't like my work and sues me or something?
Use a smart contract to make sure he doesn't do this

if statements

>measuring anything by the size of /soc/ cesspools

lel

Attached: 1514745895796.jpg (398x431, 41K)

You are saying either
>advanced C++ users are NEETs
or
>C++ is so easy newbies go straight to C++ general to talk about ISOCPP
None of which makes any sense.

So basically what I am doing now but with giving a descriptive error message before calling abort?

You forgot to unwrap() this time

stackoverflow.com/questions/8114008/when-should-we-use-asserts-in-c
>You should only use assert to check for situations that "can't happen", e.g. that violate the invariants or postconditions of an algorithm, but probably not for input validation (certainly not in libraries). When detecting invalid input from clients, be friendly and return an error code.
I should do what this guy says?

>how should I handle a user choosing inconsistent parameters? (a negative mass or something like that)
exceptions ;)

Quite the opposite.

And what people do on IRC channels these days, when almost any answer is one google query away?

>the absolute state of Jow Forums

No, I am saying that people who hang out in IRC chats are neets.

Why can't C# compete?

Attached: DeepinScreenshot_select-area_20180509125002.png (1428x821, 194K)

If the client fucks up, they shouldn't be able to use your program. Delete all associated files so you can never run again then close the program

The reasons for Rust are hard to explain to someone without a c/sepples background. I wonder how many will drop out coming from JS/Python/etc.

What C++ beginners need is a suicide hotline.

>exceptions
C doesn't have exceptions.

IRC is pretty good for short answers and advices. SO isn't suitable for such questions.

Not all IRC channels are meant for trading buttplugs

User input must be checked with if statements.
Asserts are for "I think this always will be X, but I will double check that, because if I'm wrong everything below is fucked" kinds of situations.

Why is Rust such a memory hog? I'd expected it to be comparable to sepples

>muh 16 Mb memory waa
Wake up grandpa

Attached: 1518069582580.png (485x443, 27K)

>slower than java
kek after all these shilling MS evangelism force does... pathetic

Thanks for the rule of thumb.

Well, I'd be worried if I now need 16x the memory I used to.

rustfags on suicide watch kek

>I-it doesn't matter! L-languages don't have to be good anymore, it's 2018 grandpa!!!!

Stop using outdated technology

>Cnile era
omg 128 Mb on that Pentium 1
>Rust era
omg 64Gb on that i9
Times changed, hasn't it

using std::to_string;

use c++

It will still do it in the order the standard demands.

You are welcome. Good luck with your learning !

>>Rust beginner channel
>900 active

880 are mods watching out for misgendering, gal.

heh pretty sure you can beat C in memory if you write ASM but you won't do it would you

memory is indead dirt cheap, more than x1600 cheap

>using std::to_string;
But what for? copy-pasting is one easy shortcut away.

my end goal is to do signal processing on DSP / controllers and C seems to be the way to go.

Thank you!

Your indentation is a little screwy but I think you must be one of those weird tabstop=8 people. Weirdo. Most schemers don't capitalize at all, whereas other lispers either use allcaps or don't capitalize at all.
>define swapper
define swap. procedures are verbs.
>camelCase
yuck

Usually we mark procedures which set! or swap! or ! things with an ! at the end to indicate that they're not referentially transparent.

((λ (point)
(begin
(vector-swap! Vect point High)
point))
(Swapper Low Low)))

Define, Lambda, Cond bodies and Let all have implicit begins. So you can delete a lot of begins. This should be a let as should the other case you do this.
>(define (Part)
A zero arity procedure called once isn't much of a procedure. Inline it.

The actual functionality seems good to my eyes but the style is a bit jumbly and it seems you don't know scheme that well. Perhaps I can recognize mistakes once you fix up the style. Guess you're already a good programmer just picking up scheme informally on the side.

So i've installed two of my most used libraries
github.com/fmtlib/fmt
github.com/mpark/patterns

in my system in CMake install prefix. Should I have to recompile/reinstall each time there's a GCC update?

Reminder that Rust does not have this problem

>GCC UPDATE BRAKES PYTHON
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Attached: 1517919983256.png (205x269, 29K)

LISP and C++ should be switched

// The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
//
// Find the sum of all the primes below two million.
let n = 0;
let p = 0;
let isGreaterThanOne = false;
let isPrime = false;
let isComposite = false;
let myPrimes = [1, 2, 3, 5, 7, 11];
let tfArray = [];
let cCounter = 0 ;
let sum = 0;

for (n = 0; n < 2000; n++)
{
if (n > 1)
{
isGreaterThanOne = true;
}
if (isGreaterThanOne == true)
{
for (i = 0 ; i < (myPrimes.length); i++)
{
p = myPrimes[i];
if (n % p == 0)
{
tfArray.push('c');
}
else
{
tfArray.push('p');
}
//console.log('n = ' + n + '& i = ' + i)
//console.info(tfArray);
}
for (a = 0; a < (tfArray.length); a++)
{
if (tfArray[a] == 'p')
{
cCounter = cCounter + 1;
}
}
// console.log('tfArray.length = ' + tfArray.length + ' & cCounter = ' + cCounter)
if (cCounter == tfArray.length)
{
myPrimes.push(n);
}

//console.log('Loop # ' + n + ' : ' + JSON.stringify(myPrimes));
tfArray = [];
cCounter = 1;
}
}


for (s = 0; s < (myPrimes.length); s++)
{
sum = ((sum + myPrimes[s]) - 1);
}
myPrimes[0] = 0;
console.log(myPrimes.length);
console.log(sum);
console.info(myPrimes);


what do you think, dpt?

bugs.archlinux.org/task/58487

...cont'd:
it works with n < 2000
but when n < 2000000 - oh boy!

on console using node.js it just never completes.

tries using online compiler, times out.

Friendly reminder that JS doesn't have integer numbers.

ALWAYS make a contract AND if you can get payed in advance take that train

I use conan, it just works.

js doesn't make distinction between int, double, float, etc...

but why do you bring that up?

So that people would be careful when working with numbers. Especially--with mul/div operations.

>js doesn't make distinction between int, double, float, etc...

Attached: 1519221407637.jpg (255x255, 10K)

>it works with n < 2000
>but when n < 2000000 - oh boy!
>on console using node.js it just never completes.
>tries using online compiler, times out.
WHY?!

note: previous definition of 'main' was here
int main(int argc, char *argv[])
error: redefinition of 'main'
int main(int argc, char *argv[])

this kills the man

c btfo

To make your code more concise and readable

>live in bumfuck middle of nowhere
>stuck here for a variety of reasons
>local job market is dead as fuck
Tell me sweet lies about freelancing Jow Forums. I need to believe in something. I've been cutting grass for a living and studying CS at night for about a year. What fundamental programming skills should I have mastered before I start roleplaying as a professional on various freelance websites?

get all the free certs you can and make them badges on your profile

the more paid jobs u do, the better u will look to mroe employers

>free certs
Tell me more?

I think I picked hard mode for this free programming camp thing..

Attached: 41363246.png (733x217, 52K)

u /can/ google it.

but let's use freelancer as example...

sign up for free trial. maybe win a cheap job.
use some of the proceeds to go through their certification process. then if u pass, they add a badge to your profile. in turn, making you look batter in the future

rate my homework assignment, no bully ;_;

Attached: killrf_by_esk.png (569x855, 18K)

Oh it's through the freelancer website. I see. Thanks for the tips.

>dark blue on black
Can't read shit

Attached: 1418881050882.png (639x707, 678K)

im learning haskell, give me a cookie

:set bg=dark
then kill yourself for not knowing that

u get the worst cookie of all
an un-deletable porn site cookie

Nice. Source?

That's a fun problem

I said no bully

Attached: untitled.png (267x189, 75K)

ok sorry

anyway it's a bash script, by definition it cannot be beautiful, just try to get through the bash programming with as little pain as possible

greenlab.di.uminho.pt/wp-content/uploads/2017/09/paperSLE.pdf

Felli best girl

Very bad.
#!/bin/bash

incr=1
current=1
max=0

if [ "$1" = "-e" ]; then
echo "Even Numbers"
incr=2
current=2
max=$2
elif [ "$1" = "-o" ] ; then
echo "Odd numbers"
incr=2
max=$2
else
echo "All numbers"
max=$1
fi
while [ $current -le $max ]; do
echo $current
current=`expr $current + $incr`
done
echo ""

what site is this

Where is the source code and compiler info?

codefights.com
I picked the extra credit course apparently it's like big company interview problems

Ask the authors. Might be closed sourced
dl.acm.org/citation.cfm?doid=3136014.3136031

>Might be closed sourced
LOL closed source benchmark what the hell?
They provided the OS, CPU and ram why can't they provide source?
Also,
>Vancouver, Canada
>R. Pereira er. al.
>.pt site
I call bullshit

Funny. I was in the office for 19 hours today and several times I looked out the window at the landscaping crew with envy. I mean, yeah, it sucks to be poor, but when you go home and chill for the day i'm in the office still working and then cramming new dev. shit in my free time just to keep up at work the next day.

The sources are that of the benchmark game