/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: __bowsette_and_princess_peach_mario_series_new_super_mario_bros_u_deluxe_and_super_mario_bros_drawn_ (663x1300, 790K)

Other urls found in this thread:

automatetheboringstuff.com/
interactivepython.org/courselib/static/thinkcspy/index.html
wiki.osdev.org/Expanded_Main_Page
dl.acm.org/citation.cfm?doid=1869459.1869462
ieeexplore.ieee.org/document/4273079/
ieeexplore.ieee.org/document/4404755
en.wikipedia.org/wiki/List_of_file_signatures
twitter.com/NSFWRedditVideo

First for Java

nth for nim

Why haven't you learned Haskell yet, Jow Forums?
good image OP

Attached: 1537985908896.png (1075x1518, 1.76M)

>making a thread as soon as bump limit gets hit

I wonder if the bowsette poster is the same person who would spam hime years back

Attached: K&R c.png (1000x1400, 1.31M)

what use case does hasklel excel at?

Why does strncpy always write n bytes? Wouldn't
char* copy_string(char* dst, char* src, size_t write_max)
{
size_t write_count = 0;
while( *src != 0 && ++write_count < write_max )
{
*dst++ = *src++;
}
*dst = 0;
return dst;
}

be much faster, especially as potential string length (n in strncpy) becomes large?

more than one himeposter

DSLs for parallel and distributed programming

Development time and program correctness.

it's a general purpose programming language and it excels at most things

Except memory usage and binary bloat.

yes

And cross-compilation.

shitposting

I don't buy that until someone posts benchmarks of such DSL vs MPI

uwu

Attached: Screen Shot 2018-10-02 at 7.48.10 PM.png (678x260, 34K)

based sepples

why "by"

>I write code that looks like shit so I can save myself a couple well-written lines doing something else

Maybe if it was efficient or something but it's not. Use C++ tools when they make the easier to read or understand, not harder

Like this
using System;
using System.Linq;

namespace DivisibleSumPairs
{
public class Program
{
public static void Main()
{
int k = int.Parse(Console.ReadLine().Split()[1]);
int[] list = Console.ReadLine().Split().Select(int.Parse).ToArray();

Console.WriteLine(DivisibleSumPairs(list, k));
}

static int DivisibleSumPairs(int[] list, int k)
{
int count = 0;

for (int a = 0; a < list.Length; a++)
{
for (int b = 0; b < list.Length; b++)
{
if (a < b
&& (list[a] + list[b]) % k == 0)
{
count++;
}
}
}

return count;
}
}
}

Attached: 1506112612488.png (601x508, 127K)

To paraphrase my post in the last thread: the C stdlib is just unbelievably shittily designed, and strncpy() is a prime example of this.

Anyway, sounds like you want strlcpy()

what does the "unit_type" do? also that unit is the same as just feet since a radian is unitless

>a radian is unitless

Attached: 1509893022495.jpg (1218x1015, 212K)

radian is length per length, making it unitless

god, C# is gross.

Thank you!

>for (int a = 0; a < list.Length; a++)
> {
> for (int b = 0; b < list.Length; b++)
> {
> if (a < b
*throws up*

*throws up*

post where you use it

What about it? I could have written it in a better but less compact way.

idk couldn't think of anything other than "times"
there will be wrappers for powers of course

believe it or not there is a use case for this
and I don't know what you mean by not efficient, syntax or performance?

radian is a dimensionless unit, there's a difference

The word you're looking for is dimensionless. It has a unit, the unit is 1 rad.

encasing everything in a class in a namespace.
the two loops, the formatting.

what's the use case?

APIs shared between well-established organizations who prefer working in their chosen units for a given application and can't be made to change, but where messing up the units could have significant financial impact.
Or just any code worked on by more than three people; the number of fucking times I've seen degrees passed to sin().

Wrapping everything in a class and a namespace might seem nonsensical for trivial stuff like this or Fizzbuzz but it's really not an issue and actually makes sense when you take the OO nature of the language into account. It does have its pros and cons, like everything else.

static int DivisibleSumPairs(int[] list, int k) {
int count = 0;
for(int b = 0; b < list.Length; b++)
for(int a = 0; a < b; a++)
count += ((list[a] + list[b]) % k != 0) ? 0 : 1;
return count;
}

M : [A] -> Type -> Type
return : B -> M [] B
join : M xs B -> M ys B -> M (xs ++ ys) B
mapM : (f : (x : A) -> M [x] B) -> (xs : [A]) -> M (map f xs) [B]

Hmm.

so something that can be done in a more readable manner

join : M xs (M ys B) -> M (xs ++ ys) B

Silly me, mixing up natural transformations and functions in the same type.

I'm just exercising the library, I don't expect it to be used like this

Huh, it says strlcpy is very similar to snprintf. Are you familiar with snprintf? I have a very hard time imagining how such a useful and relatively complex tool is not much, much slower than the more simple stuff (cpy, cat, etc), for simple stuff. It is, isn't it?

I'm sure it can be faster when cat'ing multiple strings or in other situations.

mapM : ((x : A) -> M [x] B) -> (xs : [A]) -> M xs B

Ugh.

just call it "multiply" fagtron

How do I into Python. Looks like a fun scripting language. What's a good resource for it?

You know, what I'm done. You know what I mean.

automatetheboringstuff.com/

if you don't know nothin' about programming
interactivepython.org/courselib/static/thinkcspy/index.html

If you're already a programmer, just download anaconda or miniconda with Python 3 and use Google every time you don't know how to do something.

If you're an IDE boy, use PyCharm and always use Python 3's type annotation features.

no

How does one start programming an operating system from scratch?

Thanks guys!

Google "strong typing"

I don't think the Scratch language is sophisticated enough for that

Attached: 1465542231484.jpg (454x558, 159K)

wiki.osdev.org/Expanded_Main_Page

>strong typing

Attached: affirmative_action_throwup.jpg (1300x957, 91K)

Thanky, fren.

Who put you up to this.

Attached: nani.png (258x243, 87K)

Strong typing is a meme. It hasn't been proven conclusively to actually improve program correctness or productivity.

the idea that you can place autistic restrictions on a language to prove certain facts about programs written using it is a relatively recent one
at the very least if you're not using C#'s unsafe blocks then you'll at least never run into pointer issues.

That's because the places where it would help can't be bothered to spend the budget to convert their legacy codebases.
I'm never going to stop shilling strong typing.

t. 150 buffer overflow and data races per line

i'm putting you up
this is a robbery

Attached: image (4).png (1080x963, 1.46M)

>static typing makes me write less bugs and be productive, r-right guys?

Attached: smug_hatsune.jpg (686x582, 156K)

>bugs are features!

>let's attack a strawman because I have no good arguments!

NO GOOD MORNING. FUCK YOU. BAD MORNING.
SHOOT ME.

You are like a baby, watch this
static int DivisibleSumPairs(int[] list, int k) =>
Enumerable.Range(0, list.Length)
.Select(x => Enumerable.Range(0, list.Length)
.Select(y => new Tuple(x, y)))
.SelectMany(x => x)
.Where(pair => pair.Item1 < pair.Item2
&& (list[pair.Item1] + list[pair.Item2]) % k == 0)
.Count();

Attached: 1515782572773.jpg (617x493, 54K)

>write less bugs
yes
>be productive
lol no but it's fun as fuck

>hatsune

Attached: 1537460465540.jpg (820x534, 58K)

Stop lowering the thread's quality.

You should learn Scheme and ML first.

You can't stop me Varg, you'll never be my real dad!

install Shen instead.

You're the one claiming that static typing improves productivity and correctness. Here are some sources to support my claims (You haven't provided any arguments, let alone sources).
dl.acm.org/citation.cfm?doid=1869459.1869462
ieeexplore.ieee.org/document/4273079/
ieeexplore.ieee.org/document/4404755

Attached: dance.gif (300x269, 521K)

>teleports behind you
>it's already a good morning

Attached: 1524715780160.jpg (930x700, 448K)

nigger

>pay or sign in to read this
yeah, i'm gonna need non-trash links.

I guess you lost the argument then. Stay mad.

Attached: smug_laugh.png (782x1021, 330K)

you dont win arguments by posting studies behind a paywall

You never provided an argument or sources. I guess I win by default then.

Attached: smug_anime_face.png (1350x1126, 1.52M)

Attached: pyramid of argumentation.jpg (777x656, 119K)

#include search starts here:
/usr/include/c++/7
/usr/include/x86_64-linux-gnu/c++/7
/usr/include/c++/7/backward
/usr/lib/gcc/x86_64-linux-gnu/7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include

Can somebody tell me where are stored and defined the directories and search order for the default includes in gcc for the C and C++ compilers? I get the above from the g++ but I cant find the source.

Jehovah's Witnesses don't celebrate Halloween because they don't appreciate random people coming up to their door.

worst /dpt/ in recent memory
post eloquent C please

>post eloquent C please
here's the complete list

What's the easiest way to determine if a file is a music file in C? I could just compare extensions but that just sounds hacky and bad. The only other way I know would be to ensure it has an audio stream via libav/ffmpeg. Is that as slow as it sounds? Is there a faster/better way?

Thank God this is a christian board then

#include
int main(c, v)
int c;
char** v;
{ return atoi(c[1]); }

en.wikipedia.org/wiki/List_of_file_signatures

why is comparing extensions hacky?

import turtle
x = 0
while x < 100:
x = x + 1
turtle.forward(x)
if x % 3 == 0 and x % 5 != 0:
turtle.right(90)
elif x % 5 == 0 and x % 3 != 0:
turtle.left(90)
elif x % 5 == 0 and x % 3 == 0:
turtle.circle(x)

Attached: chie.webm (324x438, 69K)

Here is a neat C trick.
#include

#define calculate(...) \
calculate_f((calculate_s) { .a=1, .b=1, .total=0, __VA_ARGS__})

typedef struct {
int a;
int b;
int total;
} calculate_s;

int calculate_f(calculate_s t)
{
return t.total + t.a * t.b;
}

int main()
{
printf("%d\n", calculate(.a=12));
printf("%d\n", calculate(.b=10, .total=10));
return 0;
}

Attached: cat_computer.gif (500x388, 929K)

because you can rename file extensions to whatever you want
file format specs should have information telling you what their signature or header should contain

steam it in and do some FFTs to ensure there are no sharps or flats if you meant C Major.

strong typing > weak typing

This nigga

Science Says You're Wrong

>if a file is a music file
All files are music files

Explicate.