[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: 25

File: shias-inner-asshole.jpg (93KB, 1110x624px) Image search: [Google]
shias-inner-asshole.jpg
93KB, 1110x624px
Previous thread: >>60119799

What are you working on, /g/?
>>
File: 1487413306014.png (383KB, 611x720px) Image search: [Google]
1487413306014.png
383KB, 611x720px
First for C++ is shit.
>>
>>60123996
I love you all
>>
>>60124002
>>60124005
whom'st've for these posts are not programming please stay on topic
>>
File: 1491907464231.png (71KB, 300x346px) Image search: [Google]
1491907464231.png
71KB, 300x346px
Why do they keep making C++ bigger every year?

Do they suffer from some sort of inferiority complex? C++ is INSANE, not even a 1500 pages book will teach you half of the language.
C with RAII when? WHEN!

>D
Slow. LDC, please for fuck's sake try and produce binaries that doesn't make fun of itself in comparison to the other systems languages. Dub is a JOKE in comparison to cargo and Dscanner/DCD server is just sad and pathetic compared to Rust's racer/RLS. Doesn't have many static analyzing options
>C
Too small, lacks too many features. The exact opposite of C++. If the compilers would be able to inject free() in sources during compilation that would be fucking great. I don't use C for the same reason I don't use Rust as my to-go language.
Also C macros are pitiful
>Rust
Holy shit the level of verbosity and complexity! 10/10 in getting in your way of thinking.
To be fair that's the same thing python fags complain about C. Learning C made me lazy just like learning python did.
Language is unplanned, it doesn't know what to have, what not to have and Rust certainly doesn't have syntax or library names that make sense for the most part, the incremental updates will make it worse than C++ in a couple of years.

Don't get me wrong, I personally like Rust. But holy shit there are so many things that need to mature
1. Has print! but doesn't have read!. println! flushes the stdio, print! doesn't.
Oh, you really don't need read! You need eprint! --makes SO MUCH sense!
2. for loops have i..z-1 (exclusive) syntax but pattern matching has i...z (inclusive) syntax
3. thousands of ways of doing the same thing
4. If you are indirectly pushing the functional programming practices why not adopt it fully? Add Higher Kinded Types
5. Lack of for(int i=0; ;) loop
Even C has it since C99


Thanks for reading my blog. I had to get that out of the system.
>>
>>60124002
like english, but if you don't know it well enough then you are worthless trash
>>
>>60124026
There is literally no reason to know C++.
>>
>>60124034
people in Bolivia thinks the same of english
>>
>>60124043
What the hell does that have to do with C++ being fucking shit?
>>
>>60124053
dumb people in Bolivia = (You)
english = C++
>>
>>60124034
>what are video games
>what is anything that requires performance and which isn't a legacy C application
>>
>>60124072
C is the choice for high-performance applications though.
>>
File: 1489009342990.jpg (24KB, 460x458px) Image search: [Google]
1489009342990.jpg
24KB, 460x458px
>>60124024
To elaborate this code is not valid in Rust
It's INSANE!
fn main() {
let x :u64 = 7u64 + 3i32;
let y :f32 = 7i32/3f32;
let y :f32 = 7i32/3i32;
}
>>
I use Python for testing things and C++ for implementation because it runs faster.

Fuck Java.

Rust maybe someday, once it matures a bit.
>>
>>60124075
You claim that based on what exactly? I do high-performance network packet processing (like 100GBps on a HP ProLian Gen9 server) at my job and we use C++ extensively, STL, templates and OOP including. Implementing the same in pure C would've resulted in failed deadlines, leaked memory and unmaintainable code.
>>
File: 1491009506251.jpg (24KB, 324x278px) Image search: [Google]
1491009506251.jpg
24KB, 324x278px
>>60124137
How on earth is C++ high performance?
It doesn't even have restrict.
>>
>>60124135
My man.
Currently I use D almost exclusively. It has a great productivity/performance ratio. Although I am learning Rust as of now.

>Rust maybe someday, once it matures a bit.
Very well said
>>
>>60124081
No shit, Rust is actually strongly typed, unlike C.
>>
>>60124135
> Rust maybe someday, once it matures a bit.
It's just hit 1.17, what are you waiting for exactly?
>>
>>60124160
Not him but it needs a lot more polishing. It's on the right track, may be I'll move to rust after v2 or something
>>
>>60124148
G++ has __restrict tho, but the benefits are negligible anyway. Fun fact, the most performance gain we've had over the O3 performance baseline was by adding __attribute__((always_inline)) to every method called inside the main loop.
>>
>>60124160
Did RLS get pushed into the stable?
>>
>>60124173
> it needs a lot more polishing
This is just a buzzword that means nothing tho.
>>60124236
It's a separate project, it can't be "pushed" into rustc release. Besides, you only need the nightly to compile RLS, after that you can use it with the stable.
>>
>>60124274
user0@primary:~$ cargo install rls
Updating registry `https://github.com/rust-lang/crates.io-index`
error: could not find `rls` in `registry https://github.com/rust-lang/crates.io-index`
user0@primary:~$ rustup component add rls
error: toolchain 'stable-x86_64-unknown-linux-gnu' does not contain component 'rls' for target 'x86_64-unknown-linux-gnu'
user0@primary:~$
>>
if c++ is so great why aren't any modern open source text editors written with it?
>>
>>60124353
>if c++ is so great
Your assumptions were flawed from the start.
>>
>>60124353
Made me think

Probably because C++ took away the fun in programming, unlike C
>>
File: dlang_chan.jpg (139KB, 470x545px) Image search: [Google]
dlang_chan.jpg
139KB, 470x545px
Threadly reminder that dlang-chan is not dead, and she's super duper cute! Say something nice about her, /dpt/!
>>
>>60124208
Clang and VS has it too.
>>
>>60124360
your argument without context is flawed
>>
>>60124345
You have to switch to nightly before adding the components.
[~]$ rustup default nightly 
info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
info: default toolchain set to 'nightly-x86_64-unknown-linux-gnu'

nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.18.0-nightly (128aa262e 2017-04-28)

[~]$ rustup component add rls
info: downloading component 'rls'
5.9 MiB / 5.9 MiB (100 %) 1.1 MiB/s ETA: 0 s
info: installing component 'rls'
[~]$ rustup component add rust-analysis
info: downloading component 'rust-analysis'
758.0 KiB / 758.0 KiB (100 %) 225.1 KiB/s ETA: 0 s
info: installing component 'rust-analysis'
[~]$ rustup component add rust-src
info: downloading component 'rust-src'
info: installing component 'rust-src'
>>
>>60124385
thanks
>>
>>60124408
you are welcome
>>
>>60124353
Notepad++ is written in C++, it's modern, open source and probably the most popular text editor out there.
Atom and VSCode are built on Electron which is basically Chrome which is written in C++.
Sublime Text is written in C++ too, btw.
What are the other modern text editors you're talking about?
>>
>>60124417
>Sublime Text is written in C++ too, btw.
I thought it was closed source
>>
>>60124424
How are those contradictory?
>>
>>60124417
not sure if troll
>>
>>60124429
How did you check the source?
>>
>>60124424
It is, but I was short on open source modern text editors, there's not a lot of them out there.
>>
File: 1340585195539.jpg (23KB, 260x258px) Image search: [Google]
1340585195539.jpg
23KB, 260x258px
>>60124432
My little anon can't be this stupid. Can he?
>>
>>60124432
» ldd /mnt/Black/Apps/SublimeLinux/sublime_text
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fa04101a000)
>>
>>60124444
>t. dumb anime poster
>>
>>60124432
This is the author: https://news.ycombinator.com/item?id=2822114
>>
>>60124445
Are you implying nothing else can use C++ libraries?
>>
File: 1488241177075.jpg (85KB, 917x720px) Image search: [Google]
1488241177075.jpg
85KB, 917x720px
>>60124452
Apparently he can.
>>
>>60124417
javascript and java are super popular, but that does not mean they are not shit
sublime text is the only valid text editor, even if it's closed source
>>
How do I into Prolog?
>>
>>60124464
vim, my friend
>>
>>60124461
>still posting anime
dumb anime poster
>>
>>60124466
first learn to balance a cucumber with your buttocks and walk fast as you can, then go ahead
>>
>>60124474
yeah, vim, I forgot it, even if it's older than me and has not changed a lot in those years
but why change something that works?
>>
>>60124456
Yes? C++ has no standard ABI to begin with and no other language implements C++ FFI to my knowledge, C++ libraries just export C API.
>>
>>60124486
>vim, I forgot it
You say that as if you're not using it right now.
>>
Should I learn smalltalk?
>>
>>60124504
indeed I am using it, just that I was thinking about editors like with tabs and click activity
>>
>>60124506
refer to >>60124478
>>
>>60124513
The original post was referring to modern editors; so it's understandable.
>>
>>60124524
why?
>>
>>60124531
a) you are an academic faggot
b) you are a hipster faggot who fell for the functional meme
>>
>>60124417
>all recent editors are based on electron
>github
when will we escape the sjw shit?
>>
Reposting from the Rust thread, since people there don't seem to actually it:

At work I program C for Cortex M devices, using a non-userspace RTOS. I was searching for embedded OSes for Rust, and only this one came up: https://www.tockos.org/
Has anyone here tried it? It seems board support is pretty lacking.
>>
>>60124513
>tabs and click activity
Vim has buffers, I use them all the time, and can be compiled with mouse support.
>>
>>60124075
Fortran is the choice for high performance applications
>>
>>60124569
When people stop using them; sadly, their popularity creates a vicious cycle.
>>
>>60124586
only if you do physics stuff or simulations, I will never try to do text processing with it
>>
Can we all agree that phyton does not deserve the hate it gets
>>
>>60124464
>sublime
>better than vscode
Funny
>>
I fucking love vim once I spent some time with it; I feel like a god editing text.
>>
>>60124570
Hmm, only three boards. But the project has a potential
>>
Is Javascript /ourtongue/?
>>
Nobody actually uses Rust lmao, that's a giant ycombinator meme
>>
>>60124678
ycombinator by itself is a meme
>>
File: 1473515801008.gif (2MB, 350x190px) Image search: [Google]
1473515801008.gif
2MB, 350x190px
>>60124617
>mfw i just recently learned that you can just :make
>>
>>60124678
I use Rust tho
>>
File: father_of_a_bear.jpg (169KB, 591x532px) Image search: [Google]
father_of_a_bear.jpg
169KB, 591x532px
>>60124702
Glorious, isn't it?
>>
>>60124617
post rc
>>
>>60124651
Yeah, I find the design of using untrusted capsules (drivers) in the kernel + restricted userland processes interesting. Another way to solve the problem of not having a MMU.
>>
>>60124730
It's just the essentials with nerdtree, syntastic, and pathogen as plugins. I haven't added any keybindings yet because I don't feel the need to yet. If you're still interested, I'll post it.
>>
File: dman.png (14KB, 160x301px) Image search: [Google]
dman.png
14KB, 160x301px
>>60124364
fuck dlang-chan, we already have dman
>>
>>60124888
>fuck dlang-chan
I want to.

>we already have dman
Why not both?
>>
>>60124417
>Atom and VSCode are built on Electron which is basically Chrome which is written in C++.
retard
>>
>>60124137
>100GBps
Holy shit. 100 giga bytes per second? What the actual fuck.
>>
>>60125099
It's 100 giga-BITS per second, and it's been around for a while now: https://en.wikipedia.org/wiki/100_Gigabit_Ethernet . The trick it is to process it in real-time on stock x86 servers without ASICs.
>>
>>60125099
Yeah exactly the same rate that Haskell generates garbage!
>>
>>60125136
>It's 100 giga-BITS per second
You clearly said 100 Gigabytes per second.
>>
>>60125136
You wrote GBps, that's why I was shocked. giga-BITS per second is written as Gbps.
>>
>>60125152
>>60125156
Right, my bad.
>>
string manipulation in C
>>
>>60124208
>2017
>not using [[gnu::always_inline]]
>>
Okay, I am the one who posted >>60121449 in the last thread. I asked this because I wanted to benchmark the three languages in my arbitrary criteria: readibility, productivity, and efficiency. I am very surprised at the actual results.
user0@primary:~/devel/proj/test-c$ cat test.c && gcc -O2 test.c && time -p ./a.out
#include <stdio.h>

int main()
{
size_t total = 0;
for (int i = 0; i < 100000; i++)
{
for (int j = 0; j < i; j++)
{
total += (j * j == i) ? j : 0;
}
}

printf("%lu\n", total);
return 0;
}
50085
real 8.15
user 8.15
sys 0.00
user0@primary:~/devel/proj/test-c$


user0@primary:~/devel/proj/test-d$ cat main.d && ldc2 -O2 -release main.d && time -p ./main
import std.stdio;

void main(string[] args)
{
size_t total = 0;
for (int i = 0; i < 100_000; i++)
{
for (int j = 0; j < i; j++)
{
total += (j * j == i) ? j : 0;
}
}

writeln(total);
}
50085
real 7.53
user 7.52
sys 0.00
user0@primary:~/devel/proj/test-d$


user0@primary:~/devel/proj/test-rs/test1/src$ cat main.rs && rustc -O main.rs && time -p ./main
fn main() {
let mut total: i32 = 0i32;
for i in 1..100_001 {
for j in 1..i {
total += if (j*j) == i {j} else {0i32};
}
}
println!("{}", total);
}
50085
real 2.61
user 2.61
sys 0.00
user0@primary:~/devel/proj/test-rs/test1/src$


It's fair to claim that:
1. Abstractions are not causing any negative affect on this test. This is very questionable. Rust claims that it has almost zero cost abstractions. However it turns out to be faster than the equivalent binary produced by GCC/C with -O2 optimizations
2. Interestingly enough, LDC/D has produced faster binaries than C. This is explainable. The GC in its Stdlib has not been triggered and thus it produced native binary that doesn't require garbage collection at all.

I don't hate C and I am new to Rust. But Rust is impressive. What are your thoughts?
>>
>>60125242
what is this? some clang thing?
>>
>>60125282
The problem is so simple, that any benchmarking is meaningless. They all should be in the same ballpark, though.
>>
>>60125282
Where are no abstractions tho, this is a pretty straightforward port. Measure >>60125221 instead, it's idiomatic and it should have the same performance as the naive version.
>>
>>60125316
println!
>>
>>60124081
Rust has a reasonably nice syntax for casting though.

fn main() {
let x :u64 = 7u64 + 3i32 as u64;
let y :f32 = 7i32 as f32 /3f32;
let y :f32 = (7i32/3i32) as f32; // How you cast depends on whether you want float or integer division, if you want the former cast both args.
}
>>
>>60125316
Well, now this makes more sense:
user0@primary:~/devel/proj/test-rs/test1/src$ cat main.rs && rustc -O main.rs && time -p ./main
fn main() {
let total = (1..100000).
map(|i| (0..(i)).filter(|&j| i==j*j).sum::<i64>())
.sum::<i64>();
println!("{}",total);
}50085
real 5.34
user 5.34
sys 0.00
user0@primary:~/devel/proj/test-rs/test1/src$ cat main.rs && rustc -O main.rs && time -p ./main
fn main() {
let mut total: i32 = 0i32;
for i in 1..100_001 {
for j in 1..i {
total += if (j*j) == i {j} else {0i32};
}
}
println!("{}", total);
}50085
real 2.65
user 2.64
sys 0.00
user0@primary:~/devel/proj/test-rs/test1/src$


The abstraction of map and filter is yielding a slower binary. We haven't been able to make compilers smart enough for functional programming.
>>
>>60125282
Some one post a C++ version of this
>>
>>60125282
this by itself isn't enough to make rust impressive. this is probably some fluke like some compiler optimization that C/GCC and D/GDC are missing. rust on average should be around 1-3x slower than C.
>>
>>60125316
Right, that snippet written in a functional style hides a lot of abstraction. Then again, the same thing is true of a foreach loop over a range.
>>
>>60125356
You're comparing i64 to i32 tho, ofc i32 math is faster.
>>
>>60125393
>>60125356
yeah and you're using size_t instead of int32_t in >>60125282 wtf nigger
>>
>>60125282
For a new language, the Rust compiler sure is pretty impressive, I'll give you that
>>
>>60125282
Please learn to write code properly.
$ cat test.c && gcc -O2 test.c && time ./a.out 
#include <stdio.h>

int main()
{
long long total = 0;

// The semantics of your code causes the 1 case to be skipped
for (int i = 2; i * i < 100000; ++i) {
total += i;
}

printf("%lld\n", total);
}
50085

real 0m0.002s
user 0m0.000s
sys 0m0.000s
>>
>>60125356
Now I'm curious.

I'd expect the bottleneck to be the filter operation, which takes in its argument by reference instead of by value, which is inefficient for small things like integers.

I'd expect this version to be as fast as the imperative one:
fn main() {
let total = (1..100000).
map(|i| { let mut total : i32
for j in 1..i {
total += if j*j == i {j] else {0i32};
}
}
.sum::<i32>();
println!("{}",total);
}


Another option would be functional style with map instead of filter:
fn main() {
let total = (1..100000).
map(|i| (0..(i)).map(|j| if i==j*j {j} else {0i32}).sum::<i32>())
.sum::<i32>();
println!("{}",total);
}
>>
>>60125429
>The semantics of your code causes the 1 case to be skipped
>result is the same
>>
>>60125443
That is what I was pointing out, idiot.
>>
>>60125442
he's being a fag and comparing i64/size_t against i32
>>
>>60125459
long long total is not giving much difference
>>
>>60125442
Ah, the lambda in the map of the first version should return of course.
map(|i| { let mut total : i32
for j in 1..i {
total += if j*j == i {j] else {0i32};
}
total
}
>>
>>60125474
an apples to apples comparison with the i32 rust code would be int32_t for fuck's sake
>>
>>60125369
Idiomatic C++ in this case should basically be the same as the C version though. Just using cout instead of printf.
>>
>>60125512
cout is pants-on-head retarded.
>>
>>60125518
nah it's comfy if you just want to print something real quick
>>
>>60125378
>rust on average should be around 1-3x slower than C.
Have you got any facts to back that claim up? Why do you blindly defend(?) C?
>>
>>60125532
t. delusional rust fag
>>
>>60125544
I don't even use Rust, idiot.
>>
>>60125356
It should have the same performance once you fix the types, both versions result in the same tight loop with lots of vectorizing: https://godbolt.org/g/cj65Un .
>>
>>60125548
C is about as fast as it gets with the current compiler and cpu technology
>>
File: 1486724124441.jpg (32KB, 552x446px) Image search: [Google]
1486724124441.jpg
32KB, 552x446px
>>60125544
>>60125378
mmm, can I get some fries with that salt?
>>
File: Capture.png (33KB, 346x330px) Image search: [Google]
Capture.png
33KB, 346x330px
>>60125532
>>
File: 1469013229667.png (43KB, 645x364px) Image search: [Google]
1469013229667.png
43KB, 645x364px
>>60125566
I thought you people hated that benchmark
>>
>>60125529
How the fuck is
std::ios::fmtflags f(std::cout.flags());
std::cout << my_stupid_variable << " " << std::setfill('0') << std::setw(8) << std::hex << some_other_shit << std::endl;
std::cout.flags(f);

"""comfy"""?
>>
>>60125562
>compares size_t against i32
>program executes faster with i32
>implying this proves anything
>>
>>60125577
>if you just want to print something real quick
not talking about formatting or anything
>>
>>60125595
Basically everything that gets printed involves formatting.
Even in the trivial case, formatting strings are infinitely better.
>>
>>60125574
C# shills hate it because it makes them look retarded when java is faster than C#
>>
>>60125577
iostreams should've been long time deprecated by now
>>
File: 1468147027594.png (90KB, 1920x1055px) Image search: [Google]
1468147027594.png
90KB, 1920x1055px
>>60125583
You actually have a point, anon

kek
>>
File: contemplatingsuicide.jpg (22KB, 840x405px) Image search: [Google]
contemplatingsuicide.jpg
22KB, 840x405px
>>60125574
>Hasklel
>>
Recommend me a fast way to learn GIT please.
>>
>>60125626
kek
>>
>>60125555
> https://godbolt.org/g/cj65Un .
Holy shit this thing is a golden. Thanks anon.
>>
>>60125626
Haskell will give super weird results on that benchmark. The code presented is very far from idiomatic Haskell code, because of the requirement to use the same algorithms for the benchmark.
>>
>>60125620
What if you use int_fast32_t in C in D?
>>
>>60125620
try -march=native
>>
>>60125620
Damn, D was so close
>>
>>60125620
also use int32_t instead of int
>>
a
*** Error in `./mystring': free(): invalid next size (fast): 0x0000555ae5bb2050 ***


how do i debug this error?

MyString(const char * string) {                                                                            
strCapacity = strlen(string);
cout << "String size is " << strCapacity << endl;
strSize = strCapacity;
strPtr = new char(strCapacity + 1);
strcpy(strPtr, string);
}


am i missing something memory-allocation wise here?
>>
>>60125429
>>Not using the O(1) formula n^3 / 3 - n^2 / 2 + n/6
>>
File: rust_vs_c.png (62KB, 653x954px) Image search: [Google]
rust_vs_c.png
62KB, 653x954px
Here you go, totally scientific and unbiased comparison.
I wonder why the filter version is so slow.
>>
>>60125710
my eyes
>>
>>60125703
not the code that causes the error
>>
>>60125708
Closed form master race.
>>
>>60125296
no, that's the standard c++11 attribute syntax. it's a lot less ugly than the __attribute__(()) thing.
>>
>>60125722
when i send a string bigger than 26, it gives me this error. if it's lower than 26, it's fine.

what could it be? the destructor is just

 ~MyString(){                                                                                              
delete[] strPtr;
}


https://pastebin.com/QVDhduqB

that's the full code

is this wrong?
>>
>>60124208
>>60125242
Can I get a quick tutorial on always-inline please?
>>
>>60125731
neat

[[maybe_unused]] void f([[maybe_unused]] bool thing1,
[[maybe_unused]] bool thing2)
{
[[maybe_unused]] bool b = thing1 && thing2;
assert(b); // in release mode, assert is compiled out, and b is unused
// no warning because it is declared [[maybe_unused]]
} // parameters thing1 and thing2 are not used, no warning


C++ wins again!
>>
>>60125747
You're allocating with new, but freeing the memory with delete[].

Use new[].
>>
>>60125757
>in release mode, assert is compiled out, and b is unused no warning because it is declared [[maybe_unused]]

Sounds like a reasonable thing to do.
>>
>>60125620
Had similar results with -O2. With -O3 -march=native, I get:
50085
real 1.00
user 0.99
sys 0.00
>>
>>60125750
[[gnu::always_inline]] auto add (int a, int b) -> int
{
return a + b;
}


function always gets inlined when using a compiler which supports the attribute
>>
>>60125750
Just put your hot functions in headers, throw always_inline around them, use objdump to check if they have been actually inlined, measure every step so you don't have regressions, and to see if it even worth it. Oh, and for some reasons some functions only get inlined if you also put regular inline on them, even if you don't technically need one, like when you define methods inside classes.
>>
>>60123996
const long long rareCase = SpecificNumber();
for(long long i = LLONG_MIN; i<=LLONG_MAX; i++)
{
if( rareCase == i ) DoSomethingSpecific();
else DoSomethingMundane();
}


There has got to be a better way than to make a comparison check 18 trillion times just for that one rare case, right?
>>
>>60125794
oh yeah i forgot

>GCC does not inline any functions when not optimizing unless you specify the ‘always_inline’ attribute for the function, like this:
/* Prototype.  */
inline void foo (const char) __attribute__((always_inline));
>>
>>60125802
>He doesn't use concurrency
>>
>>60125802
I'm not exactly see that you're trying to do here, but I guess some kind of bloom filter + std::set should help you.
>>
>>60125761
thank you. that was it.
new char[]
instead of new char() in fact
>>
>>60125802
const long long rareCase = SpecificNumber();
for(long long i = LLONG_MIN; i<rareCase; i++)
{
DoSomethingMundane();
}

DoSomethingSpecific();

for(long long i = rareCase + 1; i<=LLONG_MAX; i++)
{
DoSomethingMundane();
}
>>
>>60125840
const long long rareCase = SpecificNumber();
for(long long i = LLONG_MIN; i<rareCase; i++)
{
DoSomethingMundane();
}

DoSomethingSpecific();

if(rareCase != LLONG_MAX) {
for(long long i = rareCase + 1; i<=LLONG_MAX; i++)
{
DoSomethingMundane();
}
}
>>
>>60125802
What the fuck are you doing

Are you just trying to DoSomethingMundane n - 1 times, then DoSomethingSpecific, then DoSomethingMundane LLONG_MAX - n times? A condition already has to be checked at each iteration of the loop, so you have twice as many comparisons as you need. I'd do:
const long long rareCase = SpecificNumber();
for (long long i = LLONG_MIN; i < rareCase; ++i) {
DoSomethingMundane();
}
DoSomethingSpecific();
for (long long i = ++rareCase; i <= LLONG_MAX; ++i) {
DoSomethingMundane();
}
>>
I'm good with python from work, but I want to learn to program properly.

C or C++ and why?
>>
>>60125840
>>60125850
>not checking rareCase != LLONG_MAX before adding 1
ahahaha keep writing unsafe code C tards
>>
>>60125861
Why don't you want to stay with Python.
>>
>>60125861
C++. Think of C as something like Python with 90% of the features missing, not so useful now, is it?
>>
>>60125861
C++ because C is shit
>>
>>60124758
Have a look at this article, may find useful
http://blog.japaric.io/quickstart/
>>
>>60125861

throw a coin.

C is easier and cleaner, but it's somehow limited and you have to do every shit by yourself.

C++ is way more powerful and can teach you a lot of paradigms, but it's a never ending story.

Both can be fun. Both can land you a Job.

Go with C if you want to be able to be productive fast, go with C++ if you want a lot of theory and a more powerful language. But whatever you do, a little bit of C would be the best start.

Work yourself through K&R and then make you choice, if you want a more powerful abstraction level or not.
>>
>>60123996
is that a cuckshed?
>>
>>60124137
>I'm bad at C, so everyone else must be too

C isn't the best option for most people in most situations, but if you are already well versed in it (especially with network stacks) it would be a lot quicker development-wise to carry on with C than to "learn" C++.

The problem really is that the easiest to find (or rather the stuff that people always look for first) C++ source is knee-deep in OOP and has GUI boilerplate everywhere, and generally just looks fucking awful.
It's so fucking terrible that anyone with a predominately C background will take one look at it, close the tab and pretend they never even thought about it.

Telling people that it works for you isn't much of a convincing argument, you can add on all the speed requirements and large numbers you want.
But,if you can show people a relatively large C++ project that's well structured and easy to read/maintain, maybe they'll actually believe you.
>>
How to flush stdin in Rust?
>>
>>60125907
>But,if you can show people a relatively large C++ project that's well structured and easy to read/maintain, maybe they'll actually believe you.
Like, all the major browsers out there, latest GCC code, LLVM/Clang, MySQL/MariaDB, Qt/KDE?
>inb4 NOT EASY
These project are easier to read and maintain than the kernel or the legacy code in GCC, or any other pure C project of the compatible size.
>>
reposting

Assign
..Id(b) - double
..Sub - x
....Sub - y
......Sub - double
........Id(b) - double
........Id(a) - double
......Id(c) - int
....Id(a) - double



how i'm i supposed to know the types x,y ?

i'm recursing down the tree and check the leafs of my tree, and based on the leafs, give the type to the parent.

But x and y its impossible to know?

do i have to go back up?
>>
>>60125942
>flush stdin
What did he mean by this?
>>
haskell.org vs haskell-lang.org
hackage vs stackage
cabal vs stack
What the fuck is going on?
>>
>>60125951
Explain the notation
>>
1-3 keep learning cobol
4-5 go to the gym
6 Do nothing
7 Solidworks
8 Scala
9-0 rest
>>
>>60125994
So that's basically a tree, and it represents the expression

b = b - a - c - a;


So Assign is =, Id is identifier, Sub is Subtraction and so on
so
Sub - double
..Id(b) - double
..Id(a) - double

means b - a

the problem is i'm supposed to print the types of the tree, but i'm recursing down and i cannot know the type before printing because i have to evaluate the type of the childs
>>
>>60125988
What did I just see? Man if a decaying community forks itself in two they are going to have half the little significance they had, which is good because Haskell is 100% irrelevant anyway so...
>>
>>60125951
An integer added/subtracted to a double will in most languages result in an implicit conversion to a double. That means y and x should both be double
>>
>>60126031
>What did I just see?
SHITKELL faggots are too edgy to work together
>>
>>60125943
Derp, I should have clarified by relatively large I meant more on the scale of what a small to medium sized company would output, or a small handful of people working on a project.

It's a lot easier for very large projects to enforce super-strict code style requirements, so they remove a lot of the causes of problems with sheer authoritarian might.

Also, it's funny that you mention Qt, since a lot of people have started using their utils instead of C++ sdt libs since the actual language utils are such a pain in the ass sometimes.
>>
>>60126031
>because Haskell is 100% irrelevant anyway so...
wrong
>>
>>60126022
go down and figure out the type, go back up to print, go back down again
>>
>180 posts in
>autistic gate keeper hasn't revealed himself yet
Did he get lobotomized?
>>
>>60126022
Ok you know what? If you are recursing, when you and your functiom are on a Sub node, call your function recursively on both operands and decide based on the result
>>
What's the best resource to learn GPGPU programming from?
>>
>>60126053
sorry, it's only 99.9999% irrelevant
>>
>>60126039
yes i know that.

but to determine the type of x i have to look aat the types of y and Id(a) and y is not defined yet.

you see the problem?

i'm recursing down the tree . do i have to go back up?

how do i even do that'?
>>
>>60126067
Most comp sci students have used Haskell during class. That's enough to be relevant.
>>
>>60126066
literally google openCL
>>
>>60126061
hmm i'm gonna try this
>>
>>60126059
The quote faggot? I guess he's a burger so is still sleeping in his parents' basement until 9AM EST like a good NEET.
>>
>>60124452
do you know where you are
>>
>>60126085
Wrong. And wrong.
>>
>>60126085
>Most comp sci students have used Haskell during class
source?
>>
>>60126134
All the comp sci students I've talked to used Haskell during lambda calculus class.
>>
>>60125629
Use it.
>>
>>60126160
So all the students at your own, one, university? Is representative of every comp sci student in the world.
>>
>>60126085
>Haskell
Switch that to ML and I'd believe you.
>>
>>60126005

rolling
>>
>>60126191
Multiple universities use Haskell during lambda calculus. Do you expect me to give you the personal information of all the people I talked to?
>>
>>60126230
Most comp sci undergrad degrees don't even have mandatory lambda calculus courses.
>>
>>60126243
k
>>
>>60124024

>blogging inside 4chan

genius.gif
>>
>>60126271
lmao retard
>>
>>60125710
running the program with time once isn't as scientific as i would like tbqh
>>
in C, when you want a function to return 1 on success or 0 on error, should you use a return type of int or char?

like, for example

int check(int a)
{
return a>0;
}


or



char check(int a)
{
return a>0;
}
>>
>>60126603
enum CheckState
{
CheckStateError,
CheckStateSuccess,
};

CheckState check(const int input)
{
return input > 0 ? CheckStateSuccess : CheckStateError;
}
>>
>>60126618
too verbose wtf

that's the same as
int check(int a)
{
return a>0;
}
>>
>>60126603
They're both the same. Just use int though, unless you have a good reason not to (like you're programming for a weird architecture). Int for numbers is more natural.
>>
>>60126603
use a bool

it's not less efficient because checking 1 byte has its own cpu instruction
>>
>>60126603
_Bool check(int a);

or alternatively who cares?
Also
sizeof(_Bool)
is probably not 1 ;-]
>>
>>60126603
int
>>
>>60126645
d:-D
>>
>>60126618
>>60126603
or just use the EXIT_SUCCESS and EXIT_FAILURE defines from stdlib.h
>>
>>60126603
Unless you have a good reason to change it, always default to int for return codes.

Also, consider changing the name of the function to "is_valid" or something similar that reads as a yes/no question, to it's obvious that you are returning a boolean where non-zero is positive, rather than the usual behaviour of return 0 meaning success.
>>
Gonna start a new machine learning project - any suggestions? I was thinking about trying a fingerprint reader but I think I might have trouble with getting enough training data
>>
>>60126710
finger yourself?
>>
>>60126719
he'd need to get tens of thousands of people to finger him
>>
>>60126710
trap detector
>>
>>60126710
a quake 3 bot
>>
>>60126726
hmm, i see
>>
>>60126710
>machine learning
so, computer learning?
>>
>>60124490
D can use C++ ABI libraries.
>>
>>60126882
>yet another tripfag
>>
what motivates people to tripfag?
>>
>>60126915
1) being a loser
2) being a faggot
3) being a loser faggot
>>
>too tired to dev
>too awake to sleep
ree
>>
>>60126966
masturbate
>>
>>60126966
>he doesn't even all-cap the REEEEEE
must be bad
>>
>>60126966
>URRRR DURRRR LOOK AT ME IM SO WOKE
>>>/pol/
>>
>>60127027
>>>/b/
>>
File: shiny.png (441KB, 575x575px) Image search: [Google]
shiny.png
441KB, 575x575px
>>60126966
You should get help for your addiction.
>>
Reminder that Norwegian is better than English for programming discussion.
>>
File: acm.png (85KB, 631x419px) Image search: [Google]
acm.png
85KB, 631x419px
>>60127119
nah, Russian, English and Chinese are superior
>>
I've come to the conclusion that Mathematica is simply the best declarative programming language.

No other programming language lets you input a naive spec of a difficult problem you want to solve, and after a short while get back an O(1) optimized solution to it.
>>
>>60127187
Mathematica is unethical.
>>
File: EntityComponentSystem.png (143KB, 861x833px) Image search: [Google]
EntityComponentSystem.png
143KB, 861x833px
>>60123996
Ok guys I really need help with
>pic related

I'm new to programming and I'm trying to learn Entity Component Systems for my game. I've come across these bitwise operators in this tutorial and I understand what its supposed to do, I'm just not understanding how its figuring out which component it is.

>each bit is reserved for a component type. For our example lets assume a 4 bit type instead of a 64 bit long

In this is it ok to assume that there are 16 different possible combinations? Or is it just only 4 types of components?

>our example entity would have all available components. So it's key would be 1111.

How would this be ALL available components? If I'm assuming its 16 different combinations wouldn't this be just one type of component?

>It can check an entity with a simple AND operation. So our entity matches if ((1111 & 1100) == 1100).

Again with the before if I do this (and sorry I don't know how to post code snippets) :

if((1000 & 1100 & 1110 & 0001) == 1111)

Wouldn't that be correct? So if this IS the correct way of obtaining the components, wouldn't it be easier just to check for the name of components instead of constantly adding more bits until you finish the game?
>>
File: 1462130217358.jpg (64KB, 499x499px) Image search: [Google]
1462130217358.jpg
64KB, 499x499px
>>60127159
>tfw I live near one of these
>>
hello

how hard is it to get live weather data and use it in a program/game? (specifically wind at different altitudes, but things like whether it's sunny or raining too)
>>
>>60127187
but muh types
>>
Why write code when you can write types and have the compiler write the code for you?

Shitlangs BTFO
>>
>>60127248
types are code
>>
File: idris_emacs.webm (192KB, 854x174px) Image search: [Google]
idris_emacs.webm
192KB, 854x174px
>>60127248
Can confirm, been learning Idris recently, the thing basically writes code for you.
>>
>>60127159
>conquer the world
>2017
>country is a shithole
Feels bad living in Western Europe ;_;
>>
>>60127235
not hard at all, just call api and parse json response

http://lmgtfy.com/?q=weather+api

now tell us about your project senpai
>>
>>60127278
It's like some devs want to do unnecessary work.
>>
>>60127278
What an ugly language
>>
Reminder that if your CS course didn't teach you a functional language, but instead only things like Java, C#, JS, or Python, then you got scammed.
>>
>>60127309
t. low taste dev
>>
>>60127240
Everything in Mathematica is an expression. Types are not very useful in that context, because almost everything would have the expression type.
>>
>>60127278
>use the example from the talk because it's one of the few cherry picked cases that works
>it only works because of how the situation is both simple and limited
>>
>>60127317
t. unemployed NEET
>>
>>60127320
Everything in Java is a primitive or an object type, and yet types are useful in it.

Use your brain, man!
>>
>>60127331
t. employed but stuck using shitlangs at work, actually

My CS degree may have been a curse in some ways because it taught me that there are better things out there than C# and whatever this week's JS framework is
>>
>>60127332
The entire point of Mathematica is that it will often avoid to evaluate things, so you will often be passing around things of unknown type.

Like for example, I can pass around an unevaluated polynomial of some global variable which hasn't been initialized yet. I can do all sorts of reductions or factorizations on it, before giving it a concrete value that may be of any type.
>>
>>60127325
It's not about the code in question, it's about the way Idris is able to deduce code for you based on types. Not only is Idris able to replace an argument with pattern matching branches based on its type, it understands what since both arguments in the example have the same length n, the patterns of the second argument should always have the same as for the first's. And after that it tries to deduce possible implementations based on the types available to it, correctly deducing what the only possible implementation for [] [] branch is [].
>>
>>60127361
So it supports polymorphism. That doesn't mean types would not be useful in it.
>>
>>60127410
>>60127325
>>
>>60127410
You're arguing with dunces, mate.
>>
stumped with
data Feeder =
Feeder String String


feed :: String -> IO (Maybe Feeder)

vomit :: Maybe Feeder -> String


How could I write a recursive function that would run feed with the value from vomit until it reaches the point of empty (i.e. Feeder "" _) while returning a list of String from the second value of Feeder (i.e. Feeder _ a)
>>
>>60127420
It's much crazier than that. You can do things like this:

>> f[x_] := Sum[i*i, {i, 1, n, 1}];
>> f[100]
338350
>> f[x]
x (1 + x) (1 + 2 x) / 6
>> a := f[x]
>> a
x (1 + x) (1 + 2 x) / 6
>> x = 2
>> a
5
>> x = Plot[y, {y, 0, 1}]
>> x
(returns a zoomable plot)
>> a
(returns a mathematical expression with zoomable plots as variables)


So expressions and their values are interchangable, and values of variables can depend each other, which means that their types may also depend on each other.
>>
Hey, can a kind anon answer my two questions?
Why do functions return int insteqd of bool incase of error?
Best programming languages for game development?
>>
>>60127543
What?
>>
>>60127571
>Why do functions return int instead of bool incase of error?
Be more precise
>Best programming languages for game development?
Be more precise
>>
>>60127187
it's useful for math but as a programming language it's a fucking mess and even for math stuff if it's a complex problem it can be difficult to debug and prove that it's correct
>>
>>60127571
An int for an error code gives you more to work with. You can specify multiple kinds of errors with ints and then check against a larger amount, as opposed to "something went wrong" (which is not helpful).
>>
>>60127543
Why does feed need the Maybe?
>>
>>60127571
>Why do functions return int insteqd of bool incase of error?
error codes or C tards thinking int is more efficient or more portable than bool
>Best programming languages for game development?
C++
>>
Can anyone help me in understanding the implementation of an adjacency matrix graph in Java?

I have two classes that represent the vertices & edges & the main graph class that constructs 2 arraylists to store the V & E, which are parameters.

I'm stumped on what to do next.

Any help or links to where I can get more info is much appreciated.
>>
>>60127569
Still not seeing why you think this means types aren't useful.
>>
>>60127580
In C++, for example, many functions return 0 in case of failure or 1 incase of success, problem is that they return int and not bool, isnt bool better for this type of returns?
>>
>>60127543
let me break it down for you
data Feeder = -- set the data equal to
Feeder String String -- feeder is 2 Strings


feed :: String -> (Maybe Feeder) -- Feed into String but maybe a Feeder we don't know

vomit :: Maybe Feeder -> String -- Vomit into maybe feeder? Probably returns String

>>
>>60123996
Working on getting the slackware package manager to work in a LFS system. Arg: more little problems than expected.
>>
>>60127577
main = do
kek <- feed "some initial"
-- Now I want to keep calling feed with the first value of kek (Feeder a _)
-- and this goes on while building a list of strings from kek's second value (Feeder _ b) until feed returns empty


>>60127594
another function inside which requires the maybe
>>
>>60127222
>wouldn't it be easier just to check for the name of components instead of constantly adding more bits until you finish the game?
If by "name" you mean "a string containing the name," sure, it might be easier. It would also be slower. If your game doesn't need to be fast, you don't need to worry about "correct" ECS implementation.
>>
>>60127633
yes bool is better in that case
>>
>>60127543
idk maybe (forgetting the Maybe because fuck that)
step :: Feeder -> IO String
step (Feeder "" _) = return ""
step x@(Feeder _ a) = feed (vomit x) >>= step >>= \b -> a ++ b

not tested, not saying it's not utterly broken
>>
>>60127631
Because functions are just rewrite rules for expressions. They can not be typed.
>>
>>60127633
It's neither better nor worse it's the fucking same thing
>>
>>60127679
Why are babies who've probably never seen a type system more advanced than C allowed to comment on what can and can't be done?
>>
>>60127649
Ok if the maybe is to be then
step :: Maybe Feeder -> IO String
step Nothing = return ""
step (Just (Feeder "" _)) = return ""
step (Just x@(Feeder _ a)) = feed (vomit x) >>= step >>= \b -> a ++ b
>>
>>60127679
They can. Your claim is absurd.
>>
>>60127705
spotted a missing return
step :: Maybe Feeder -> IO String
step Nothing = return ""
step (Just (Feeder "" _)) = return ""
step (Just x@(Feeder _ a)) = feed (vomit x) >>= step >>= \b -> return (a ++ b)
>>
>>60127705
>>60127724
thanks
>>
>>60127700
I've used Haskell and Coq. I've experienced what type systems have to offer. I'm still making the claim that no static type system would work for Mathematica, and any dynamic type system needs to be extremely permissive.

>>60127707
Because functions like Exp[x] are allowed to return the expression Exp[x] if x is not a number. If x is defined as a dependent variable x := Log[y], then Exp[x] can return y.

Mathematica functions are halfway between Haskell-like lazy functions and Lisp macros.
>>
>>60127789
Unless mathematica is completely incoherent then a type system would work fine
>>
>>60127620
can't you just like

class Graph {
int weights[N][N];

addEdge( int i, int j, int w );
}
>>
>>60127789
>Because functions like Exp[x] are allowed to return the expression Exp[x] if x is not a number. If x is defined as a dependent variable x := Log[y], then Exp[x] can return y.
So? This does not mean you can't have a type system. This does not mean types aren't useful.

What >>60127700 said.
>>
>>60123996
>Daily Programming thread
You mean "programming" as in "tv schedules"?
>>
>>60127827
(You)
>>
>>60127827
wasted joke potential
>>
>>60127827
I programmed your mum last night.
>>
File: 1491429975560.gif (4MB, 204x204px) Image search: [Google]
1491429975560.gif
4MB, 204x204px
>>60127827
>>
Dynamic typing is morally wrong.
>>
>>60127940
Extraordinary claims require extraordinary evidence.
>>
Why is the generate statement in VHDL so limited? I'm currently trying to create a tree structure with an arbitrary size and it's actually easier to just write a python script that outputs the VHDL code for it than to use pure VHDL with generate statements.
>>
>>60127963
Dynamic typing is detrimental to performance and correctness. It results in inferior products that are more expensive for end users. Pushing costs onto consumers is morally bankrupt behavior.
>>
File: Javascript development.jpg (376KB, 700x422px) Image search: [Google]
Javascript development.jpg
376KB, 700x422px
>>60127963
>>
C++ has polymorphism right? I can have an array of object pointers where each pointer might actually be pointing at things that have inherited from object?
>>
>>60127940
Any static type system wannabe is a inaccurate compared to Idris's, so all programming languages except one have a morally wrong element.
>>
var is a sin
>>
>>60128022
That is not incompatible with my post.
>>
>>60127963
What extraordinary claim?
>>
>>60128018
yes
>>
>>60127940
In 2017 it is.
>>
Reminder that console apps are useless at solving real life problems.
>>
>>60128036
This snippet
int arr[] = new int[2];
System.out.print(arr[4]);

Typechecks in Java (save for the fact that I probably mistyped it but you get the point) but produces an "inferior product" and is "detrimental to performance" because of the embedded bounds checking. Any type system that cannot statically enforce safe and fast array access is morally wrong according to your reasoning.
>>
>>60128077
>take console app
>wrap it in a GUI
>market it to normies
>>
>>60128079
Do you think I disagree?
>>
>>60128103
no
>>
>>60127789
>>60127797
>>60127817
Lots of people have implemented their own type systems for Mathematica.

Example: http://community.wolfram.com/groups/-/m/t/911604
>>
New thread:

>>60128161
>>60128161
>>60128161
>>
https://hastebin.com/ferazakuko.java

Trying to make this be able to preform a google search
>>
>>60128182
You probably want to use HttpURLConnection
>>
>>60128096
OSX: the movie
>>
>>60124137
>writing a driver in C++
Dumb. And if you're not writing a driver you're wasting your fucking time calling yourself a high performance network packet processing system.
I doubt you're actually getting anywhere that throughput with dynamic load.

A child could handle streaming data at that rate. Useless fucking product.
>>
C is fucking retarded and useless kill yourselves.
>>
>>60126915
That's an excellent question. In my case, it was boredom and a decent GPU.
Thread posts: 319
Thread images: 25


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