/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

togototo.wordpress.com/2013/08/23/benchmarks-round-two-parallel-go-rust-d-scala-and-nimrod/
github.com/kostya/benchmarks/blob/master/README.md
attractivechaos.wordpress.com/2011/06/22/my-programming-language-benchmark-analyses/
tonyarcieri.com/it-s-time-for-a-memory-safety-intervention
npmjs.com/package/is-zero
raw.githubusercontent.com/mohayonao/is-zero/master/lib/is-zero.js
cl.cam.ac.uk/~mgk25/pet2004-fpd.pdf
twitter.com/NSFWRedditVideo

first OwO

second!

If your language has GC, then its performance is necessarily inferior to C/C++/Rust, and you cannot use performance as an argument for using it.

trying to solve a problem i've created using algorithms that are way beyond my capacity

That's not a strawman really. D is designed such that most "obvious" code is fast and safe. On occasion a function might need to escape the confines of type safety for ultimate speed and control. For such rare cases D offers native pointers, type casts, access to any C function without any intervening translation, manual memory management, custom allocators and even inline assembly code
import core.stdc.stdlib;

void livingDangerously()
{
// Access to C's malloc and free primitives
auto buf = malloc(1024 * 1024);
// free automatically upon scope exit
scope(exit) free(buf);
// Interprets memory as an array of floats
auto floats = cast(float[]) buf[0 .. 1024 * 1024];
// Even stack allocation is possible
auto moreBuf = alloca(4096 * 100);
//...
}

// Using inline asm for extra speed on x86
uint checked_multiply(uint x, uint y)
{
uint result;
version (D_InlineAsm_X86)
{
// Inline assembler "sees" D variables.
asm
{
mov EAX,x ;
mul EAX,y ;
mov result,EAX ;
jc Loverflow ;
}
return result;
}
else
{
result = x * y;
if (!y || x

Friendly reminder that if your language doesn't have a specific data structure, it doesn't exist and asking people to "make it themselves" is not a valid engineering advice in 2017 where downloading a library for one function is faster than learning to implement it yourself.

cirno is cute!

Download me a regex parser for x86 assembler

I was at the hospital today and had a camera shoved up my dick, it hurts like hell now and I can't concentrate on programming.
wat do, Sup Forums?

Is it advisable to store non-pointer values in a pointer?

>dude just implement it yourself lmao

c apologists are awful

>c
Literally no one cares

You know there's plenty of libraries you can access from C that does 99% of basic shit.

I suggest that such cases are not rare.

So, if you want performance, you have to use an ugly wrapper around C? Why not just use C++ and benefit from more consistent code and more mature tooling and ecosystem? After all, in C++ most "obvious" code is also safe and actually fast.

Yes, this is an excellent idea, very good.

togototo.wordpress.com/2013/08/23/benchmarks-round-two-parallel-go-rust-d-scala-and-nimrod/
github.com/kostya/benchmarks/blob/master/README.md
attractivechaos.wordpress.com/2011/06/22/my-programming-language-benchmark-analyses/

Wow, just look at those inferior speeds

what do you expect to be told

how do you ever store non-pointer values in a pointer?

No, you should never store anything in a pointer

int *ptr = 14;

You can do it with C unions.

>its okay when c does it
>its not okay when JS does it

well, that's a segfault.

this guy is fucking EPIC

int *ptr = "hello world";

>Programming in C means you are using an unsafe memory model 100% of the time. It is the programming equivalent of trying to walk a tightrope over a lake full of alligators while trying to avoid getting electrocuted by dangling power lines. The slightest mistake in your arithmetic at any one place in the code can be the difference between a perfectly safe program and remote code execution.
tonyarcieri.com/it-s-time-for-a-memory-safety-intervention
When will C fags learn?

If you don't try to dereference it, it's not an issue.

>I suggest that such cases are not rare.
Wrong.

>ugly wrapper
Or ugly wrapper around ASM like C people do

I don't think there's ever been a C library for checking whether a value is zero.

npmjs.com/package/is-zero

>dude php!
do you know what pointers are for?

>I can't write safe C code, therefore nobody can
I'm sure there's a name for this fallacy.

>Or ugly wrapper around ASM like C people do
Hardly. C is portable, ASM is not.

raw.githubusercontent.com/mohayonao/is-zero/master/lib/is-zero.js

>positive zero
>negative zero
is this a joke?

>isPositiveZero
>isNegativeZero

>Hardly.
Um, no not hardly. I see ASM being used in C projects very frequently, because C belongs to that niche

C fags are delusional. Keep creating work for infosec. I hear Blackhat 2017 is going to have a all you can eat shrimp buffet
>tfw I'm a pentester and C fags are making me rich

struct node {
void *data;
struct node *next;
};

So instead of writing a separate list container that holds a head pointer and the depth, just start with a node and use the next pointer to hold the depth value.

source of that gif?

>what is IEEE754

Anyone got experience with this retard dotCover? It's saying my code isn't properly tested but AreEqualIncludingHashCodes(null, null, true) and AreEqualIncludingHashCodes(null, null, false) should cover the whole null block

Only if you're writing bare-metal software for a single-tasking machine.

>having your CPU nearly melt down from playing a 2D turn-based game is normal
Java apologists are awful.

an abomination

>your CPU nearly melt down
Poorfags BTFO

Real talk here, where have you ever just sat down and thought to yourself "Well fuck I only wanted to execute that code on negative zero, not positive zero!"

Reminder that C does polymorphism better than Go.

Now that was edgy

Well, Go has strings

savage

So does C.

typedef char* string;

rekt

Go has nothing going for it
it needs killed

>import "fmt"

func main()
{
fmt.Println("Hello, 世界")
}


is invalid code.

>public static void
Java?

That's just sad.

Nope. C strings are very efficient.

C#, it's a class of test methods wrapping NUnit

Why do people make fun of me when they find out my whole program is written in C?

Because it's C

nice headers, nerd.

First language: Haskell
Second language: Idris

What should I learn as my third language?

Because they are not people.

No one is making fun of you, they're just happy there's a larger attack surface for them when they want to steal people's baking info

Patrician

Learn Cyclone or Rust

There's literally no need for a "depth" value, especially if you'd need to traverse the list to the last element anyways. Just do

size_t depth(struct node *head) {
size_t n = 0;
struct node *a_node = head, *next_node = a_node->next;
if(a_node != NULL) {
while(next_node != NULL) {
a_node = next_node;
next_node = a_node->next;
n++;
}
}
return n;
}

What if user's software isn't going to use network?

Why?

cl.cam.ac.uk/~mgk25/pet2004-fpd.pdf

>oh god my braces this is very very important how will i program now hepl me denis richie im being oppressed oh god ohgod oh god

Considering the number of string operations that require foreknowledge of the size of a string, no not really.

>cyclone
>literally a proper C++
>now ded

wow

My main computer is a laptop. I don't see any point in buying a super-powerful meme processor that couldn't run for more than five minutes without needing water cooling anyway. Besides, if a game isn't a 3D game from the last five years, it shouldn't be straining a modern processor. That's either a sign of bad programming, or using the wrong tool for the job.

Good news is Cyclone lives in Rust

I'd happily share my cookie recipe if they just asked, no need to hack me.

python-tier parsing
muh freedoms
If i cant format like a human, then no thank you

Well what even is the POINT of having braces if the compiler is going to sperg out about significant whitespace anyways?

And rust is nothing like a proper c++
ripip

Does that sequence contain a byte that would be " in ASCII?

Well, that's not C issue now, it's electromagnetics issue now.

How is this a C only problem?

congrats you just turned measuring the size of the list into an O(n) operation

So, guys, I have a question about solving a personal problem using programming.

I have a huge picture folder with probably thousands of pictures (at least hundreds) that are divided into subfolders.I place a new picture into a subfolder, and then create shortcuts for other relevant folders (that way I don't have dozens of copies of huge pictures uselessly eating up hard drive space). I recently moved my greater picture folder to a different hard drive. I'm sure that you can see the problem.

Going right click -> shortcut -> cut -> paste multiple times for every picture that goes in more than one folder would take hours. I figure that what I can do is create a list of every subfolder, and then have the program prompt where to move the picture to (if necessary) and where to place the shortcuts. Problem: I have zero knowledge on manipulating windows features specifically.

>Use this program!

Unless this would somehow take a ridiculous amount of work, it would be a good exercise to write it myself.

So how would you do it, without having a separate field in at least one node?

This may be more of a math-related problem, but I figured I'd give it a try in /dpt/. I've been working on a performance calculator for large airplanes using some fuel-burn profiles I found online. The problem I am having is that in order to calculate total weight, you first need to know total fuel, which you can't calculate until you know the proper burn rate. Here is some pseudocode:

private int calculateOptimalAltitude(int grossWeight) {
....
// queries a table that returns an optimal altitude given a weight
return altitude;
}

private float calculateFuelBurn(int altitude, int grossWeight) {
....
// queries table shown in image to return the optimal fuel burn based on altitude/weight
return fuelBurn
}

private float getGrossWeight() {
return emptyWeight + payload + fuelLoad;
}

Can anyone point me in the right direction?

just store the depth dumbass
increment when pushing a new node

Whitespace isn't significant in the core language; statements are all terminated by semicolons. The compiler does a quick pass over source files to insert semicolons after certain tokens so programmers don't have to. This also has the not-unintended side effect of mandating a certain brace style, which the designers were fairly happy with.

If the braces were removed there'd be nothing to mark the ends of functions without redesigning and complicating the current grammar to have it pay attention to indents.

Also, Java.

I was honestly never really interested in Java, but thanks to my comp sci classes (just started), this is the language that I'm the most fresh on.

Which to learn is better, Sun-Oracle C# or Microsoft Java?

It might get optimized out by the compiler anyway. Still shouldn't be retarded for the sake of simplicity.

Haskell

If I run Mono on my sparc64 machine, does it count as Sun/Oracle C#?

As usual people in /dpt/ can't read.

Common Lisp

>It might get optimized out by the compiler anyway
No, it certainly wouldn't. That is way beyond what a modern compiler would do.

Explain how a compiler is able to optimize away what is effectively a while loop of arbitrary length that may or may never halt.

What do i need to create a programming language with clear syntax and high performance?
Something simple and efficient.

typed lambda calculus
consistency

how do i become programmer god and write hundred thousand lines of code a day?

Just recreate C, but faff around with the syntax a bit.

How much performance is high for you?
What kind of syntax is clear for you?
What's complicated for you?

AND NEVER BRING MEANINGFUL WHITESPACE

you don't need to do that, just use C

Lisp

>More lines of code is better
Spoken like a true programming nooblet.