/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?
Old:

Attached: Kagari_Akko_discrete_maths.jpg (1200x675, 75K)

Other urls found in this thread:

code.tutsplus.com/tutorials/4-ways-to-auto-refresh-your-browser-when-designing-new-sites--net-13299
ioccc.org/1988/westley.c
twitter.com/AnonBabble

Sup, /dpt/.
I'm building a digital circuit simulator, specifically the interface for it. Currently trying to figure out what to do about wires and their movement.

Picrelated is the behavior of Logisim, a popular circuit simulator. It seems pretty smart: avoids obstacles, dismisses useless chunks of wire, tries to find the shortest path with least amount of changes to the existing one.

Is there an algorithm out there for this type of pathfinding?

Attached: logisim_wire_path_2.webm (632x392, 655K)

Discrete math was so easy. I did three semesters of discrete and never encountered anything that wasn't common sense.

Check out A* search algorithm

Filthy noob here. How can i preview html in Notepad++ x64 version?

Attached: 1fe.png (658x662, 59K)

You can't. You need to view html in a browser or at least something that is based off a browser to render html.

I'm learning Python by creating a FOSS Filebot alternative

you might like brackets, it's a text editor that offers a live preview in your browser as you edit code, without manually refreshing.

Drag your .html file into the browser. It will display. When you edit it in notepad, save and then hit refresh in the browser.
If you want it to automatically refresh for you look at something like this:
code.tutsplus.com/tutorials/4-ways-to-auto-refresh-your-browser-when-designing-new-sites--net-13299

Which language should I learn? Scala or Ocaml? I heard Ocaml compiles very quickly and is very fast and uses little memory for a functional programming language. but I also heard Scala has good performance as well and can access the wide variety of Java libraries as well. And with Scala native, JVM and Javascript, you can create software on pretty much any platform you want.

forth is kinda nice

: gcd ( n1 n2 -- n )
begin
2dup mod rot drop
dup 0= until drop ;

I have that textbook, it's alright.

Except for the fact that it's more unreadable than brainfuck

dis mine r8

Attached: 51nSnO5i7eL._SX403_BO1,204,203,200_.jpg (405x500, 27K)

Scala seems like a better option. In most use cases you won't see enough of a performance difference to offset the benefit of having access to Java's libraries and cross-platform development. Scala also outranks OCaml on the TIOBE index by far, so you'll likely get more support when you run into issues

what's so hard, look at this
>duplicate top 2 items in stack
>mod using top 2 items, push result back into stack
>move third item in stack up top
>drop it
>duplicate top item (for testing)
>if it's equal to zero, stop, otherwise repeat the whole thing
>drop the zero cause we don't care about it
>now we have the greatest common denominator

I have that one too, didn't like it much.

>what's so hard, look at this

Attached: Sanskrit.jpg (605x370, 22K)

Learning bit fields.
From what i understand one basically sets up few functions with hardcoded bitwise operations to control certain bits in the word.
This way you can save a ton of space.

Lads I've already lost all drive and motivation to do anything again. It keeps happening. Please respond.

Attached: 1396571416586.jpg (278x278, 34K)

You don't need functions you can check and set bits with basic bitwise operators

once I started transitioning from male to female I regained all of my motivation
you should try it

this

>feel like killing myself now
>only option is take a 50% chance of killing myself
Why is life so hard.

I have only ever learned meme languages and shell stuff and a bit of random languages here and there

I guess I need a job, is C# in linux completely uphill or what? I really disliked java and C++ seems like a lifetime investment I don't want to make, and C, I dunno, I really like it but I don't think I could get a job writing it.

Maybe I should do javascript and resign myself to webdev hell?

C# is the same shit as Java.

so basically it's perfectly readable if you actually learn it
not looking like C is not a valid criticism of a programming language

but from the little I know, I might appreciate LINQ and all the "dot net" stuff though I fucking hate that name I can't even type it without getting angry

LINQ Is just Java 8 streams with slightly better syntax.

alright, well I'm not keen on C# or Java really, though I haven't done more with C# than fuck around with a complete intro tutorial and heard things in passing.

So, I just need to do something, you know?
Are there actually jobs in languages like Rust, Elm, Elixir, Go? I'm not looking at these because I just need a job so I just need to get some proficiency and projects and so on.

Javascript is "technically" functional, isn't it? Is it possible that javascript can be a decently enjoyable language? I need to learn something widely used.

What age did you grow out of C, /dpt/?

Finally managed to upload to jitpack, build and hook up my image loading library for my chat project.

Attached: chat.png (1215x724, 30K)

I work almost exclusively in C, both in employment and personal projects.

The second I wanted to kill myself using it

I love dynamic languages for some reason

How should I map PIDs to PCBs?
Hashmap? Tree map so I can quickly generate unique PIDs?

Isn't it usually just a linked list? At least that's how it is implemented in windows kernel.

I was just going to do that for my basic implementation but I thought it'd be too inefficient because I may have to walk the whole list to find a PCB.

Nothing, because I'm so burnt out

>do nothing all day
>feel burnt out

Attached: 1418856960809.jpg (506x260, 22K)

>have achieved nothing in life
>tired

JUST

Attached: 1.jpg (600x238, 14K)

How the fuck doesn't C++ still not have designated initializer lists? They would be comfy AF.

Rust doesn't have this problem

In fact if you have a builder pattern neither does C++ or D.

>Builder pattern
No thanks.

C++ is shit, by the way.

Attached: 1374574136479.png (735x724, 685K)

They're in for C++20. G++ supports it already and it is supremely comfy. I look forward to passing comfy config structs like foo.bar({.baz = qux, .wibble = wobble}); - especially now that structs will be allowed as template parameters.

>G++ supports it already and it is supremely comfy
So does Clang. Being supported by the two most popular compilers makes them a de facto standard already, and they're soon going to be an official standard.
Cniles once again eternally btfo.

>Only supports doing it in the order the members are defined
And it's fucking useless. Sasuga C++: you're introduced more useless garbage into the language.

This is a good thing, it means you don't get fucked over by construction ordering.

>B-b-but s-sour gr-grapes...
Fucking sepplesfags are pathetic.
You're literally defending a useless and gimped feature.

When have you ever cared about the order of initializers?
I'm already using it in my projects and it simplifies things dramatically.

>When have you ever cared about the order of initializers?
It allows me to put in initialisers in any order that makes sense, and I don't need to keep referring to the original declaration.
It allows me to add and reorder members without breaking all of my initialisations.
Basically, it provides a decoupling between declarations and initialisations.

What you have is literally no more expressive than leaving the name off. You've just slapped extra syntax on there.

Thanks lads

Attached: 1404752839900.jpg (640x640, 91K)

>C++ is shit
brainlet alert!

Who cares? If you ever get it wrong, your compiler will spit out the error in a matter of moments and you'll get it fixed just as quickly. It's a small price to pay for not being deceived into reading uninitialized garbage.

handle.foo({.flag1 = x, .flag2 = y}); is just as expressive as mylib_foo(&handle, (struct mylib_foo_config){.flag1 = x, .flag2 = y}); and even more expressive than either mylib_foo(&handle, MYLIB_FOO_FLAG1 | MYLIB_FOO_FLAG2);, or handle.foo({x, y});

Does OOP damage your brain or something? I'm forced to interact with a library.
They've got a bunch of public functions that expose virtually everything in this one class. Like the three elements of a 3D vector. But there's no function for all three/just getVector() and the vector is private.
Am I being trolled?

It's as if someone heard encapsulation was a good idea but they didn't understand what it is.

>It's a small price to pay for not being deceived into reading uninitialized garbage
You cannot partially initialize arrays/structs with initilizer lists in C: as soon as a single element is added, the rest are zero-initialized, and this behaviour is relied upon.
>is just as expressive as
That's not what expressive means, dumbass.

You fail to understand the point.
struct pair {int x; int y;};

int foo();
int bar();

struct pair make()
{
return (struct pair){.y = foo(), .x = bar()};
}
This C program is bad. It suggests that foo is called before bar. It is worse than inexpressive - it is outright deceptive.

>Who cares?
data layout randomization, for example.

>I'm too stupid to know what a sequence point is

public static void main(String[] args){
PowerPlant plant = new PowerPlant();
plant.startReactor();
int exitCode = 0;
while (plant.isRunning()) {
try {
// if (plant.needAdjustment()) {
// plant.adjustThroughput(plant.getOptimalThroughput());
}
} catch (ReactorCriticalException reactorCriticalException) {
plant.shutdown();
plant.soundEvacuateAlarm();
System.out.println("Error: The reactor is critical and will be shut down.");
exitCode = 1;
}
}
System.exit(exitCode);
}

those // throw me an unreported exception.
this is my method from my reactor class.

public int readThroughput() throws NoDigitException {
try {
if(!SENSOR_INPUT.matches(".*\\d+.*")) {
int throughput = Integer.parseInt(SENSOR_INPUT);
return throughput;
}else {
throw new NoDigitException();
}
}catch(NoDigitException c){
System.err.println("The sensor can only read numbers as Strings, displaying sensor with zero" +c);
c.printStackTrace();
return 0;
}
}
this is the supposed exception that should've been displayed.
package de.gse.powerplant;

public class NoDigitException extends Exception {
public NoDigitException(){}
public NoDigitException(String message) {
super(message);
}
}


How do I caugh it or handle it so that my exception is shown?
Never did exception handlings

>Except for the fact that it's more unreadable than brainfuck
When you say unreadable, though, you actually mean "my IQ isn't high enough to keep track of the stack in my head". I'm not saying putting additional mental burden on the programmer is good, but at least be honest about the source of the problem (your brainletism).

Lisp is the most powerful programming language.

C++20 is an acceptable Lisp.

C++20 is the most acceptable programming language.

C++20 is an the most acceptable programming language for C++ brain damage sufferers.

C++20 is a little less homoerotic, which is a shame really

When you catch an exception it's not rethrown.

So readThroughput doesn't actually throw NoDigitException because it's caught right away.

If you want to catch it then rethrow it you can do
catch(NoDigitException c){
c.printStackTrace();
throw c;
}
but there are very few situations where you would want to do that. Namely when you want to close some resource, rollback a transaction...
Otherwise you can just get rid of the catch block in readThroughput and handle the exception outside the method.
Also your regex looks weird. It says anything followed by some number followed by anything, which would match something like "aaaa234aaaaa", but then you parseInt the entire string which will fail for that input.

#define _ -F

It's a career choice you have to make. If you really want to work in a meme language it's possible but you have to be willing to work in any kind of company on any kind of project, because you'll be lucky enough to find a company willing to hire you for that meme language. But it's possible.
In my opinion despite all the programming language fetishism that's common around here, at the end of the day it's just a tool. What really matters is the company, your role, the projects you work on, the people you work with, etc.
Additionally the language matters less than the ecosystem around it. Fighting with subpar tooling, amateur libraries, inconsistent practices isn't necessarily worth using a pajeet free programming language.
Have you considered python? Not my cup of tea but there are a decent amount of openings for python.

ioccc.org/1988/westley.c

>Calculates Pi.
It also launches nuclear missiles and solves Fermat's conjecture, because it's a huge pile of UB.

Yes.

What you're saying is exactly how I feel, which is why I don't feel like I need to work with a meme language, though I've enjoyed playing a bit. Having a language that's widely used will give me more options, because like you say, the company/etc and the language ecosystem/etc is what I find important.

So what would you say, is C# more or less tolerable? I've never looked at javascript but that's all over the goddamn place. I guess I could give Java another chance, it wasn't painful because like you say it's a tool.

Yeah, I have some experience with python and intend to keep working on that even though I think it's pretty gross and wish that ruby occupied python's place in the world.
I could focus on ruby I suppose, because I really enjoyed it, but on the other hand, that would probably mean Rails, and for all the love I have of ruby, I was really unhappy working with rails, what a mess.

There's literally nothing wrong with "programming language fetishism". Any programming language requires promotion before it gains traction and evolves a good ecosystem around it. The actual way to go is to be proficient at some mainstream normie language so you could find a comfy job, and then slowly undermine the stronghold of said normie language at your workplace.

based trips
based tips

I've worked in C# for 2 years versus 4 in Java, and frankly for all the C# advocates you can find on the internet, I can't see all what all the fuss is about.
Sure it evolved at a much faster rate than Java, which means it's currently a lot more modern language. But it started as a Java clone and hasn't really fixed any of the fundamental issues with Java, it just added syntactic sugar on top of it to make them more bearable.
The real issue is how Microsoft centric it is. They make the runtime, IDE, database, version control, web framework, cloud platform... Alternatives exist but there's not as integrated so they're not very attractive.
For all the hate Oracle gets, it's almost irrelevant in the JVM world, considering how influencal Google, IBM, Red Hat, Pivotal, JetBrains, Lightbend and other players are. Not even mentioning the endless high quality libraries part of the Apache project.
.NET only started being a credible open source ecosystem last year, and while it's a good thing, it's 10 years too late. The open source Java ecosystem is massive and .NET will never catch up.
Not mentioning that a lot of things are closed source and/or windows only. Whereas in the JVM world it makes no difference whether you're on Windows, OSX or Linux.
That said, while Java 8 was a major improvement, Java is still an old language that has evolved very slowly and conservatively.

i need some help with java inheritance

i have a car class with 4 private fields and a constructor with 4 parameters that sets respectively

now i have a subclass of car, which adds a field, and calls super at its constructor with the 4 parameters too.

when i do subclass.getName(), which is a field of the superclass, i get nullpointer exception. now i made a getName() method in the subclass that returns the getName() of the superclass, but that also doesn't work.

how am i supposed to access superclass fields? or am i meant to repeat the fields for the subclasses to, which seems to me is counterintuitive as it already calls super with the default fields.

Post code.

isn't dijkstra's algo useful for that if you mark the dots as graph vertices

public class Car {

private String brand;
private String model;
private String power;
private String price;

public Car(String brand, String model, String power, String price) {
this.brand = brand;
this.model = model;
this.power = power;
this.price = price;
}

public String getBrand() {
return brand;
}
}


public class ElCar extends Car{

private String batCap;

public ElCar(String brand, String model, String power, String price, String batCap) {
super(brand, model, power, price);
this.batCap = batCap;
}

public String getBrand() {
return super.getBrand();
}
}

>discrete math with applications
kek, isn't that pretty much software development? fucking npcs

if you're worried about that use a skip list?

maybe the library is just ... bad

As for Javascript, it's the most important language one can be skilled with right now, so I wouldn't even waste time thinking about how stupid a language it is, it's almost a requirement professionally.
I just wouldn't want to work with it full time. The ecosystem is beyond awful. Unreliable, needlessly complex, unstable, I hate everything about it.
But if you can stand it, there are a lot of frontend developers able to hack something together quickly, but very few able to write a complex, well structured applications with good maintainability, extensibility etc. Traditionally frontend development wasn't as complex, and the real applications were written server side, or as desktop applications, so frontend developers put less emphasis on software engineering practices. If you're one of the few who's good at it, it's a nice career opportunity.

>library doesn't follow OOP principles
>it's OOP's fault, it rots your brain
there's no winning this uh

Just get rid of the getBrand in ElCar. It's inheriting it from Car and it's public, so you should be able to call it on an ElCar object.

>They've got a bunch of public functions that expose virtually everything in this one class. Like the three elements of a 3D vector. But there's no function for all three/just getVector() and the vector is private.
You're just a retard, though. For all you know, they have a good reason to not want to expose the exact internal representation of this 3D vector. For one reason or another, they apparently consider it an implementation detail. This isn't even an OOP-specific thing - similar things are done by different means in non-OOP languages.

hm, youre right

reason i got nullpointerexception was something else, thanks:P

OK do you have a recommendation then.
I mean I already know about and dislike those things about C#, I don't have a windows partition and I imagine it will be a pain to work around that.

But like, I get they're all shit but I need to focus on something. What would you do in my position? Run with Java even though it's a bit crusty around the edges?

python and javascript? find a company I like and learn whatever they're looking for? find the perfect smaller language and become niche-valuable? give up and pick up woodworking?

>What would you do in my position? Run with Java even though it's a bit crusty around the edges?
Learn Idris.

>For all you know, they have a good reason to not want to expose the exact internal representation of this 3D vector.
Well it's exposed to me in source and it's just x,y,z floats in a struct (with countless member functions) for now. I don't see why you would need that. Sure it could be a future concern but from context I don't see that as likely.
>it's not an OOP problem
I interpret it as an OOP inspired problem by virtue of the rest of this crap. Of course I can never know the intent of the developer. But we could never attribute fault to anything but programmers in this case and every paradigm would be just as valid. I don't think that's a good way of viewing things.
>You're a retard
You don't have anywhere close to enough information to say that. You're naive for defending a random unknown library over a user when faced with a silly problem.
Yeah, absolutely, for many reasons. But why do I never see this with other paradigms? The complaints I have there are never so obvious.
I don't know of other paradigms that encourage zealous encapsulation and it is a paradigms fault if it offers problems to the implementer. They've obviously needed to expose the components of the vector. I certainly don't count a get() that just returns a component value as proper message passing. But I wouldn't want to see a more 'appropriate' interface most likely. I can wrap the component access.

rate my script to scrape all attached media in Jow Forums threads
#!/bin/bash
# scrape Jow Forums threads for posted images

if [[ -z "$1" ]]; then
echo "Usage: ""$0"" ";
exit 1;
fi

curl -s "$1" | grep -Eo '//i.4cdn.org/[^/]+/[0-9]+\.[a-zA-Z]+' | sort | uniq | sed 's/^\(.*\)$/https:\1/g' | xargs -n 1 -P16 wget -qnc --show-progress

I plan to brother, but I need to make some moneys.

their API wants you to wait a second between calls, but since this isn't using the API, does it need to respect that?

i was reading torvalds' initial linux announcement and in a reply he says
>It's mostly in C, but most people wouldn't call what I write C.
what did he mean by this? i dont know c apart from the very basics and im confused as to what he means. is linux written in non-standard c or something?

someone recommend a 2d drawing js library for someone who's never used js

Linux is heavily dependent on GNU specific extensions. But I'm not sure that's what he means.

>is linux written in non-standard c or something?
Yes, it's targeting gcc and makes liberal use of those extensions.
And the software communists laugh at clang for not compiling Linux.

I couldn't tell you what he's referring to specifically though.

you're like a baby

watch this
function scrap() {
wget -H -A '.webm,.jpg,.png,.gif,.swf' -R '*s.jpg' \
-rc -nd -Di.4cdn.org -P pics -erobots=off --no-clobber "$@"
curl -s "$@" | \
grep -o -i 'href="//i.4cdn.org/[^>]*>' | \
sed -r 's%.*"//([^"]*)".*%\1%' | \
sed '$!N; /^\(.*\)\n\1$/!P; D' | \
xargs wget -c
}

dunno never been timed out or anything