/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

stackoverflow.com/a/2752753
khanacademy.org/math/basic-geo/basic-geo-coord-plane/coordinate-plane-quad-1/e/graphing_points
pastebin.com/8YjSiFxJ
cslibrary.stanford.edu/101/EssentialC.pdf
eta-lang.org/
twitter.com/SFWRedditImages

Requesting additional opinions on my thread:

The examples are shit

Java is a good language

Anyone have non-lisp programming lang development resources?

the dragon book

I have decided to take the time to fully learn a programming language. I only have basic programming knowledge I acquired from a Codecademy Python course I completed a couple years back. (pls no bully)

What language would be the best place for me to start? I'd like to try to find something useful in the real world. Suggestions?

can somebody please help a brainlet out with math


stackoverflow.com/a/2752753
what is x in

A * x + B * y + C = 0

Java

Why is shell scripting so comfy?

I just wish you could distinguish between numeric variables and strings in shellcheck.

hobbyist or looking for a job?

is that just the general form that i don't need to care about that this guy just mentions for trivia? because i've been thinking for 10 minutes about where i get that x from and i don't have it. i can't go on like this.

x is x.

khanacademy.org/math/basic-geo/basic-geo-coord-plane/coordinate-plane-quad-1/e/graphing_points

what animu pls

Most are going to point you to Java but it depends on what you want to make in the realworld,be it databases,websites,desktop apps, etc.

GJ Bu

I don't understand. If you don't have x and y then WHAT are you trying to figure out whether or not is in a Rectangle?

x is an x co-ordinate. If you plug the x and y co-ordinates of a point into the left-hand side of that equation and it equals 0, the point lies on that line.

I've been pretty lost in life and I can only get entry level shitty help desk jobs. I need something that'll get me a decent salary mainly.

>it's been 5years since it aired.
time is enemy of man...

eat shit why do you have to make posts like these stupid motherfucker

>that'll get me a decent salary mainly.
JS + Java or C#

>the Pajeet languages that will get you barely above min wage
Nice meme faggot. You've seen the Mexicans building stuff on the side of the road? They're making more than a programmer of any of those.
COBOL is the only language where there's money.

>get me a decent salary mainly
hope you like getting paid in bananas with java

Why would you pair JS with Java? You know web applets aren't really a thing anymore and even when they were they never really interacted with JS.

Because front-end devs sometimes are expected to do more.

I love OpenGL!

Thanks everyone for the input. I'll continue to lurk for any future input on what language to start with.

I have some Java resources at my disposal already, so I think I'll start with that.

Yeah, like mySQL and maybe some shitty PHP if the company is old as shit and hasn't migrated to Node.JS. You don't "do a little Java/C# to accomplish this small task." That is the complete opposite of what Java and C# are about.

If anything it's Java and C# developers that need to know a little Javascript.

my point was JS + an enterprise lang.

Does it frustrate your mortality?

x was actually x of the test point

since i' m now free of shame because i've already demonstrated that i'm a brainlet, can somebody glance over this and tell me what i can do to make this more efficient? i don't want to make unnecessary copies and such.

pastebin.com/8YjSiFxJ

x = -(By + C)/A

I want to implement a language in python. Am I wasting my time?

New to gdb

I have a pthread_create call with a function, and the next line is a wait on a variable being true (the function will end with setting the variable true), however when I step through the program with gdb it just waits on the variable check and the function from pthread_create doesn't execute

Anyone know what this could be?

yes.

Fixed it, I had non-stop off

how the fuck does std::chrono work god

Just work on your Python. Most of the things you'll ever do will be small scripts anyway, and that's where Python really shines. If you use Windows, learn to use Powershell. And obviously Bash, if you're using Linux.

1) What you're doing is fine and efficient enough (the important thing is not to call sin/cos over and over). It's not necessarily going about the problem in the fastest way, but the way it's going doesn't have any glaring efficiency problems.

2) This problem exists within the space of something called "Affine Transforms." It's worth reading up on them and understanding them and using a Matrix library if you're going to be doing a lot of spatial stuff.

3) This will probably go over your head, but if I were putting this in a GLSL shader or something and hyper-efficiency actually mattered I'd bake the "translate then rotate then translate than invert" Matrix into a single Matrix-constructing algorithm and apply it on the point. The idea being that if you have a Matrix that defines how the Rectangle is transformed (rotated and translated) then its invert will convert the point to the Rectangle's native Space. Inside the Rectangle's native space. This means only doing a single transformation (instead of 4 like you're doing) and, you can test inside-ness simply with
if( x >= x1 && x = y1 && y

here to shill for > some more.

Here's a program to find the 10001st prime, printing each until it gets to it:
a:::***31[\>?!/l1-?\]r1-:?!/r:nao1+70.
\/{*::+1

>>
Christ.
>I honestly feel that everyone who has the spare time should learn an esoteric language.
Learn Assembly. Don't be a retard.

So I started writing a PostScript library for Fortran 77 and it started out fine, then I added some more subroutines to it and the library still compiles fine but the programs start to throw errors. The problem seems to have started after adding the only subroutine with three variables.
Here's how I've been building the library in case that helps.
gfortran -std =legacy -Wall -Wextra -Wconversion -O3 -c *.f
ar rcv PSLib.a *.o
ranlib PSLib.a
And here's the error I get gf ../test.f PSLib.a -o test
/tmp/cc2rPOWa.o: In function `MAIN__':
test.f:(.text+0xd4): undefined reference to `movet0_'
test.f:(.text+0x164): undefined reference to `rlinet0_'
collect2: error: ld returned 1 exit status
The subroutines in the error are ones that work fine before adding the additional subs

Fun, sure, but as much as I appreciate Archimedes for advancing human thought, I'd rather do my Math using modern shorthand and modern understandings of Algebra and Metric spaces rather than having to talk in ratios and allusions to convoluted physical constructions.

Could someone explain the idea behind generics to a noob? What is the point and why are they useful?

Hmm, I see your point.
Maybe I should learn *>

auto (T x, T y)
{
return x + y
}


In languages like C without generics/templates you need multiple functions to handle all the type cases. And you could go even more generic by having a user specified operator. Which would increase the function count even more. And then there's variadic function templates which say "this thing could take 1,2,3 or 5 variables.

1. Engineering a Compiler
2. Practical Foundations for Programming Languages

Most appreciated bro. I started to see that the more I thought about it but you concisely brought the point home.

Especially for more purely object-oriented languages like Java and C#, Generics can be thought of as a form of Type-safety. Because you certainly CAN have a "List" object which just has an array of "Objects", but it's nice to have a List and grab something from that without having to dynamically cast it as a Rectangle, hoping some jokester didn't put a GraphicsContext in there or something.

The subroutines it's saying are undefined are moveto and rlineto, both had RETURN
RETURN instead of just one RETURN, I fixed that but now it's throwing the same error about lineto, which is written the same as other perfectly functional subroutines
SUBROUTINE LINETO(x, y)
INTEGER x, y

PRINT *, x, y, 'lineto'

RETURN
END

cslibrary.stanford.edu/101/EssentialC.pdf

I'm kind of hyped for Scala 2/dotty. It gets rid of all the old cruft much like Python 3 did, with the end result being a surprisingly simple language that I could definitely see myself using.

...It won't cause any kind of schism between old and new versions at all or anything, honest!

Is there an easy way to retrieve the bytes of an int as a char array in C++? I'm currently using the code below, but there has to be a better way.
int a = 404;
char bytes[4];
for(int i = 0; i < 4; i++)
bytes[i] = (a & (0x000000ff > (8*(3-i));

What's the difference between if [ ! 1 -eq 1 ] and if [ "1" != "1" ] in bash?

I like the fact that Scala is essentially getting dependent types with type lambdas as the new basic foundation of its type system.

In for a penny, in for a pound. If you're going to annoy users by having a type system which doesn't let you do full type inference, you might as well make it fully dependent and add all the bells and whistles to it.

One is a value comparison, while the other is a string comparison.

>>Deprecating most of the current Scala type system.

This can clearly only end well...

How do I sort a list alphabetically?

l = sorted(l)

One way would look like
int a = 404
char *p = reinterpret_cast(&a);

However, this won't give you a char[4].
You could also do:
int a = 404;
char bytes[4];
memcpy(bytes, &a, 4)

However, both of these ways are architecture specific. Your version will always have most significant byte first (big endian), but both of these versions will match the endianness of the system they're running on.

consider also:
for (int i = 3; i >= 0; i--) {
bytes[i] = a & 0xff;
a = a >> 2;
}

Are you doing this for a single int or are you converting a char array to an int array to be read by a Network Stream or be fed to the GPU or something?

For a single int just do that and don't worry about endianness. But that extra shift is uneeded:
bytes[i] = (a>>(8*(3-i))) & 0xff;

If it's for some sort of stream, then they probably have internal ways of dealing with different Endianness and a dynamic cast should be used to avoid unnecessarily copying data.

Is type coercion different in C and C++? I know in C you don't have to do bitmasking when casting an int to a char, it just grabs the first byte of the int.

Also, check out sprintf if you want to fuck your shit up.

Well I figured it out. I shortened subroutines like rlineto to rlnto and that fixed everything, which is odd because other longer subroutine names like showpage worked fine.

The problem is Endianness. On some processors int = 0xAAFF;

Will be conveted to
byte[0] = 00;
byte[1] = 00;
byte[2] = AA;
byte[3] = FF;

On others it'll be
byte[0] = FF;
byte[1] = AA;
byte[2] = 00;
byte[3] = 00;

Presumably he cares about Endianness but possibly not.

Thank you user, a nice concrete example of their utility was helpful

ah, ok, so I guess since the mask is a literal it will be represented in memory the correct way in either architecture.

How the fuck do I do this?

Write a program that reads lines that the user inputs, until the user inputs a line that consists of the string "end". The program then prints how many instances of a certain word there was, and the word that followed that word. The following word is always taken from the current line.The words need to be in alphabetical order.

ex.1:

kangaroo tea meat video
tea video
end

words, quantity, followers

kangaroo, 1, tea
meat, 1, video
tea, 2, meat video
video, 2

ex.2:

kangaroo, meat, video
video, meat, kangaroo
end

words, quantity, followers

kangaroo, 2, meat
meat, 2, kangaroo video
video, 2, meat

I've gotten the words separated from the lines in to an ArrayList but I have no idea how I'm going to figure out the words, quantity, followers bit.

Apparently, memcpy was what I was looking for. Thank you.

Not sure how I would use sprintf for this. From what I understand the integer would be interpreted as a number in the output string, using "%n" of course. Can you use "%s" with an integer or something?

It was an int to be written to a file stream, so endianess was not a problem since I essentially implemented the reverse of my shitty loop after reading back the chars and kept it big endian.

Yeah, bitwise operators are, like addition and subtraction, handled at the processor level and represent something (relatively) architecture-independent. Where as brute-force casting is making no alterations to the memory, it's just re-interpreting it and C[++] array arithmetic is ignorant to the architecture''s Endianness.

HashMap

Bad at methods and relearning. Anyway, with simple code like:
class Program
{
static void Main(string[] args)
{
Multiply result = new Multiply();

Console.Write("Enter the first number: ");
int x = Convert.ToInt32(Console.ReadLine());

if (x != 0)
{
Console.Write("Enter the second number: ");
int y = Convert.ToInt32(Console.ReadLine());
Console.Write("\n{0} * {1} = {2}", x, y, result.Product(x, y));
}
else
Console.Write("0 is not valid.");
Console.ReadLine();
}
}
class Multiply
{
public int Product(int x, int y)
{
return x * y;
}
}
}

How would I move the zero check to its own (or the multiply) class?

I can't really be bothered thinking too much about the solution, but it probably involves some kind of tree or graph.

We must go deeper
Iterator

>How would I move the zero check to its own (or the multiply) class?
Method, not class*

Writing a booru/imageboard indexer, dumper, searcher. Currently it can concurrently (using a thread pool, i use 7 threads right now) dump pictures from safebooru, put info about them into the database and generate 256px thumbnails

>In languages like C without generics/templates you need multiple functions to handle all the type cases
In languages like C++ without comprehensive mechanisms for abstractions, generics are, primarily, a means to abstract away types. They're essentially glorified C macros.

Huh, I just found out about Eta: eta-lang.org/

It's a non-shit Haskell JVM backend. It actually works with most mainstream Haskell libraries.

Why do we need Scala again?

>JVM
Why would you want to target that garbage?

woah, this looks REALLY good

I'm pretty sure that no one on /dpt/ is smart enough to solve this.

You could pass your values to result and have the conditionals in your setters.
class Program
{
static void Main(string[] args)
{
Multiply result = new Multiply();

Console.Write("Enter the first number: ");

while (!result.setX(Convert.ToInt32(Console.ReadLine())))
{
Console.Write("0 is not valid.");
}
Console.Write("Enter the second number: ");
while (!result.setY(Convert.ToInt32(Console.ReadLine())))
{
Console.Write("0 is not valid.");
}
Console.Write("\n{0} * {1} = {2}", result.getX(), result.getY(), result.Product());
}
}
}
class Multiply
{
public int Product()
{
return x * y;
}
public bool setX(int new)
{
if(new != 0)
return x = new;
else
return false;
}
public bool setY(int new)
{
if(new != 0)
return y = new;
else
return false;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
private int x, y;
}
}

>i you don't do my homework for me, you're dumb
Well, if you put it that way!

Probably not worth the effort for such a simple program but I'll keep this in mind for bigger projects, thanks

libraries,
ability to use multiple programming languages in project, should be able to use any libraby from any language as long as the compiler compiles to jvm
compile once and run everywhere instead needing to provide binaries for each platform

also, a shame ibsearch is dead it seems, it was bretty good, so I'm trying to achieve something in it's spirit but without JavaScript maybe

>libraries
For widespread libraries, C would be a much more appropriate language.
>ability to use multiple programming languages in project, should be able to use any libraby from any language as long as the compiler compiles to jvm
Not exclusive to the JVM. Basically every language can do it through their C FFI, even if C itself isn't actually used.
>compile once and run everywhere
You know that's a load of shit.

>tfw working through SICP instead of studying for finals

>t. Cnile

Why don't you actually try refuting my points, fuckboi?

>tfw had a free day yesterday
>tfw I wasted it playing a shitty clikker game insted of starting the uni project due to the end of the week

>You know that's a load of shit.
It's not though, the problem is that the user has to have jvm implementation but otherwise it works.
>Not exclusive to the JVM. Basically every language can do it through their C FFI, even if C itself isn't actually used.
Sure but do you know anybody who exports C compatible API from language like Haskell? With every language that uses gc you have to init the runtime first before you can call anything from the library. It would become huge mess where there would be running gc for multiple runtimes and each of the them locking the process.
FFI trough C works only from C to any language.
With jvm each language would be using the one running jvm process.

It mostly uses straight GHC for the frontend and benefits form its optimization. LLVM doesn't optimize compiled Haskell well, while it actually turns out that JVM JIT better at it. It apparently runs faster than standard GHC + LLVM Haskell in some benchmarks.

An Ethereum block chain explorer.

These faggots think 256 bit integer is the next big thing. Every number is hexidecimals.

Simple enough to decode to decimals but useless for humans to look at.

dumb reddit poster

>Why don't you actually try refuting my points
Because they're brought forward without any evidence or reasoning, and can be freely dismissed because they're a load of shit. The JVM has more libraries, they're easier to deal with, interop on the JVM is easier to work with than the C FFI, and unlike C code, JVM bytecode is actually portable.

I've done this to the point where I print the words and how many words there are in alphabetical order, but I can't figure out the followers part.

Any tips?

Hello dear friend, I once ask my self this. I have learned 4 languages so far and the most important I would say is c sharp or c# it takes a LONG time to learn but after you learn that you can program anything

I feel it coming.

>LONG time to learn
t. brainlet