/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

en.wikipedia.org/wiki/Coq
pastebin.com/X40e6TbS
play.golang.org/p/ZJjo0x7qUI
play.golang.org/p/IoP1epycaR
play.golang.org/p/mjD5u3JNIU
aviation-edge.com/
play.golang.org/p/fdg2qRRCCt
twitter.com/SFWRedditImages

Heh heh. Look at the name of this programming language:
en.wikipedia.org/wiki/Coq

>What are you working on, Sup Forums?

Exploring the deepest, darkest corners of Racket. advent of Code 2017.

the power of coq at my fingertips! yatta!

(OP)
I'm sick with a runny nose and a soar throat and have this assignment due tomorrow. Anyone wanna do it for me in exchange for an invite to a private tracker? (Emp/AB)

Code:
pastebin.com/X40e6TbS


The work is in pic related. I'm gonna go lay down. I'll check back in 50 minutes. If no one's done it by then, I'll just do it myself.

I posted the problem in the w last thread, the filename is war.png

does endianness affect program loading times? the compiler generates a little-endian binary and the OS loads everything in little-endian? even if the cpu can switch endianness the OS runs it in little-endian all the time?

nice reddit thread

Learning Rust :^)

Font?

dumb frogposter

Envy Code R VS Regular

help me /dpt/ you're my only hope.

I haven't the slightest clue where to start with this.
How I managed to survive all the way to the end of this semester I have no earthly idea.

well, start by
1.having the user enter two sets of numbers
2. asking them whether they are adding, subtracting, multiplying, or dividing
3. printing the result of applying that operation to those sets of numbers
4. improving this basic program with error validation.
then, repeat steps 1-4 in the other language.

Anyone wanna do for me before I do it myself?

this is actually really easy

if you give me something in return i'll do it for you. in python, i dont know raptor.

wtf is raptor

No, you stupid faggot. Just add the members and functions to your already existent class and move the fuck on. Lazy bastard.

Hello, I'm very new to programming and can't figure out what's wrong with this simple program I have made. It runs but doesn't do what I want.

package main

import (
"fmt"
"strings"
"time"
"math/rand"
)

var s []Card
var human Player
var pc Player

type Player struct {
hand []Card
name string
score int
}

type Card struct {
/* card index */
cdx int
/* card val 1-11 */
cvl int
/* card suit 0-4 */
cst int
/* card glyph letter and suit */
cgl string
}


func main() {
deal(human.hand)
deal(pc.hand)
deal(human.hand)
deal(pc.hand)
fmt.Println(human.hand,pc.hand)
fmt.Println(s)
}

func makeCard(x int) (int, int, int, string) {
val := x%13
suit := x/13
return x,val,suit,glyph(val,suit)
}

func glyph(x,y int) string {
cards := strings.Split("A 2 3 4 5 6 7 8 9 10 J Q K", " ")
suits := strings.Split(" "," ")
ret := cards[x] + suits[y]
return ret
}

func dupe(x int, y []Card) bool {
for _, index := range y {
if x == index.cdx {
return true
}
}
return false
}


func deal(x []Card) {
r := rand.New(rand.NewSource(time.Now().Unix()))
instx,instvl,instst,instgl := makeCard(r.Intn(52))
newCard := Card{instx,instvl,instst,instgl}
if dupe(newCard.cdx, s) == false {
s = append(s, newCard)
x = append(x, newCard)
} else {
deal(x)
}
}

The problem is that I can't seem to append to the persistent Player.hand. This is a cleaned up version, but I did try retooling it to work in pointer receivers / a method but clearly don't understand them well enough to get it to function properly.

Yes I am a brainlet faggot, thanks for your help!

there is no need to be so mean, user. im really not feeling well

You can't append to an array you initialized.

*never initialized

How do I initialize it in this context, declare it like

pc.hand = []Card{}


in main()? I'm not really sure. That in particular doesn't work.

not him but that should be okay
play.golang.org/p/ZJjo0x7qUI

i think you should cut this down a bit. the error must be simple but there's all this stuff

>final project of the semester
>babies first calculator
jesus fucking christ, i hope they're paying you to attend that school - only way it's not a rip-off.

gonna get a job offer from my cousin in some weeks to design and implement a small database
im still a student and thought i would learn db in school and now that im taking it noticed the professor is a massive retard and im not learning jack shit
what are some good database books to read or tutorials or anything you can recommend?

I can't append to a slice in a struct and have it be persistent. I tried initializing it, I tried reworking it to use pointer/value receiver and it won't work the way I did it.

MySQL? Just read the documentation - you should be decent in a couple months, basically functional withing a couple weeks. Or install workbench and spend a weekend watching youtube tutorials.

oh, i understand what the error is. you need to rework some of this: it's like if you had a parameter x int and then later in the method assigned x = 2. that isn't visible from the outside

var foo aaa

type bbb struct {
first int
second int
}

type aaa struct {
third []bbb
fourth int
fifth byte
}

how to append to aaa.third in a function

Here you go:
num_1 = input('Enter the first number: ')
num_2 = input('Enter the second number: ')
operation = raw_input('What is your operation? (add, sub, mult, div): ')
result = 0
if operation == 'add':
result = num_1 + num_2
elif operation == 'sub':
result = num_1 - num_2
elif operation == 'mult':
result = num_1 * num_2
elif operation == 'div':
result = num_1 / num_2
print 'Your result is: {}'.format(result)

Error handling and other cleanups are left as an exercise to the reader

>if the user enteres 0/9, it needs to tell them this isn't allowed as you can't divide by 0.
0/9 = 0

that should be a final assignment? what the fuck thats just too easy

pass the function a reference to the instance of aaa

>raptor
What the fuck is that?

it didn't work when I had X Struct as the parameter and tried to assign struct.slice inside, that's the same issue, right?

play.golang.org/p/IoP1epycaR

ill work with this, thanks

you need a pointer. let me whip up an example

If I could blow you through the internet I would do it right now.
Thank you user. Thank you for helping this massive retard pass his programming class

>final is tomorrow
>have a cold and copy of xenoblade 2 just came in
>grade is a pure 98.5
>i could skip the final and still get a b
tempting

He's getting scammed. The monkey boot-camp I attended after HS had us make a copy of windows explorer and a basic rendering engine at the end of the first semester. The calculator was homework from week 2. What's the point of going to college or a boot-camp if any self-learner can outpace you by watching youtube vids?

ah well
play.golang.org/p/mjD5u3JNIU

You know that's wrong, right?

also thanks

public double getSize(File target) {
try {
if (target.isFile()) {
return target.length();
} else {
double folSize = 0;
for (File f: target.listFiles()) {
if (f.isFile()) {
folSize += f.length();
} else {
folSize += this.getSize(f);
}
}
return folSize;
}
} catch (NullPointerException e) {
System.out.println("COULD NOT CALCULATE SIZE.");
}
return 0;
}
homework, is this halfway presentable?

the } below return folSize looks too far to the right

how complicated or abstract should a project be before one ought to try/catch, //comment shit, etc...

simple shit should just work, right?

obviously, if you're writing:
hello world = no
fizzbuzz = nope
MS Word = hell yes

I'm thinking of implementing an AR android app. The app will receive real world coordinates of some objects and draw them on top of the camera view. So you will be able to see those objects through your phone's camera. I need a service that will provide me with coordinates of some objects. Like this site aviation-edge.com/ but they allow only 100 requests per month for free.

>I'm sick with a runny nose and a soar throat and have this assignment due tomorrow. Anyone wanna do it for me in exchange for an invite to a private tracker? (Emp/AB)
Fuck off, cunt. I didn't go through 5 years of university, doing every assignment, every exam, every homework all by myself, studying my ass off, so I can help some cunt cheat his way through his courses and steal my jobs because he has "a runny nose and a soar throat".
How about this, cunt. If you're ACTUALLY that sick that you can't do it, go to your fucking doctor and get a doctor's note and show it to your professor. Jesus

See

I cleaned it up a bit

play.golang.org/p/fdg2qRRCCt

I'm not seeing where I'm messing up

using try catch for a null pointer exception is horrible practice, check for nulls where necessary only...

You're funny
I did it myself, don't reply to me anymore.

pointers the whole way down; in particular, for deal. if you want the function to change something you have to tell the function how to find it

Just rip the data from flightradar and store at your own server. Not sure if they'd tell you to fuck off if they saw constant queries from your site, though.

Something about this read like a salty 15 year old girl.

otherwise my ide starts bitching all the way up the chain about a missing null pointer exception. teacher specifically said that he'll fail any homework that doesn't have all possible exceptions in try blocks.

You're like so like funny
Don't like reply like to like me like anymore. Gawd like whatever I'm so totally over it.

Why don't you just check in places where a null could occur whether its null and e.g. skip that file instead so no null pointer exception can occur?
Otherwise by applying the catch everything logic, wouldn't you also need to catch stuff like out of memory which could in theory occur everywhere but won't unless something is very fucked? I've never really seen catching nullpointer exceptions in real life code unless in very rare occasions where there is some kind of legacy hack or super dirty workaround in place

i fixed it by passing it initially as a pointer, that did it, cheers

public String getInput() {
Scanner scanner = new Scanner(System.in);
String scannerString = scanner.nextLine();
if (scannerString.equalsIgnoreCase("QUIT")) {
System.exit(0);
}
return scannerString;
}
how terrible an idea is it to calls this every time i require an user input?

>public String getInput() {
> Scanner scanner = new Scanner(System.in);
> String scannerString = scanner.nextLine();
> if (scannerString.equalsIgnoreCase("QUIT")) {
> System.exit(0);
> }
> return scannerString;
> }
>how terrible an idea is it to calls this every time i require an user input?
Why not declare it regularly in the code??

I'm a complete noob but as far as I understand the null pointer could occur if between checking if the file exits (which happens in the method that calls this one) and this method trying to call .lenght() or .listFiles() the file got erased. Ergo, by the rules it has to go in a try block.

Trying to virtualize Windows 95 with games, so I can play old games on Windows 10

bump for insight

are you sure about that? I'd expect some kind of IO Exception being thrown in that case, not a null pointer exception. I don't work with c# but i guess the API will tell you.

yeah, the first line could go outside - just thought it's clearer this way. is there any real difference in terms of speed or memory usage?

you're right, deleted all try-catches from the programm, plenty of IOE but no null pointer. must have gotten something confused. great, so I'm still completely unclear on what constitutes an NPE.

to say it simple a NPE occurs when you try to invoke a method on an object which hasn't been constructed beforehand and is null, like, to show it to you using your function, imagine calling it like that:

File someFile = null;
getSize(someFile);

Your function would then throw a NPE when it first tries to access the given file object, which is still null as it has never been initialized with some value.

Therefore, you could probably add a check up front like

if (target == null) {
return 0;
}
or however you want to handle that case

by the way as you said you remvoed all try catches, since an IOException can basically always happen when working on files wouldn't it be wise to leave a catch for ioexceptions in place or handle it in some more fine-grained way like just using 0 file size if a file operation throws it.

thanks a lot man. i have a check like that, the NPE probably showed up before I put that in and I got it confused. honestly, try blocks got me scared so I tend to stick them everywhere - turns out roughly a quarter of all 20 of them were completely unnecessary.

What's the point of policy-based design? Isn't that what inheritance gives us?

I want to make a small program for learning foreign languages, that is really simple.
Text, then some sort of text-input, button, then next text (even without checking previous... However, maybe it worth implimenting).

So, what is better to make:
- console app (Pros: easy to make. neat. Cons: not user-friendly, it is executable)
- Dozens of HTML pages linked. (Pros: good looking, user-friendly. Cons: difficult to make)
- Single HTML page with Javascript (Pros: user-friendly. Cons: well... none)
- Make a QT app (Pros: user-friendly. Cons: difficult to make, is executable)

(Sorry if I am asking in wrong thread)

if (temp == 0)
return -2;
else
return 0;
if (temp == 0) {
return -2;
}
else {
return 0;
}
if (temp == 0) { return -2; }
else { return 0; }
I never use the first style ever, usually use the second style, and most often use the third style with if else chains that have a line length of

if (temp == 0) {
return -2;
} else {
return 0;
}

I find this even worse than no brackets at all. The idea of purposefully misaligning the else if and else with not only the if but also the closing bracket is blasphemy.
You should be ashamed of yourself.

It's compact while also less error prone.

if (temp == 0) return -2
return 0;


or

if (temp == 0) {
return -2;
} else {
return 0;
}


or if no one's going to read my code but me

return temp == 0 ? -2 : 0;

return !temp ? -2 : 0;

Which IDE do y'all use for Python, PyDev? IDLE?

Less compact than third style.
Less error prone? Entirely unsubstantiated opinion.

First and last won't work with else if chains, right? It's always nice to only use multiple ifs instead of an if else chain when you can though.

It allows easy editing of the insides of the blocks without a possibility for mistakes.

>without a possibility for mistakes.
Nope. You're delusional.

I'm currently 2 semesters away from graduating, and I'm just finishing up my co-op term.

Why can't I start projects on my own? Why do I have to be forced to program? I'd rather do so many other things. I think I'm just doing this so I have a stable career where I make money.


What the fuck do I do?

If you want to expand the blocks in
if (temp == 0) { return -2; }
else { return 0; }
with extra lines, you have to insert 3 newlines. My style needs just one. Unless you are fine with keeping multiple semicolon-separated lines, that is.

I have a solution to a problem but I'm not sure if it's neat enough.
The problem is to randomly generate a number from 0 to 6 (rand7) using only a defined function that can only generate from 0 to 4 (call rand5). Rand5 and rand7 are uniformly distributed.
Here is my solution:
int rand5() {
return rand() % 5;
}

int rand7() {
while (true) {
int first = rand5();
int second = rand5();
int num = first * 5 + second; // Convert to base 10 because doing math in base 5 sucks
if (num

i'm reposting from in a program, i have a function with the sole purpose of returning an instance of a class. throughout the rest of the program, instances of this class are needed in several other functions.

would it be unwise to repeatedly call aforementioned function every time an instance of the class was needed? or should i attempt to pass an instance of the class as a parameter every time one is needed? i realize this question is probably not explained well and i apologize.

It's not a programming language. I learned how to use it in 600 level advanced logic course while in school for my master's. The professor was a petite Italian woman who wore brightly colored pantsuits. The way she'd say "coq" was endearing and erotic.

>Unless you are fine with keeping multiple semicolon-separated lines, that is.
I still find this less blasphemous than misaligning your 'else if' and 'else' statements with their closing brackets and the 'if' statement.
I don't think I'd use that style in the first place if I thought it might need to expand the block in the future.

So you don't even use a consistent style? Honestly, kill your self.

Not them. I try to, but I'd never finish my software if I worried too much about style.

There is this thing called automatic formatting. Any text editor should have a plugin.

Coq is both the name of the software (the implementation of CoC) and the language. You can export Coq proof to actual programs too.

I've never found one that takes care of every edge case in a way I'm comfortable with

Learning erlang atm (havent started OTP yet)
Its very intetesting, unlike any other language, not sure what it can be used for though

Clang-format.

Watch as he insists that his formatting style has very specific corner cases (?) you can't specify with clang-format.

I made a thingy which downloads threads, but in Rust.

I do not write code because I am lazy and I do not have ideas.