/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: pl-alignment.jpg (1000x800, 159K)

Other urls found in this thread:

amberframework.org/
crystal-lang.org/
en.wikipedia.org/wiki/Automatically_Tuned_Linear_Algebra_Software
docs.oracle.com/javase/8/docs/api/java/util/Optional.html#ofNullable-T-
twitter.com/SFWRedditGifs

First for C.

Wrote a function in Haskell:

import Data.List
import Data.List.Zipper as Z (toList, duplicatez, fromList, Zipper(..))
import Data.List.NonEmpty as NE (nonEmpty, toList, NonEmpty)
import Data.Bifunctor
import Control.Monad

anyEqualPartitions :: [Integer] -> Bool
anyEqualPartitions = maybe True (foldl' (||) False . ((.) . fmap) (uncurry (==) . bimap sum sum . (\x -> case x of Z.Zip l r -> (l, r))) ((Z.toList . Z.duplicatez . Z.fromList)

haskell's operator sugar is pretty disgusting.
i can't even find a nice breaking point to split that into multiple lines

Second for C.

replace Erlang with Common Lisp and replace Go with Perl, and replace Perl with Erlang

* is used to indicate that a new variable is a pointer, but when used in assignment/access, it means the _value_ the pointer points to. The pointer IS a value of a memory, indicating there is something at the other end. During variable declaration (int *ptr) you create the variable, and definition ( = &var) you assign that the value of ptr is the memory cell of that used for 10.

When you do it in two steps it is assignment in the second step, therefor you're saying the value of ptr is the memory cell, not the value contained within which memory cell ptr currently references.

See
for some pointer uses. I could upload the whole code.

Variables are automatically scoped. In a { block } you can define any variable you want. It will only exist within that scope. Basically the scope check in C is if it's defined in the local block, it's a local var, otherwise it's a global.

I'm making a lemonade stand game in C with ncurses!
I'm learning C so my code is garbage compared to the magic some of you right, but I plan on reading K&R sometime soon to actually learn the language.

Attached: 2018-07-31-222804_3840x1080_scrot.png (3840x1080, 2.25M)

Here's a more readable version of the code:

partitionSumsEqual :: ([Integer], [Integer]) -> Bool
partitionSumsEqual (l, r) = sum l == sum r

extractPartition :: Zipper a -> ([a], [a])
extractPartition (Zip l r) = (l, r)

zippersAtAllPositions :: [a] -> [Zipper a]
zippersAtAllPositions = Z.toList . Z.duplicatez . Z.fromList

anyPartitionWithEqualSums :: [Integer] -> Bool
anyPartitionWithEqualSums [] = True
anyPartitionWithEqualSums xs =
let zippers = (permutations xs) >>= zippersAtAllPositions
in any (partitionSumsEqual . extractPartition) zippers

yeah that does look cleaner.

If you wanted to make it cleaner, but not create a new function definition in the module, you can use the `where` keyword.

>magic some of you right
*write
god I'm fucking retarded ):

fpbp

Someone convince me to refactor the huge mess I made please I beg you

just rewrite it from scratch and copy/paste everything

You'll thank yourself tomorrow if you just get it doe today. If you're working with other people they'll greatly appreciate it too.
Put on some tunes, maybe brew a cup of coffee or tea, and just start hacking away at it.
Do it for me, onii-san!

Attached: 1532686037409.gif (322x287, 46K)

I already did that once though.

Is there any way in C to get the current windows explorer sorting type of a folder? For example whether the folder is sorted by data, last modified, etc.

The fuck is that? >returning locally declared structures

That should be very wrong, is it just a newer revision that lets him dynamically allocate shit or is he programming cpp in a .c file and it's not throwing a fit?

I.e. all local non-static vars should be released from existence unless allocated on the heap.

put more thought into it this time

its all placed on the stack, or registers if its small enough

>foldl' (||) False
isn't this just or

Is it weird that I like the old K&R C over ANSI C? It's just so simple and comfy

wtf am i readin

Thinking about learning elixir because I always wanted to learn Ruby but all the other bits put me off (performance, no jobs, not much future etc)

oh boy

Attached: G6h3mAf.jpg (1564x1564, 372K)

>no jobs
elixir is starting to blow up though.

If the performance of Ruby puts you off, don't even look at the performance of Elixir
it is much worse than Ruby.

All in all, I like it a bit better because it is a proper functional lang which is highly robust.

Elixir, like most new tech, is really only gaining popularity in the startup world.

how else do you think new tech gets picked up by the big companies?
They look at which startups are using what and how they're progressing.

programming has such a shitty fucking mindset with the no adoption because no people because no adoption plague. Haven't heard about the performance issues though, most people who use elixir and phoenix rave about its insane scalability.

K&R C is better.

Well, Elixir is not very good for number crunching. Elixir is based of Erlang and the BEAM VM which was designed for high reliability, concurrency and scalability.

>Elixir is not very good for number crunching
obviously you dummy, web shit in general is not good for number crunching.
you may want to look into the most feasible wasm solution.

I meant that ruby has no jobs, where I live new stuff like Elixir is ironically vastly more popular than something like Ruby. Sounds crazy, but yeah.

Yeah, people hear "parallelism" and think "number crunching performance boost", then they are disappointed because it is not that.

because ruby is old and busted shit.
check out amberframework.org/
and crystal crystal-lang.org/
it's basically just compiled to c ruby

Why does C++ use this-> instead of this.?

this is a pointer

because bad design. also this is a pointer.

I checked. The draft spec doesn't explicitly say it, but you can return the contents of an entire structure to another at the return of a function.

Absolutely disgusting though.

If I'm doing linear algebra using "real time" data should I use Sepples with some library, C and writing the libraries myself, or Python and search for a numpy / scipy lib that already does what I'm trying to do? (Just recursive least square, and maybe fancy it up later on)

>C and write the libraries myself
What would make you think a C lib doesn't exist?

I know about the scientific GNU but I don't want to use GPL license

What are you, chicken?

Just a hoarder wanting to make tons of money, hacker.

en.wikipedia.org/wiki/Automatically_Tuned_Linear_Algebra_Software

Remember to loan your shekels wisely

breddy gud op pic :-DDD

What resources to learn modern C++? When I learned it was more like C++98 or as C with classes. Haven't touched it in a while so looking at anything C++11 and beyond looks like an entirely different language.

I've noticed that there are hardly any free resources for learning cpp compared to other languages nowadays.

Still working on the rabbit breeding mini-game.

I spent like 3 hours trying to convert the first rabbit image into a correctly scaled image button and I just commented it out, I'll come back (TM).

Attached: app dev image.png (4404x1928, 631K)

The absolute state of dpt

With an array of uint64_t *arr;, which is safer
arr[j >> 6] |= (1UL > 6] |= ((uint64_t) 1

lol what a retard you are
it's standard practice you absolute mong

arr[j >> 6] |= UINT64_C(1)

Could someone recommend a good book on C++03? I am very familiar with C17 and want to move on to C++, but not too fast.

C++ is garbage; don't bother.

I need a job.

learn a real programming language

Such as?

JAI

Learn to read.

it will revolutionize the game dev industry!!!!

It will flop, like all meme languages do

it's not a meme, jon blow is a genius, he made this puzzle game where time like, goes BAKCWARDS and it's way too deep for a pleb like you to understand

javascript

If I want to plot data out of a C++ program (plot curves and update regularly), would I be shun down if I embed a python script?

????????????

How to Avoid Huge Ships by John Trimmer

java, aka the nonshit version of c++

C#

"how to kill yourself by trying to learn a shitty language"

Let's say I want to plot a "sliding sin wave", something like
n = 1000;
double x[n];
double s[n];
x[0] = 0;
s[0] = 0;
double dx = 0.001;
double phi = 0;
double time = 10;
eps = 0.01;
while(phi < time){
for(int k = 1, k < n, k++){
x[k] = x[k-1] + dx;
s[k] = sin(x[k] + phi);
}
// I want to plot the sin wave at every iteration
phi += eps;

so I considered calling a python script and use matplotlib

Seeing as I accidentally wrote 1UL where I meant 1ULL, I suppose that macro is useful to eliminate mistakes like that. But all 3 forms compile to the same code on my machine, as does replacing 63 with its hex value.

this is from before references existed in the language.
so this is a pointer, rather than a reference
and because it's a pointer you must dereference it to access members

if this was added today, it would be a reference not a pointer

Realize now before you start that the biggest problem with sepples is how out of date much of the knowledge about how to write good c++ code is. Anytime you learn anything about the language, be cautious about whether or not it is good practice today.
You can write old-style c++ pretty easy, in pretty much the same way that big C projects write "object oriented" C. Many big C projects have a bunch of structs, and a bunch of what are basically member functions that take a struct pointer as their first argument. Writing these kinds of programs in c++ is easy to do.
The most important thing is to get your head around RAII, and how it let's you completely avoid manual memory management with new/delete.

#include

/*This programme replaces every 4 spaces with a tab*/

int main(int argc, char const *argv[]) {
int c, i;

i = 0;
while((c = getchar()) != EOF) {

if (c = ' ') {
++i;
} else {
for (; i > 0; i--) {
printf(" ");
}
putchar(c);
}

if (i = 4) {
printf("\t");
i = 0;
}
}
}

I'm working my way through the C programming language book and got stuck on this exercise, whenever I try this it just replaces every letter with a tab instead of just every 4 spaces.

Attached: 1409220454430.png (600x624, 170K)

>if (c = ' ')
This is an assignment.
You meant to do if (c == ' ') for equality.

Holy shit I'm retarded

Yup, saw it straight after posting.

Attached: mercyiwanttodie.jpg (829x964, 79K)

That's typically how it goes; realising your fucking right as you're asking for help.
For that error in particular, compilers will actually warn about it. Make sure you're compiling your code with at least -Wall, and preferably -Wextra as well.

In Java, I want to see if scanner hasNextInt(), if so create an optional type. What's the correct way to achieve this?
return Optional.of(istream.hasNextInt() ? istream.nextInt() : null);

How do you post code in the white box?

Yeah, K&R just told me to use cc, but I know that there are better ways to compile.

>Optional
I thought Java didn't support generics on primitive types.
I suppose docs.oracle.com/javase/8/docs/api/java/util/Optional.html#ofNullable-T- might be useful.

cc is just the standard unix way of calling your C compiler, but is basically just an alias for GCC. You can safely pass extra command line options to it.

That, how do you do that?

Read the damn sticky.

Good enough answer. Thank you.

I'm trying to put various types of eye images over a body pattern, the images have the same dimensions and are layered correctly, but something about this section of the program is malfunctioning.

public void DisplayEyesBabyOneMethod () {
HareEyesBabyOneView.setImageResource(Eyes[BabyMethod(hairy, lola).EyesType]);
int babydimension = (75*BabyMethod(hairy, lola).size)/150;
FrameLayout BabyFrameOneEyesLayout = (FrameLayout) findViewById(R.id.BabyFrameOneEyes);
FrameLayout.LayoutParams WrapParam = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
FrameLayout.LayoutParams CenterParam = new FrameLayout.LayoutParams(150, 150, Gravity.CENTER);
BabyFrameOneEyesLayout.setLayoutParams(WrapParam);
BabyFrameOneEyesLayout.setLayoutParams(CenterParam);
HareEyesBabyOneView.getLayoutParams().height = convertToDp(babydimension);
HareEyesBabyOneView.getLayoutParams().width = convertToDp(babydimension);
}
public void DisplayBodyBabyOneMethod () {
HareBodyBabyOneView = (ImageView) findViewById(R.id.HareBodyViewBabyOne);
HareEyesBabyOneView.setImageResource(Bodies[BabyMethod(hairy, lola).BodyType]);
int babydimension = (75*BabyMethod(hairy, lola).size)/150;
FrameLayout BabyFrameOneLayout = (FrameLayout) findViewById(R.id.BabyFrameOneBody);
FrameLayout.LayoutParams WrapParam = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
FrameLayout.LayoutParams CenterParam = new FrameLayout.LayoutParams(150, 150, Gravity.CENTER);
BabyFrameOneLayout.setLayoutParams(WrapParam);
BabyFrameOneLayout.setLayoutParams(CenterParam);
HareBodyBabyOneView.getLayoutParams().height = convertToDp(babydimension);
HareBodyBabyOneView.getLayoutParams().width = convertToDp(babydimension);
}

With the images being the same dimensions, and overlapping perfectly in GIMP, I don't see why the supposedly centered and identically scaled images would be askew.

Attached: misoverlap.png (152x169, 9K)

Could you make your code any more dense?

lisp is just javascript with parentheses

It wouldn't be like that if I knew what I was doing, I only started programming at all in May.

Newlines and imports are free. Also your naming convention is bad.

Scott Meyers effective modern c++ explains all the new fetaures. Google and stackoverflow the rest, or ask here.

You should see my first program

public void RenderMethod(){
UltraDummy = 1;
Exim.setImageResource(Emagos[UltraDummy]);
JI = J % imagos.length;
Jim.setImageResource(imagos[JI]);
FI = F % imagos.length;
Fim.setImageResource(imagos[FI]);
xI = x % imagos.length;
yIm.setImageResource(imagos[xI]);
if (YY >= 1 || HHTwo != 0 || YY != 0) {
wI = 1;
} else if (YY == 0 && HHTwo == 0) {
wI = 0;
}

if (XX >= 1 || HH != 0 || XX != 0) {
WI = 1;
} else if (XX == 0 && HH == 0 ) {
WI = 0;
}

if (GG >= 1 || VV != 0) {
GGI = 1;
} else if (GG ==0) {
GGI = 0;
}
QQIm.setImageResource(Emagos[GGI]);
eIm.setImageResource(Emagos[WI]);
EIm.setImageResource(Emagos[wI]);

if (N >= 1 || HHTwo != 0 || YY != 0) {
NI = N % imagos.length;
Nim.setImageResource(imagos[NI]);
} else if (N == 0 && G == 0 && L == 0 && Q == 0 && O == 0 && Sh == 0 && HHTwo == 0) {
NI = N % imagos.length;
Nim.setImageResource(Emagos[NI]);
} else {
NI = N % imagos.length;
Nim.setImageResource(imagos[NI]);
}
if (G >= 1 || HHTwo != 0 || YY != 0) {
GI = G % imagos.length;
Gim.setImageResource(imagos[GI]);
} else if (G == 0 && L == 0 && Q == 0 && O == 0 && Sh == 0 && HHTwo == 0) {
GI = G % imagos.length;
Gim.setImageResource(Emagos[GI]);
} else {
GI = G % imagos.length;
Gim.setImageResource(imagos[GI]);
}
}

it goes on like this for 340 lines

Ahhh yes.. The joy of GUI programming in Java

Serious question, since Java is my first experience with any programming language, what has a better GUI system?

My brother suggested I move my entire game into unity.

All GUI systems are basically terrible.

In Go, can you access struct fields from interface methods? Does Go have default interface method implementation?

>javafx

what do you mean by a gui system?

yes, no (but it does have an automatic delegation system which may fit the bill)