/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

wiki.dlang.org/Voldemort_types
youtu.be/KlPC3O1DVcg
librec.net/datagen.html
msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx
glslsandbox.com/e#35177.0
glslsandbox.com/e#35177.4
twitter.com/SFWRedditVideos

D is just okay.

pls respond

D a shit

Employed Haskell programmer sighted

import System.Environment

primes :: Int -> [Int]
primes n = sieve 2 [2..n]
where sieve _ [] = []
sieve p [x] = [x]
sieve p xs = p : sieve (head rest) rest
where rest = filter (\x -> x `mod` p /= 0) xs

main :: IO ()
main = do
(num:_)

He was flying away in this vehicle when I spotted him

Okay fine.

I was just trolling user

/dpt/-chan, daisuki~

Ask your much beloved programming literate anything (IAMA)

Use a language with actual generics

it either looks really good or really bad.

Pretty clumsy.

import System.Environment

primes :: [Int]
primes = sieve [2..]
where
sieve (x:xs) = x : sieve (filter (dontDivide x) xs)
dontDivide d n = mod n d /= 0

main :: IO ()
main = do
(a1:_)

neat

Ok, going back to java.

So I'm having a huge amount of difficulty with a program. The code below creates a simple java swing frame and allows the user to move a square left and right. If you hold down the direction key down the square jerks/lurches forward a couple of pixels about every 2 seconds. Why is this?


public class TestSquare extends JFrame {

protected static Keyboard2 key;

public static void main(String[] args) {
new TestSquare();
}

public TestSquare() {
setResizable(false);
setTitle("movesquare");
key = new Keyboard2();
addKeyListener(key);
add(new TestPanel(key));
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
requestFocus();
}
}

@SuppressWarnings("serial")
class TestPanel extends JPanel {

public static int x, y;
private Keyboard2 key;

public TestPanel(Keyboard2 key) {
this.key = key;
setPreferredSize(new Dimension(1280,720));
setBackground(Color.white);
}

@Override
public void paint(Graphics g) {
super.paint(g);
g.fillRect(x, y, 100, 100);

key.update();
if (key.left) --x;
if (key.right) ++x;

try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}

this.repaint();
}
}

class Keyboard2 implements KeyListener {

private boolean[] keys = new boolean[120];
public boolean up, down, left, right;

public void update() {
left = keys[KeyEvent.VK_LEFT] || keys[KeyEvent.VK_A];
right = keys[KeyEvent.VK_RIGHT] || keys[KeyEvent.VK_D];
}

@Override
public void keyPressed(KeyEvent e) {
keys[e.getKeyCode()] = true;
}
@Override
public void keyReleased(KeyEvent e) {
keys[e.getKeyCode()] = false;
}
@Override
public void keyTyped(KeyEvent e) {}
}

Hey OP of the thread with pic related, sorry that I didn't get the chance to reply before the thread got archived
I miss it too

>function named sieve
>not a sieve
typical hasklelfag

wiki.dlang.org/Voldemort_types

Planning on implementing a Rails-inspired web framework in Free Pascal. Might me the caffeine high because I just drank a coffee after a month without caffeine but I think it can be done.

Wish me luck

i know it's a long shot but i need 2d data for some tests, problem is some of this data is literally "draw something at random", doing it by hand is going to be a pain, and i can't use function or distributions to create them because it's either gonna be not on par with what i am looking for or way too time consuming, is there something where i can draw random shit on a board and get back 2d data?

tldr need 2d data wich i draw out by hand

not sure if you can program, but you can make an image with your drawings and then write a script to grap the x y values of the pixels that you need

youtu.be/KlPC3O1DVcg

is c obsolete and am i better off learning c++ instead

yeah ofc i can, but i need to do this very fast so i was looking for something already done, wich i found btw, linking in case anyone else needs

librec.net/datagen.html

'Is English grammar obsolete and am I better off studying English literature instead?'

so learn c then move to learning c++
!

'so I learn grammar and then write a story?'


Do a small project in C and then do a small project in C++ - you don't just 'learn' them.

Go and write fizzbuzz in C or something and then post it here.

I'm currently trying to send commands to a background program without it being in focus. I managed to send a mouse click to it but I haven't figured out how to send it to a specific location within the program yet.

I am using win32gui for Python and the method I am using is called SendMessage(). I takes in 4 parameters:
1. The window object
2. The command you wish to send
3. No fuckin clue.
4. The x and y coordinates somehow mashed into one integer.

>Rails-inspired
Gross! Such an over-convoluted mess.

>Free Pascal
Why not Ada?

>What are you working on, Sup Forums?

your mum

>Hey Bjarne what kind of haircut do you want?
>just fuck my shit up senpai
>I got you familia

>Gross! Such an over-convoluted mess.
I mean one that uses MVC and convention-over-configuration, of course not a carbon copy of Rails which in later versions has become quite bloated imo.

>Why not Ada?
I learned to program in Turbo Pascal. Just going back to my roots.

savage

well, I was going through K&R before going on vacation and now that I'm back I was thinking of continuing with it, that's what I meant by learning it, but a friend has been telling me recently that there was no point and I should just go for c++

Wth WinAPI you'd use MAKELPARAM macro but since it's probably not available in Python's win32gui, you will have to implement one yourself.

The MAKELPARAM macro packs two 16-bit integers into a 32-bit one using the lower & upper 16-bit parts of the 32-bit integer respectively.

With that knowledge we can write this:
def makelparam(low, high):
return (low

actually just go with python or ruby if you wanna make money, sure you can't brag about your autism on Sup Forums with ruby but god damn does it pay well

After a while programming/engineering you'll realize that you've stopped learning incremental chunks of information and started getting a ‘feel for things’. Your lessons will be more intuitive and exploratory and the problems you’ll face will be more sociological. At work I solve code problems all day but the bigger problems are with people management and process.

Do one thing and do it well. Do one thing and do it to completion before doing something else.

Programmers that don’t heed this end up with 3000 unfinished projects. Learn C and learn it until you have one single tangible project that you can show to someone else and which is a finished project because it fulfills a set of requirements that you set when you started it.

I tried this but regradless of what integers I put in as the last two parameters the clicks stay in the same place where I left the mouse last in the window of the program.

when trying to convert one markup language to another, is there any benefit to building a full AST instead of just translating the list of tokens?

Is there a name for rounding errors that build upon eachother? I want to make a variable that will count the total incorrectness from built up rounding errors but I can't think of a name.

I'm not sure then but I've one more possible solution. Have you checked whether the function needs the absolute coordinates in regards to the entire desktop or if they are relative to the window position?

I have tried with both options sending both coordinates relative to the window itself and coordinates relative to the entire desktop but neither worked. I don't think that is the problem I have to focus on first though. My current problem is that regardless of what I send to the function I get no change in mouse position at all. I even made a loop that changed the value each loop just to see if I could get the mouse to click in a different spot at all but no such luck. I have a hunch that it is the third parameter (currently "win32con.MK_LBUTTON") that has to specify that it is by coordinates I want to decide where to click but I can't find any documentation on what the different input options does. Not even MSDN says anything about it:

msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx

If it's small enough and/or you don't need to do a lot, you're probably better off using a list of tokens. But it really depends on what you're doing.

Playing with distance fields in GLSL. It's easy to do csg and other fun stuff with this.
My work so far: glslsandbox.com/e#35177.0

Modelling stream processors as continuous functions on final coalgebras.

>look at me, I know words

how should I rollback changes after a junit test which inserts into a database?

I'm not using any frameworks or anything, just JDBC.

Thanks for the attention!

Working on getting ROS setup on my rpi for my senior design project. Gonna use it with a kinect for some computer vision stuff.

The fucjing deadlines on this projct are ridiculous. Here's to hoping openni and ROS are well documented..

I still don't understand co-algebras
Are they sort of like multiple branches / outputs?

For instance comonoids:
co+ :: m -> (m, m)
co0 :: m -> () -- useless in haskell, unless you make it a monoid in a monad category and give it an effect

comonoid*

I suppose that would be a comonad though, like
m -> m (m a)
m a -> a

Do coalgebras help you understand comonads?

You shouldn't put your square movement logic inside of paint. You should keep it all in the button press. Windows sends a keypressed event every X milliseconds when a key is held down. Linux distros tend to send a new event entirely. So you can increase the x position in the keypressed event handler.

After that, you need to invalidate and revalidate the panel. Paint will only be called when the canvas it's drawing on is invalidated or you explicitly call repaint. So, you should do this in your event handler. Not in the paint method itself.

Only do drawing in paint. Never logic. If you need to pass data to the class containing the paint method, that's what interfaces are for.

I did some digging and wrote a version of this using a timer and action listener and another version using JavaFX and keyframes.

The same stuttering happens in both. It seems as though the every 2 seconds stuttering is something far more fundamental and related to how the drawing is distributed across hardware cores.

This gets the same problem:

public class MovementStutter {

public static void main(String[] args) {
JFrame win = new JFrame("Stutter Demo");
win.getContentPane().add(new GamePanel());
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setResizable(false);
win.pack();
win.setVisible(true);
}
}

@SuppressWarnings("serial")
class GamePanel extends JPanel implements ActionListener {

private boolean running;
private double x;
private double y;
private double movementFactor;

public GamePanel() {
setPreferredSize(new Dimension(640, 480));
setFocusable(true);
grabFocus();
movementFactor = 1;
running = true;
new Timer(16, this).start();
}

public void actionPerformed(ActionEvent e) {
update();
repaint();
}

private void update() {
if (!running) return;
if (x < 0) {
movementFactor = 1;
} else if (x > 608) {
movementFactor = -1;
}
x += movementFactor * 200 * 0.016;
}

@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.fillRect((int) x, (int) y, 32, 32);
}
}

Scapy is a Python library which allows someone to craft packets. You can use the command ls() to list layers and commands.

Does anyone know the Python equivelent of using ls() for some functions?

It would be really useful to know what arguments can be passed into functions, similar to what can be done with with Pycharm.

How did oracle let java get overtaken by c# in features and quality so fast?

By not having any features or quality

Because Java has to wait for all 12 billion people on their mailing list to complain about potential features, and C# just goes for it, anyway.

There was also no historical baggage, so on C#'s end, things like type-erased generics and half-baked 'streams' were never a problem.

Whats the actual problem is with type erasure?

Because Oracle doesn't actually give a shit about Java.

How did Bjarne Strousup let c++ get overtaken by rust in features and quality so fast

It's just a shit system compared to reified generics where the type info is preserved.

That, too. It's unfortunate.

What are the tanglible consequences to the programmer?

No serious business will move to Rust.

Runtime type safety, and also that pesky issue of primitives is not a problem.

He refused to attach a CoC to his language, and that was really his downfall.

>tfw no impredicactive types

Just made a js implementation. I get the same thing with that also.

This is getting pretty spooky.

I might try and make a really basic torrent client

language growth should be taken cautiously

c++ never stopped growing. It just stopped getting quality features and instead got a million more half baked datastructure objects.

>got a million more half baked datastructure objects

what do you mean?

How should I know, I'm just a shitposter.

my brother please help me
i have compile the code but it does not run
i require the solution immediately email [email protected]
please do the needful

What the fuck is the "Function Object technique" for Java? It came up in my class this week and I can't find any good online explanations. I can tell it's something about passing methods as parameters to objects or methods, but I'm not really sure how to use it or what it's useful for. My professor is really shitty so he didn't even mention this in class.

it's higher order functions + OOP bloat
Higher order functions are insanely useful

Replication is fun.
glslsandbox.com/e#35177.4

Doing c++ and using google test framework, and using anonymous namespaces.
I can name anonymous namespace something like internal but that i really don't like them being seen from outside the namespace they were meant to.
I could #include the .cc files in the .cc test files and compile from there, is that seen as a dirty practise or acceptable?

say I have a hierarchy of classes, and all of the concrete ones call a method after initializing variables:
public Dog(...) {
super(...);
someMethod();
}


and this too
public specializedDog(...){
super(...);
someMethod();
}


I only want to ever call method once. So what if I instantiate a specializedDog, then it calls super and super calls someMethod, and then specializedDog calls someMethod. I don't want that to happen.

what do?

OOP IN LOO

Depends what language.

java

the thing is that deep hierarchies are bad. remember: composition over inheritance

You could do any number of things, pajeet, but given we don't really know what you're trying to achieve, it's hard to give advice.
I would be tempted to say you're doing OOP wrong, and make Dog more general.

I was interviewing with a "too proud of my java skills"-looking person.

He asked me "What is your knowledge on Java IO classes.. say.. hash maps?"
He asked me to write a piece of java code on paper - instantiate a class and call one of the instance's methods. When I was done, he said my program wouldn't run. After 5 minutes of serious thinking, I gave up and asked why. He said I didn't write a main function so it wouldn't run. ON PAPER.
[I am too furious to continue with the stupidity...]
Believe me it wasn't trick questions or a psychic or anger management evaluation thing.

I can tell from his face, he was proud of these questions.

That "developer" was supposed to "judge" the candidates.

some assignment for my architectures class on database to domain mapping. the professor specifically wants database mapping logic in the constructors. I'm stuck working with this design.

Basically each domain class is supposed to be like an active record.

Originally I thought of having all the logic inside each constructor, but then I realized that I would connect to the database multiple times. So now I'm trying to add an insert method that each concrete class overrides.

Why not use a D atabaseCon nectionFactor yF actory?

Did you get the job?

Also keep going.

>not just using an AbstractBean

I want to go full NSA and start a database to keep tabs on everyone I know. What language should I use to build it? I thought of SQL, but keeping everything need and tidy might be a bit cumbersome. Maybe javascript? It's not really fast, but I won't know those many people of interest in my life and being able to just add properties to objects would be helpful if I know someone's mother's maiden name, for example (which I obviously won't know for everyone). Maybe some sort of graph database language? Or SQL with those oop-esque extensions?

Any suggestions? And yes, I know it's creepy and "autistic", but I'm already too far gone to go back now.

le haskell > java POO IN LOO OOP langzz

amiright?
AbstractBeanGatewayFinderFactory lololol

go back to india PAJEET

>Guy is literally fighting with OOP
>Not a poo in loo language

database constructor guy here. I feel like an idiot. obviously I just throw the method into the super class constructor and it delegates to the appropriate implementation at runtime.

I'm pretty much an honorary Pajeet at this point.

Is there any valid use of multiple inheritance?

OOP is a choice

I'm trying to find a way to grab the links from all the videos in a jewtube playlist and store those links to paste them elsewhere but Im so lost at this point. I think I might just automate my mouse to do it because Im losin hope. Any codeguru have any alternatives for a newcodefag?

Inheriting multiple ABC classes in C++.

calling attention to this post again

I just want ideas

Just use MySQL or PGSQL, design a decent database, perhaps blobs to store data (like pictures, recordings and so on) along the meta.
Then slap simple web interface on top of it or some CRUD app for easy management.

You can only understand Haskell if you speak Norwegian, because monads come from the Norwegian word måned.

The only reason I'm not going straight to SQL is how hard it'd be to add random properties to certain rows without creating an entirely new attribute on the table. That's not possible, is it? Unless I use the oop extensions I mentioned

I don't want to end up with 1451612612 attributes where most of them are only not null for one or two rows