/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.22
stackoverflow.com/questions/4638473/how-to-powreal-real-in-x86
twitter.com/SFWRedditVideos

>1 post early
kill yourself

First for Haskell

Reading the entire section on higher order functions in javascript made me want to vomit in my mouth a little bit.

Everything about higher order functions in JS is so fucking wasteful and yet the author goes on and on about how "beautiful" and "clean" it is.

I can't even read half the shit he wrote, passing function literals is not elegant.

Swap to Hasklel or F2#

>being this autistic

also post code

>Reading the entire section on higher order functions in javascript made me want to vomit in my mouth a little bit.

SICP is the only answer.
Learn from the masters.

Get raped and kill yourself, you retarded fucking faggot sack of shit with down syndrome.

I was working on a program to create DLC deck recipes for Tag Force Special. That project died a quick death.

Last night I started a little project for a simple renderer. I called it a night when I was too tired for simple vector calculations (how to find the viewport pixel world coordinates when given the eye point, another point the camera is looking at (defining view direction), distance of viewport from camera, viewport width and height in pixels and viewport width and height in object space).

Related to uni:
Reminder that NI LabVIEW and similar graphic """programming""" """languages""" are complete and utter shit and can't produce any results an hour or two of coding won't.

nobody uses those meme tools anyway you sperg

"Graphic/visual" (though they really aren't) programming languages are the future

I should add - the problem is that all instances of them are shit atm

Actually there are two modules just in the first semester of my masters studies that require similar shit: one needs LabVIEW, one needs simulink.
> you can't even zoom in on your frontpanel or block diagram in LabVIEW
> several GB download just to run it
> Windows only, maybe Mac, and some chosen few GNU/Linux distros if you bend over and pay
> have to set up a VM, pirate Windows and wait several hours just to use this cuck abortion of a programming environment
Why is this allowed? Going back home and just coding some C in gedit was bliss compared to that.

>require
As in absolutely? No workarounds to get your projects done?

What are some good ways to practice programming other than doing projects?
I am self-taught and not looking to be a software developer, but I need to program for finance, especially trading related.

Nope, no alternatives allowed and I wouldn't even know if there are any. The point is to learn how to use these programming environments since they're """industry standard""" (i.e. idiots who barely passed their shit can have something to click around in because coding is harrrrrd, then give up and let me rewrite their program in C or Python). At least in the previous semesters we were allowed to substitute GNU Octave for MATLAB.

well it gives 2 different results, probably due to rounding. Which is probably what he originally wanted
let ayy n = List.takeWhile(fun i -> i * i < n) [1 .. n]
let kek n = [1 .. n |> (float >> sqrt >> round >> int)]

> ayy 135;;
val it : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11]
> kek 135;;
val it : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12]

I recently got into programming to start prepping for an upcoming course and this is throwing me off. My Java program compiles fine, and throws no errors, however it returns a 3 on my first sysln and a 2 on my 2nd. What is happening? Surely a pajeet can help? I started learning java tonight don't judge me Sup Forumsentleman


public class NewClass {
public static void main(String[] args){
int a = 1;

System.out.println(a^2);
System.out.println(a^3);
}
}

>started learning java
Then it's a good time to stop

^ is bitwise XOR, not exponent

^ isn't exponentiation it's binary XOR

java doesnt have bitwise operations you dunces

Shoot me a pointer guys this shits weird. Thanks ahead of time.

pajeet...

Really?
docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.22

This wasn't me, just help please. I'm clueless with java

Haven't tested yet, but I think this ARM assembly should do add and shift multiplication:

.section .text
.global multiply

@ Compute multiplication of two 32-bit integers
@ without the use of a multiplication instruction.
multiply:
@ If second argument is negative, negate both arguments.
@ This ensures pos * neg = neg, neg * neg = pos, pos * pos = pos.
TEQ a2, #0
BPL .L1
NEG a1, a1
NEG a2, a2
.L1:
@ If first or second argument is 0, return 0.
MOVEQ a1, #0
TEQ a1, #0
BEQ lr
@ Employ a variant of square and multiply exponentiation
@ called "add and shift" to ensure O(log(a2)) multiplication
@ of the arguments. Register a3 will be used as a scratch for this.
MOV a3, #0
.L2
@ While a1 > 1:
CMP a1, #1
BLE .L3
@ If a2 is odd, add a1 to a3
TST a2, #1
ADDEQ a3, a3, a1
@ Multiply a1 by 2, divide a2 by 2.
LSL a1, a1, #1
LSR a2, a2, #1
@ end while
B .L2
.L3:
ADD a1, a1, a2
B lr

When you xor 2 numbers, any bits that are the same return a 0, any bits that are different return a 1

1001
^ 1100
----
0101

You want to use
Math.pow(double,double)

so
public class NewClass {
public static void main(String[] args){
double a = 1.0;

System.out.println(Math.pow(a,2.0));
System.out.println(Math.pow(a,3.0));
}
}

such verbose syntax for such common functionality, surely there must be an operator not in use they can use for exponents

Welcome to java!

What tool do you guys use for Class Diagrams?
Coding a side project and it's getting pretty big
Needs to look good and be easy to update

If you are worried about that being verbose just wait for public static HashMap myvar = new HashMap()

Will this work for exponential growth? Is that how Java works? I'm sorry to be such a fucking noob about it dude but I'm having issues finding some actual direction in this book.

>UML

uml is a fucking scam and nobody bothers with this shit in the real world

PyCharm has one built-in. It makes work really easy when co-workers are using mixins and inheritance fucking everywhere

>Class Diagrams

If you mean exponentiation off of a previous power you will have to:
double a = 2.0
a=Math.pow(a,2.0)
System.out.println(a) //4
a=Math.pow(a,2.0)
System.out.println(a)//16

Gonna make a baseball GM sim for my summer project

I'm 4th year software dev student and they do UML in most subjects
What are you telling me user

How would you show a fellow coder your object relationships?

I don't use OOP. It's an inherently flawed paradigm that encourages shared, mutable state.

Nobody uses UML shit in the real world, user.
It's too clunky to be useful and any non-trivial program layout is unreadable.

You share source code, because your peers will know how to read code as well, dumbass.

I almost told you that was nonsense, but upon closer look that makes alot more sense. However, why is there no operator for a straight across exponentiation?

t. jobless loser

It's not used extensively, but a tool for checking or quickly drawing is useful. Most jobs I've worked in don't use UML practices to their full, but know the value of a well-laid out quick diagram

t. code monkey

But if I get given source code with 10+ objects I get lost
As in I'm reading ObjectA, then I see it uses ObjectB, then C and I've completely forgotten about A
Having a diagram to show relationships can speed up the process of it all?

I understand that UML is fucking annoying to do but it's useful in some scenarios surely

t. Alberto Barbosa

good lad

Most of Java's operators where stolen from C, which didn't have a exponent operator because exponentiation couldn't be done on hardware in the 70s when C was made. It was implemented in software for the most part so it was just a function.

You sound like a moron tbqh senpai.

is there even an exponentation opcode on any modern architectures?
it seems awfully specific, considering it's just repeated multiplication and squaring.

That makes sense, thank you user. I'll do more research before asking my questions. Thank all of you Sup Forumsentleman.
>tits for time.

>it seems awfully specific
So many opcodes are awfully specific even at an opcode level

can you rev progider

>swift will have Higher Kinded Types before F#/C# and Rust
ogre

what should i do for my summer project

There is no strait power opcode, but this is a thing:
stackoverflow.com/questions/4638473/how-to-powreal-real-in-x86

T-that's good for swift, i guess

Everyone already knows swift is a god-tier language, it's flaw is that it's used for apple hardware, even if you use Linux (I believe you can use it in Linux)

I have this function
void enter_breakpoint(unsigned long line_num) {

char buf[60];

strcpy(buf, "Entered breakpoint @ line #");
//strcat(buf, line_num);
strcat(buf, ". Press b to continue...");

send_debug_string(buf);
}


The call to this function is: enter_breakpoint(__LINE__);

I need to use these formats because they are what is provided.

void send_debug_string(char* string);

Only accepts char array. My attempts to convert this to a single char array has failed me. The above function basically takes in a string/char array and sends it to what ever serial is connected, it works and should be irrelevant.


//snprintf(buf, sizeof buf, "%s%lu%s", str1, str2, str3); - wont print to putty

//char vOut [11];
//_ultoa_s(line_num,vOut,sizeof(vOut),10);

//ultoa(line_num)

just a few different attempts


Yes I am a retard at C, and it's homework, this just isn't my usual thing.

Try reducing your problem and use snprintf to convert the ul to a char* and do string operations as in your current function. Then play around with cleaning it up if you so please

Ah, the dangers of programming in assembly. Do I bother debugging this? Or should I spend the night doing something less autistic?

Ah thank you, seems I was almost there.

code?

Here
Had to make a few quick changes to get it to assemble. Namely, .L2 needs a colon after it, and the B LR and BEQ LR need to become BX and BXEQ respectively, or else the linker will look for a symbol with that name...

I made a C version of what I knew it was supposed to look like, and it produced a correct result. That is, this works:

int multiply(int a, int b)
{
if (!a || !b) return 0;
if (b < 0) { a = -a; b = -b; }
int c = 0;
while (b > 1) {
if (b % 2) c += a;
a = 1;
}
return a + c;
}

But I want to beat the compiler in producing optimal code, for funzies. A bit difficult though.

>But I want to beat the compiler in producing optimal code, for funzies. A bit difficult though.

This is literally impossible.
Good luck unrolling all your loops manually, faggot.

>I want to beat the compiler in producing optimal code [to multiply 2 integers]
Not gonna happen

There is one loop, and it is impossible to unroll for better optimization. But strictly speaking, I could reduce the code size by an instruction or two.

So, lately I finished my first actual program that was meant to be used (albeit for fun). I programmed it on OS X, for OS X. I used C and the SDL2 framework. It runs just fine on my system, but when I tried to give the binary to a friend of mine, it didn't work (he's obv. also running OS X).

So, my question is: How can I include the parts of the framework I need into the binary to be independent of it? Programming is pretty boring when your programs only work on your own system.

I looked at the code, and for a sec I thought I forgot what I did know about Assembly, since I only used it briefly, but I realized you're using a different type of Assembly, lol.

I only knew a little bit of basic MIPS x64 for a Comp Architecture class.
I've never seen those ARM commands before at all.

I wouldn't be able to help, then, sorry. =/

It probably has something to do with me not correctly understanding what flags certain instructions are modifying. The algorithm is right, the implementation is wrong. It's not worth expending too much time on though, as shift and add multiplication has no real world practical use... except maybe in multiplying arbitrary precision numbers - I don't know what they use for multiplying bignums.

>be me
>start project in nodejs
>have no clue about javascript
>do shit just like dog
>now after over a year project gets kind of working
>realize some flaws
>now that I know some kind of javascript realize how shitty it is programmed
fuck me

Look into static linking the binary and the library. The program you gave to your friend is probably looking for libsdl2 on the system and it can't find it.

I'm debating whether I should make my project in NodeJS or Django

What do you think senpai

not him, but node.js
asynchronous is good once you get used to it
npm has a huge community, which benefits you

Golang

How do people perform math on numbers of arbitrary size?
Do they store every digit separately in a string?

yeah I was thinking node, I have experience with async

now to decide what to program. I was gonna try a reddit clone since that seems to present an opportunity to learn about a lot of different topics

That would be one way to do it, but it would be very inefficient. An 1024 bit integer might be implemented as an array of 32 32-bit integers (or 16 64-bit integers), and when adding is necessary, an add with carry instruction (or similar assembly mnemonic). Alternatively, a C programmer could check for overflow on addition and consider that a carry if necessary.

this

you need to bundle the libraries or static link it

since this is OS X, your libraries were in the library folder.

OS X also has a way to bundle apps, look at that


is this a game?

Thanks, I'll look into that. I was trying to google it, but just found shit. "Static linking" was the magic word I was looking for.

And no, it's not a game.

>posting the homosexual anime image

Kys.

>posting cyka blyat

What monospace terminal font do you use, /dpt/-chan?~

If I wanted to write a function that can be called in multiple types how would I go about doing that in C.
Say I want to write a simple implementation of vectors (c++) in C, since vector can be of int, double, float etc how would I implement this in C.?

Is this really the best way to update a json node in python:
def set_cog(cog, value):
with open('data/red/cogs.json', "r") as f:
data = json.load(f)
data[cog] = value
with open('data/red/cogs.json', "w") as f:
f.write(json.dumps(data))


Because this just seems inefficient

macros

If you dont care about size you can just use void*. If you need the size you will need to write macros to either a) generate the required functions for the type, or b) use the macro as the function, but this would result in code duplication as you are effectively inlineing everything

Thanks guys

tewi-font

My screen resolution is pretty bad (1280x800), but even I wouldn't use pixel fonts.
Do you have your monitor 2 inches from your face or something?

He probably wont upgrade from his 640x480 CRT because of nonfree microcode.

In practice it's not so bad. It doesn't look too flattering because of the coloring, I think.

Naw, I use an LED monitor.

how much nose grease is on your monitor?

About the same amount as is on your mother's ass.

I use bitmap fonts on a 1080p

sounds like you need glasses or better color/font rendering desu