/dpt/ - Daily Programming Thread

Previously

Attached: 1529861734188.png (1200x1198, 1.03M)

Other urls found in this thread:

play.google.com/store/apps/details?id=com.aide.ui&hl=en
youtube.com/watch?v=LOg6If-25l0
en.wikipedia.org/wiki/Racetrack_(game))
twitter.com/SFWRedditImages

string scanning is kinda ugly i probably should try to tokeniz that instead

Attached: uhoh.png (1920x1080, 188K)

char* str = line.c_str();
char* str2[1+strlen(str)];
char* head = str;
strcpy(str2, str);
strtok(str, "-:");
map.start = strtol(str, NULL, 16); str += 1+strlen(str);
map.end = strtol(str, NULL, 16); str += 1+strlen(str);
memcpy(map.permissions, str, 3);
str += 4;
map.offset = strtol(str, NULL, 16); str += 1+strlen(str);
map.dev_minor = strtol(str, NULL, 16); str += 1+strlen(str);
map.dev_major = strtol(str, NULL, 16); str += 1+strlen(str);
str += 1+strlen(str);
strcpy(map.path, str2+(str-head));

Horrible. sscanf clearly expresses your intent and has a neat and quick template. You might want to consider the SCNx32 macros and friends, but probably not.

Which one makes your eyes bleed more, Boost or Rust?

C, to be very honest. Especially when it (which is always) has tons of macro abuse, bit shift hacks and void * casting

newfriend here, teaching myself c++ to get ready for my intro course next semester. What are some recommended practice questions? project euler is a little mathematically intimidating

Attached: 1530548699257.png (534x560, 308K)

True, true, I guess I'll worry about making it prettier later. For now it can find a variable in its own memory, time to write some more convenience functions.

Attached: file.png (1920x1080, 146K)

Idris will be the industrial-strength functional programming language of the future.

True, true, I guess I'll worry about making it prettier later. For now it can find a variable in its own memory, time to write some more convenience functions.

Attached: Untitled.png (1920x1080, 114K)

Why are you parroting me ;_;

Why are you parroting me ;_;

>>>/reddit/

Intro to C++ was pretty simple at my university. You'll do alright user, just go to class and work hard. Have you done any programming before?

shit. well I guess I don't need to worry about scribbling out my name anymore

That's just one of my computers, the other ones are more Jow Forums worthy, pic related

ty user
A sentient outfit would be fun, but i just want to be happy and at peace with myself, and somehow I've latched onto the idea that I can escape somehow through anime and shitposting on Jow Forums

Attached: Screenshot_20180718_224733.png (1440x900, 678K)

Why not just use ifstream's extraction operator like it's meant to be used?

Attached: 1301537945739.jpg (404x402, 28K)

Because I'd have to keep shuffling stream modifiers and ignoring stuff, that'd be ugly as fuck. In general I avoid most of iostream stuff in C++ because it's horrendous.

couple of years back I made a barely functioning tic tac toe with SDL, but i really didn't understand most of what I was copy pasting back then.


these days, the thing i've programmed that i'm most proud of is the 3rd project euler problem, which was finding the largest prime factor of the 600851475143

hot opinion: universities should teach more about build tools. I wouldn't even know what a makefile is if I hadn't taught myself.

I know very little about project euler, never done it myself. if you can do what you described, then you'll do fine.

universities prepare you for research. it's up to you to learn things like build tools imo

>universities prepare you for research. it's up to you to learn things like build tools imo
Isn't understanding build tools pretty essential if you're going to do research?

We had a 2 hour git lecture as part of a programming course, which I think is sensible. I already knew git, but it feels natural that understanding your tools should be part of it.

Thing is though, it's not that big of a deal if they add. You could make arguments either way, but in the end it's like 1 lecture to teach people about build tools, it's not that much. Or even better, just give homework with build tool instructions as part of every program. Just sending out a pdf with instructions (or even a link to some site with instructions) at the start of the course should be enough.

>program
I meant course.

i have an ArrayList of elements.
should i call it "eles" or "eleList"

I think there should be a few lectures spent on writing makefiles, maybe CMake, language-integrated package managers (e.g. cabal and pip), etc.

It amazes me how few of my peers know how to actually build a project. You hand them something with more than 2 files and they just look confused.

You should call it elements

arrayListOfElements

There's a special place in hell for people who put types in variable names.
Partly it's errenous information - you can see that is an arraylist by checking the variable info by either hovering over it or, as might be more appropriate, pressing a button.
But maybe most of all there seems to be a very obvious name here - elements. Element is a class, a bunch of element objects is called elements. It's pretty straightforward.

i figure if i come up with a standard of how i express my vars, then i can get he same amount of clarity of less words.

And less words are good.

mszInteger

>i figure if i come up with a standard of how i express my vars, then i can get he same amount of clarity of less words.
In general people should write more descriptive names. Of course don't put something there that doesn't belong, but people have this idea in their heads that they need to save characters. Shorting elements to eles might seem nice but it's going to be like this

Scanner input = new Scanner(eyes);

>input = elements -> this is a list of elements
>input = eles -> this means elements -> this is a list of elements

As you can see, it takes more effort to read eles than elements, and those last characters can be autocompleted if you're typing it a lot so you're not saving typing time, and most of the time you'll be reading the variable anyway.

>>input = elements -> this is a list of elements
>>input = eles -> this means elements -> this is a list of elements
this is how my brain works?
while ur in there, tell me about my childhood trama.

>wake up and deploy
>roll in late as fuck
>shitpost and doze off all day
>go home and write some code
>repeat

anyone else caught in this?

>while ur in there, tell me about my childhood trama.
Your father was in software but when he showed you his work you saw that all his variables had awful names.

>gtk is shit
>qt is bloated
>tk is ancient
>wxwidgets is just a gtk wrapper
>sdl doesn't provide widgets
What the fuck am I supposed to use for a GUI?

write your own

javascript

:^)

Why do people use boost?

Build tools aren't a skill, you just need a quick primer. Copypaste works fine enougn.
.POSIX:
CC = cc -std=c99
CFLAGS = -Wall -Wextra -Ofast -march=native
LDLIBS = -lm

[TARGET]: main.c [ADDITIONAL SOURCE FILES YOU DON'T INCLUDE GO HERE]
$(CC) $(LDFLAGS) $(CFLAGS) -o bin/$@ main.c $(LDLIBS)

clean:
rm -rf bin/

>Copypaste works fine enougn.
yeah, until it doesn't. Then you're fuuuucked

elems?
So your programs. Sed, grep, wget, curl, ping. How does that work? Are they poorly named?

libui
nuklear

inject Chromium Embedded Framework context into your application

both garbage for anything but a few quick debugging tools

These are programs though. Descriptive names are always better than non-descriptive names but I feel like this is a related-but-different-discussion.

>Are they poorly named?
maybe. How different would the learning curve be if it was stream_editor, global_regular_expression_print, web_get, capture_url

Probably not a lot, but when you're looking at hundreds of lines of code that aren't standard things like above. I can easily see that int is as good as integer, but eles is definitely a lot less clear than elements.

nuklear looks interesting

Desktop apps are DEAD senpai.

>posting from a desktop

In Java, can I clear the exception state? For example I have caught an exception in the catch block but I want to try again.
I tried removing --i, but java thinks all other input suffer from the same exception.
public class parti {
public static void main(String[] args)
{
String[] programs = {
"quiz", "mid semester", "applied project", "final exam"
};
int[] weights = {10, 20, 40, 30};
assert programs.length == weights.length : "Test and Weights mismatch";

var input = new Scanner(System.in);
double total = 0, buff_double = 0;
for (var i = 0; i < programs.length; ++i) {
System.out.printf("Enter your score in %s:\t", programs[i]);
try {
buff_double = input.nextDouble();
if (buff_double < 0 || buff_double > 100) {
throw new Exception("Number out of range.");
}
} catch (Exception e) {
System.err.printf("Could not read number: %s\nTry again.\n", e);
--i;
// now I want to clear any exception and try again.
continue;
}
total += buff_double * weights[i];
}
System.out.println(total);
}
}

>Decent quality programs
>Portable
>Lots of boost only requires C++03 allowing older compilers to user features in newer versions(boost::variant vs std::variant)

imagine a Jow Forums application.

Yeah, fuck off phoneshitter. No wonder you don't program.

play.google.com/store/apps/details?id=com.aide.ui&hl=en

nvm figured it out

lol, I can see having productive conversations with you on the dev list

tfw too dumb for multithreaded programming

>grasping on the straw
Don't pretend anyone uses it to actually do anything.

electron, of course

I'm not, I was just joking. I'm not the original guy you were talking to it just seemed like the obvious thing to link.

GUIs will always be bloated, either use QT or gtfo and write a CLI application.
Also QT runs on embedded devices, so is this a real constraint you have, or did the big widget frameworks hurt your feelings?

Uses queue, avoid direct usage threads

>when () isn't considered null in scheme

WHY IS THIS A THING

why are errors messages in android studio completely useless? do the people who maintain that shit live in an alternate universe where useful error messages don't exist? they might as well not have any messages at all.

>Also QT runs on embedded devices
Impressive desu

writing your own widgets from scratch is actually kinda fun

If you are a brainlet just wrap stuff within mutexes

The future is functional. #metoo

The state of modern game developers.
>youtube.com/watch?v=LOg6If-25l0

OO with functional features is favored over functional with OO features.
(near)Pure functional is useless.

Do not shill your channel

Just playing around. Can Jow Forums undo this?
static void Main(string[] args)
{
if (args.Length == 0) return;
string outName = Path.ChangeExtension(args[0], "mascii");
using (var fs = new FileStream(outName, FileMode.Create))
{
foreach (byte c in File.ReadAllBytes(args[0]))
{
if ((c >> 4 ^ 0x3) != 0)
fs.WriteByte(((byte)(c >> 4 | 0x80)));
fs.WriteByte((byte)(c & 0xF | 3

Gib fun Java programming project (that is resume including worthy).

Attached: fuckborders.png (634x566, 30K)

im not just subbed to it

what are you talking about?

i think you're confusing () -- which is the display for null/empty -- and '() -- which is what you have to write in code.

>>gtk is shit
nice meme

Let's say I'm recursively taking the tail off a set. I might have a check for null? somewhere in the function. But in my scheme Null? triggers an error because scheme terminates lists with (), not '()

I'm new to programming but this has thrown a wrench into what I think are elegant functions.

I mean, I really doubt that. Terminating lists with '() (meaning null) is one of the core features of Scheme; you literally aren't using a proper Scheme or aren't using it correctly if that's the case.

I'm using the SICP language in Dr. Racket. maybe it's a problem with the implementation?

Nah, I just tested it. Terminating is fine with #lang sicp. Your code must be incorrect.

Okay I don't want to spend time on this, can a Java wizard help me out? How can I detect the parametric type in a generic function in Java?
static T
readln(Scanner s, Optional prompt)
{
prompt.ifPresent(str -> System.out.print(str));
/*
swtitch (typeof(T))
{
case char: return s.nextChar();
case double: return x.nextDouble();
defaykt: throw new Exception("Not a char or double.");
}
*/
}

Sorry, last time I used java was back in java 5 days. Things have changed.

I think Java's Optional is far more ergonomic than std::optional.

Attached: 1344970833081.gif (480x270, 261K)

Java doesn't have 'typeof' like in C#. It has instanceof which doesn't work on generic type param due to type erasure.
You need to add a parameter of type Class and do .equals(type.class)..etc

code? Sorry I need spoon feeding like a baby here. Here's my blueprint:
static T
readln(Scanner s, Optional prompt)
{
// generic function to read either char, double or a string
prompt.ifPresent(str -> System.out.print(str));
/*
swtitch (decltype(T))
{
case char: return s.nextChar();
case double: return s.nextDouble();
case String: return s.nextDouble();
default: throw new Exception("Not a %s.", decltype(T));
}
*/
}

Something like this:
static T readln(Scanner s, Optional prompt, Class typeofT) {
prompt.ifPresent(str -> System.out.print(str));
//switch doesn't work on types, you need to use a hashset or if statements instead
if (typeofT.equals(Character.class)) .....
}

Is it better to put main method on the top and supplementary methods underneath, or main method on the bottom and supplementary methods on top?

>switch doesn't work on types
Thank you, based Javabro

Me on top, you on the bottom.

Doesn't work for me. Scheme lists terminate with (), not '(). The cons cells look like this

(1 2 3)
(1 -> (2 -> (3 -> ()

Attached: issue.png (1051x215, 8K)

Trigger dpt with one phrase. I'll start

nlogn

Only have the main method in that file and separate your code (put it in another and include it and then use it in main). Much nicer than having to dig/search for main in a big file.

RUST

I made a quick game of racetrack (en.wikipedia.org/wiki/Racetrack_(game)) with javascript. it's a lot harder than it seems.

I really hate writing in javascript (or needing a transpiler) but the convenience of SVG and DOM events make it so appealing for small games like this

Attached: nani.png (889x559, 28K)

>std
>vsc
>not instantiating templates
>mixing clib and stdlib in the same file
>not using multiple assignment
>reinterpret_cast but not on a function pointer
i don't feel so Jow Forumsood

() is just what it prints. When you type it as code to run what it is interpreted as is "evaluate what is inside ()". For example take your pic. It prints (3) as the result of the operation before it, but type (3) as an operation itself and it will fail unless you've redefined 3 as a procedure (which I don't think you can do with numbers). Then run '(3) and see it prints (3).

How do I render a 3D cube onto a 2D canvas?

do you have coordinates for the cube and the viewpoint, and the normal vector of the plane? Then just draw a line between the viewpoint and each vertex of the cube, and mark where it intersects with the plane.

Google veronimesh and delaunay triangulation

Voronoi diagram**

Inline calling lambda doesn't seem to work in Java
public class partii
{
public static void main()
{
System.out.printf("%i\n", i -> { return i + 10; }(100));
}
}

It's for a tech demo so I can make it all up.

Thanks.

Java's lambdas are polymorphic tho

that syntax is completely wrong and they also need an interface
you want something like
((IntUnaryOperator)i -> i + 10).appyAsInt(100))

but you dont want inline lambdas like this

>tfw starting to understand Applicative and Functor

Attached: alpha.jpg (768x1024, 248K)