/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

gist.github.com/anonymous/56473f34704f3e9725076fd2215cdf94
askubuntu.com/questions/331626/how-to-add-keyboard-shortcuts
twitter.com/SFWRedditGifs

working on getting a fucking operating system to boot

How the heck do you acces the Internet before booting up? Haha!

Starting over with Haskell. Can't wait to program as a real trap!

I'm making my new video game using JavaScript

This trap has a republican in their pants?

Always fun. Stuck on anything?

i'm making a porn book slicer (gets table of contents and creates appropriate artist folder according to pages)

Acceptable. A browser game, I take it?

can one do machine learning with c?

>a-user, i thought you were gonna teach me how to program, why are you making me wear girls clothes??
>w-wait, what are you doing!!

Yes, but it doesn't exactly have the best library support with regards to machine learning stuff. It may be smarter to use a language like Python or R, and use native extensions to handle anything computationally expensive. Although I think there may be a few C++ libraries if you're willing to use it over C.

i'm on a puppy linux live cd booted from an old ipod (really)

i hate everything to do with partitions, booting, bios, all of it, user... it's maddening how difficult it is when it has no reason to be.

basically i have to repair the mbr but i never owned the windows cd (if there ever was one) for this computer so it's more or less a gigantic pain in the ass

Yeah I had a similar experience with Arch recently. I had everything sorted out EXCEPT for the bootloader. God, I fucking hate UEFI. I ended up just installing Fedora since I had never tried it out. Liking it so far though.

>muh data structures
>muh algorithms

Oh, you're just repairing a bootsector, not programming a bootloader. Just pirate Windows and run like... one or two commands. I can't remember them off the top of my head, but you should be able to find them easily on Google. You don't need a license key to repair a MBR, just a regular Windows disk.

hey Sup Forums im stuck at typecasting in c.all i can find out on youtube are some pakis with a broken ass english explaining it.

What the hell is going on here, I have been coding my first programs with knowledge from youtube and forums, but I can't find a explanation for this...

double x= 435046000000000000;
double y= 0.4374;
double r= x + y;


r = 435046000000000000.0000

Nope, desktop

This is why you should use PHP

i wouldn't mind programming a bootloader one day actually, haven't done much with anything more bare metal than C though

>with C
Oh you won't be using C much at the bootsector level. That's one level up.

Javascript is an odd choice for desktop applications when there are many better options. At least it's a step up from PHP though.

i want to write a TUI script for fun. how's bash for someone with barely any experience?

if i ever wanted to move my project to a gui or make it work in other shells, i'd have to completely re-write it, right? i don't want to maintain different versions in different languages because it just seems like a pain. but i really do want a TUI

precision

wait i'm retarded. what about python? i think rust has a tui library too

should i go with python so i can make a gui too?

TUI == NCURSES

Learn how doubles are represented in binary format

435046000000000000 would require 59 bits to represent as an unsigned integer. A double precision floating point has 52 bits for the mantissa, 11 bits for the exponent, and 1 bit as the sign bit. It can only reasonably represent integers that could be stored within that 52 bit mantissa, and anything larger involves loss of accuracy.

Thank you

So if i added

x = .111112

to

y = .111111

what would I get? 0?

Same. I've pirated the last couple of versions but I think I'm going to just bite the bullet and buy 11 under a student license. Their new neural network stuff looks really nice and I'd like to use it on my Linux machine which is tough to find cracked copies for online.

...

Floating point variables (of which doubles are a specific type) store decimal numbers to limited accuracy. The number 435046000000000000.4374 has 22 significant digits, which is more than a double-precision floating point number can store. Which means that the number gets rounded, as you have found.

Does /dpt/ like Go?

rubyist@Overmind:~/scratch$ irb
irb(main):001:0> x = 0.111112
=> 0.111112
irb(main):002:0> y = 0.111111
=> 0.111111
irb(main):003:0> x + y
=> 0.222223

Not even a rounding error.

Not really. Some do, but most rather dislike it.

>c
lmao people still use this ancient meme language

Working on further optimizing my mbox parser written in Rust.

Right now it can parse a 280MB file with ~51k emails in 0.8 seconds, not fast enough.

Is someone using Go for mobile? Do you happen to know if whatever external library I import, will it compile/install just fine to an android device?

Why's that?
I've started a project at work using it and its easy concurrency usage. It's compiled and statically typed like C but has lots of the convenience of scripting languages, very pleasant to work with. Just trying to find reasons why I shouldn't be totally all-in for this.

The type system is shit, interface {} everywhere, and depending what you're using it for there are better programming languages for whatever you're doing.

Also channels were implemented in a retarded way last time I checked.

Writing string-based arithmetic functions in R. There's a package that already does this, but I'm using these arithmetic functions for challenges where I can't use foreign packages. Plus I like making it myself and it's something for GitHub if nothing else.

so, is my fib function O(3n)?
#include

void fib(int n) {
long double a=0, b=1, temp;
printf("0 1 ");
for (; n>0; n--) {
temp = a+b;
printf("%.0LF ", temp);
a = b; b=temp;
}
}

int main (char argc, char **argv) {
fib( atoi(argv[1]) );
putchar('\n');
return 0;
}

Compiles to native code, but uses a fucking garbage collector. Has no real purpose, given that there are better languages if concurrency is the primary objective.

It's O(n). you remove constant factors when calculating algorithmic complexity.

>Long double
Just use intmax_t or some shit.

my long double is bigger than intmax

>my long double is bigger than intmax
And way less efficient.
Anyway, that is not guaranteed. It depends on the system.

>Oh wait, I need this set up for UEFI.

how do i get a c++ job

>flower
>not a rosebud

how do I find out how my system stores doubles & floats?

Jesus Christ. The only threads on 4chins that I used to consider worth while have gone completely to shit. Thanks.

What's a good alternative to try out for concurrency?

Is there a "go to" guide for MSDOS programming?

Someone tell me what Reflection is in C# and how it can be used in productive (non-toy) programs.

If you want a language centered around concurrency, Erlang and Chapel are designed with concurrency first. If you want something more likely to get you a job, Clojure is relatively popular. Plus, you'll get to say you program in a Lisp for a living. If you still want to use a systems language, Rust will perform just as fast as Go, without the use of a deterministic garbage collector.

Is there a better way to do this in C#?
class ExampleClass
{
float aggressiveness = 1;
float generosity = 2;
float cuteness = 3;
float cheerfulness = 0;

public void levelUp()
{
aggressiveness += 1;
generosity += 1;
cuteness += 1;
cheerfulness += 1;
}

public void printStats()
{
System.Console.WriteLine("Aggressiveness: " + aggressiveness);
System.Console.WriteLine("Generosity: " + generosity);
System.Console.WriteLine("Cuteness: " + cuteness);
System.Console.WriteLine("Cheerfulness: " + cheerfulness);
}

}


It's OK when I only have 4 stats, but what if I have 20? 30? They're all floats. In C, I'd use a union with an array of however many floats I have, and then a separate array for the strings and just iterate through and print, but unions seem like a huge pain in the ass in C#.

It's O(n), and also ϴ(n).

use a map / dictionary

I'm writing a website scraper in Go. I now have about 8TB so far and it's going to start getting expensive to keep it all in one place.

>my long double
more like atomic_short

Don't use floats. Use integers where ever possible. Floats are tricky and usually don't behave like you want them to.

Cast them to integers and see what the bits look like. Most floats are ieee.

>mfw I realize enums are just syntactic sugar for dictionaries

I want to write a program that calculates the braid group B_N upon N particles (or rather, the subgroup of the braid group that's generated by particle permutations) on a manifold of choice. This can be done by writing out the group relations that comes from considering particle exchanges on the manifold, and this is the process that I want to automate. Is there an "no-go" algorithm that determines whether something can "pass through" something else?

i don't get this joke
its 128 bits
but I assume some are reserved for the mantissa

that's false tho

what are the implications of array names having the address of the first element in the array

is it possible to do array_name += 1
meaning array_name lost one element
what happens to the previous element
can do array_name -= 1, after I've done the above?

>what is reflection
Runtime information about types, assemblies, modules, etc...

>what can I use it for
Dynamic loading of classes. It is particularly useful for implementing dynamic languages on the .NET runtime. So if you were developing a Lisp on the .NET runtime, you would obviously want to be able to load new classes in the REPL. You would likely then be using some methods on the System.Reflection.Assembly class to do this.

Spoiler : I'm a bio guy, not a programmer.
The only thing I lack in GNU/Linux in respect to Windows is hotkey registering like AutoHotKey or similar alternatives. Sikuli for Java works but full python integration would be far better for my purposes.
So wrote this hack. It somehow works, but has serious flaws. Don't know if/how those are solvable.
gist.github.com/anonymous/56473f34704f3e9725076fd2215cdf94

>"+ cuteness"
even a fucking SQL is more strict when it comes to this
this fampai

No, arrays cannot be changed like that, which is how they are slightly different than pointers (at least at compile time).

long doubles are 80 bits on Intel CPUs

i have intel but 4 cores, how come my long dubs are 128

Are you using C#? If so it is emulating it in software. (maybe)

>Hotkeys
askubuntu.com/questions/331626/how-to-add-keyboard-shortcuts

C# does not have a long double type. It has float, double, and decimal. Only decimal is necessarily emulated in software. The other two will use hardware instructions if they are available.

Is there any point in using XML when JSON exist?

XML looks nicer

(You)

What is the point of this post?

That's subjective.
I think json is more readable because less bloat tags.

XML is much cleaner

Like i said. It's subjective. I think the opposite is true.

Your post was clearly just fishing for (You)s, so I gave you that without taking your lousy bait.

Whilst I find json a lot more readable.. I have small config files using json that quickly go to shit because I can't comment what any variables mean.

There are much better formats you could use for configs instead of JSON or XML.

pls respond

Sublime text settings files use comments.
But i guess it's an unofficial extension.

Look for a parser that supports it, or write your own.

What kind of game?

JSON has too many annoying things about it which makes it bad for config files.
Something like TOML is a lot more readable and workable for the user.

>Make a portfolio containing C++ projects
>Apply for jobs.

For C++ (without a degree) the most chance of getting hired is in the vidya gaem industry.

>the most chance of getting hired is in the vidya gaem industry.
I can confirm on this. With the right contacts/money to go to cons, it is extremely easy to get a low level game programmer job. (That said, I personally haven't had a "real" job in the game industry yet, but I have the right contacts)

>mfw you don't understand what enums are actually for

Not wm independent and can't bind to arbitrary behavior, eg : I may want alt+w to call a function that :
1. automates this program with predefined keyboard and mouse actions (pynput or pyautogui
2. copies some text
3. scrapes a site basing on that text
4. writes the results in a temporary file
5. opens it in a gvim window
6. etc
All of this is trivial with python.

Go is a good tool for specific jobs. The emulator and debugger backend for Microcorruption.com is all written in Golang, for instance, plus lot's of security outfits lately have written pretty complicated web fuzzers and SAT solvers using Golang because it's a non complex language, perfect for building automatic software verification toolsets, concurrent memory safe message passing "backends" for cell apps, a custom web server, ect.

Yes there is Erlang for this as well but if you're not building RabbitMQ and just want to dick around with a snazzy custom SAT solver to blow out a control flow graph in a C program then you have Go.

Carnegie Mellon uses it in their distributed computing class now too

I dereferenced a pointer and now my cp isn't working, what do?

Further, the only reason Go exists, according to Pike's blog, was how forbidding and painful Google's C++ build and development process was. So essentially they set out to make a language the complete opposite of C++.

compile times are long → use the Plan 9 toolchain to speed it up in Go

memory management is difficult and unsafe at massive scale, prone to bugs and complexity → garbage collection

templates are a mess of complexity → no generics

exceptions interact badly with RAII → no traditional exceptions

header files get convoluted at scale across multiple servers doing parallel builds → use packages and forbid circular dependencies

OOP → barely implement OOP

You're going to need to be more specific than that.

it was UNINITIALIZED, now my tar.gz isn't working

C++ question time
vector vec;
for(int i=0;i

so today python fucked my over by being helpful, funnily enough

I thought accessing -1 indices on an array would throw an error, right?
NOPE
just gives you the last element in the array
bizarre

No. Vector makes deep copies iirc.

But you're better off passing a reference as parameter instead of returning a vector.

No, well written classes in c++ protect idiots like yourself from doing stupid shit like that and make sure it deallocates. If that wasn't vector and your own class then yes.

That's not bizarre, it's explicitly defined to do just that, for strings and lists.