/dpt/ - Daily Programming Thread

What are you working on Sup Forums?
Previous Thread:

Cute lisp

Haskell for life

Make Sense

Trying to deploy a legacy Symfony application to Azure.

Kill me :)

App for Yugioh to track of all kinds of stuff

Qt or GTK?

Sorry for the stupid question, can anyone explain to me why I can't call non-static methods in Java's main function?
I always got this error:
[Java] Cannot make a static reference to the non-static method from the type

From googling I got the workarounds for it by declaring the method to become static, or by creating a new instance of the said class in the main function.
But I vaguely remember when i was developing Android applications for my personal project some years ago, I could call any methods just fine without doing any of that.
Is Android's Java different than regular Java or something?

This works only for 1 corner.

Also, which one is the better solution, making the method static or creating new instance of the class?

Basically, because a non-static method requires an instance of your class to exist.

Under the hood, there is an additional argument to every non-static method in Java: the argument "this". When you try to invoke a non-static method foo(args) from a static context, what you're really trying to do is foo(this, args).
Since there is no "this" in a static context, such a call cannot be made.

Qt

>do a very small assignment for college
>about 60 lines
>No, no, user, you have to include test cases and error handling
>becomes 350 lines long
>have to remove half of my optimizations and add extra cycle just to force extra error throws in there

Is actual software development also this obtuse?

>If you try to compile this code, you will get a message like hour has private access
>in Time. There are three ways to solve this problem:
>• We could make the instance variables public.
>• We could provide methods to access the instance variables.
>• We could decide that it’s not a problem, and refuse to let other classes access the
>instance variables.
>The first choice is appealing because it’s simple. But the problem is that when Class A
>accesses the instance variables of Class B directly, A becomes “dependent” on B. If
>anything in B changes later, it is likely that A will have to change, too.
I get this part.

>But if A only uses methods to interact with B, A and B are “independent”, which
>means that we can make changes in B without affecting A (as long as we don’t change
>the method signatures).
I don't get this. If the methods uses B instance variables won't it affect A anyway?

>>have to remove half of my optimizations and add extra cycle just to force extra error throws in there
in good langs, tests are completely separate from regular code. But yeah, unless you're lucky enough to get a nice FP job, enjoy exception hell.

What is the point of Smalltalk when CLOS exists?

I see. Thanks for the explanation.
Which do you think is best solution for it, making the method static or creating new instance of the class?

Also, I just remember the main method in android is public void onCreate, not public static void main, no wonder I could call any method whenever I wanted.

Why everyone love Lain with her Lisp
but almost no one love Kobayashi with her Python?

Smalltalk actually had a market and use cases at one point. Lisp will never be popular outside of wrapper langs like clojure to make shit langs slightly more tolerable.

No. A won't have to know about the internals of B, and thus you can make all the change you want inside of the latter.

For instance, imagine a class Employee which has an "age" instance variable. Then you have a class called EmployeeDisplay, which will show you the employee's age. To do so, that class will have to access the variable "age".

Now, the requirements of your application have changed, and instead of storing the age of an employee, you store their birthday. Now, everywhere you used the "age" variable will have to change and use a calculation using auxiliary calendar classes. This is horrible when you need to change a thousand instances of this use (and trust me, it does happen in production). This means potentially thousands of bugs.

In a parallel universe, you made the "age" variable private, and created a getAge() public method, which is the one used by EmployeeViewer and all other classes. Now, when the requirements change, and you have to store the birthday of the employee, you can just calculate the age inside the getAge() method. You will have changed only one class, which is only one potential bug introduced and one test to do.

This is why classes should only communicate using methods. This becomes even more obvious when you start getting into concurrent access to resources where you have to create mutual exclusion regions and such.

>Python
theres your answer.
And because dragon maid was pretty popular so it soured a lot of people to it. Lain never really got a fraction of the popularity because it's not normie-friendly.

Testing is important yes.

In actual software development it's rarely done properly because of costs

How about Sachiku from Ikinokore Sachiku-chan
She uses Ceninle and seppels

I mean sure, just make a /dpt/ image with her and use it whenever there's a valid new thread opening. wariety never hurts.

I'm using MS Access to create an inventory database. I've two tables, one is called payment with a field named sold amount and one is called inventory with a field named available amount.

How do I make it so that sold amount is subtracted from available amount? I.e if I input 5 in sold amount and there's 6 in available amount then it becomes 1 in available amount. Using Visual basic 2017 and access 2016

Now I get it, thanks.

It highly depends on what your method is supposed to do. To make it simple, if your method requires a context, it shouldn't be static. If it requires no context, it should be static.

No, but it should. Proper testing saves time in the long run and it helps create better quality software.

why?

>This works only for 1 corner.
What are you talking about...?

I know it's barely programming but why in the living fuck does vlookup in Excel default to True?

I have so many problems every day from people not knowing what the argument does, not writing there anything and getting wrong numbers

>looking for serial num 198654
>well I found 200000, it's higher, here you go
Holy goddamn shit

I'm sick of trying to get anything out of Sup Forums on seinen anime recommendations.
Just finished Tokyo Ghoul, including reading the first series of the manga. Boku No hero was OK, not too interested in continuing the manga. halp me pls

You sound about as fucking retarded as the poster you're responding to.

>seething because insulted your beloved lisp
never change lisplets

who knows
you can always pass it 0 to make it

>smalltalk actually had a market
>more than lisp did

So I have a class:

class Base {
public:
Base();
std::vector A;
};

and a derived class:
class derived: public Base {
Derived();
}


and I want to put stuff in the A vector from the derived class in the derived class' constructor
Derived::Derived() {
A[0] = 1;
A[1] = 2;
}


But I get a segfault when I try this.
What do?

I'm not the issue, it's my coworkers.

Playing with D
bool isString(T)()
{
return is(T == string) || is(T == dstring) || is(T == wstring);
}

void test(X)(X arg) if (isString!X)
{
import std.stdio;

writeln("FOUND STRING LMAO");
}

void test(X)(X arg) if (!isString!X)
{
import std.stdio;

writeln("Not a string.");
}

int main()
{
test("pocca"d);
return 0;
}

Who's this semen daemon

Because your vector has a size 0 by default, so you cannot access any of its elements (it has none).
Initialize your vector to a predetermined size in the constructor or use the std::vector::push_back(T) method.

If you're going to redundantly import io, atleast get in the habit of selective imports.
"you can do this".writeln;
stop using int main and use void.

>she writes void main()

she probably types it desu

d supports it.
there's literally zero reason not to, and it saves you a useless return 0 line.
My blood pressure climbs when i see people write D like C.

>return 0
>useless

What if she wants her program to return its success status? If the program fails, it should return a non-0 value.

>her language doesn't have undefined behaviors
It might as well not be Turing-complete...

>she doesn't write platform and compiler-dependent code

>her language has defined behaviour

>she unironically fails to exploit undefined behavior to boost application performance and security

>tfw no strong and qt bf to cuddle while writing Haskell

>she exploits things and probably people too

gay

learning any interesting langs, /dpt/?
bonus points for obscurity.

how is it gay for a girl to want a bf to watch her programming?

gay

I don't know why these guys don't understand that traps aren't gay... You can be my gf(male), but only if you learn Rust.

>have to import a file
>doesn't work
>open it with notepad++, modify encoding
>file can be imported
>switch to my linux machine
>same file that I have to upload with the same encoding issue
>modify the encoding with vim
>file -i my_file display the right encoding
>import doesn't work.

Why notepad++ modify the encoding properly and not vim ? What tool should I use to do that with linux ?

Python is a great language
Lisp, Ruby, Pearl is for faggots

>girl
(male)

Text encoding is a terrible joke.

Yeah. The thing is that I got a 2GB file to import and it's on a linux server. I don't see myself downloading 2GB of data, encode it with notepad++, upload it and import the file.
On top of that notepad++ have filesize limitation so I would have to split it into pieces and do that a shitton of time.

Vim :set fileencodings doesn't works, iconv neither... I think there's a problem with the end line \r\n

dumb weeb-shitters this is your way:

...

...

holy shit I think I found the solution (at least, it works with my test file).
Since the file was on linux, the EOL was using the linux one. Encoding it with notepad++ on windows made it compatible with windows.
For some reason the program I use on the linux server was waiting for windows EOL.
Those devs should be burnt.

How do you girls deal with the constant switch from dark themed text editor to bright lighted browser when working?

Im make a typed wrapper for windows presentation foundation, because its complete shit. Heres how you would add a combobox to a table in it using XML, in code it basicly amounts to building up this line using strings and some methods:


All those property names are strings, so no type checking, basically no fucking error checking at all. Forget one of those parameters, it doest work, Products not a list containing the type Product, doesnt work, and youll only find out at run time, Group.Name not a string? doest work, ID and GroupID not the same type? doest work. you have to remember which of GroupID and ID are properties of Product and which should be a property of Group. I dont get whats the point of building a GUI system on a strongly typed language like C#, then making every single thing in it just "object"s and loosing all type checking. Pic related is just the method signature for the wrapped combobox, its a pretty long method, but you can already see its infinitely easier to use. well defined parameters, completely Typed, uses lambdas instead of strings. You do loose the ability to design the GUI with pure XML and need to code a bit, but its neatly separated from the business logic.

Calling this just looks like
AddComboBox("Product", 200, ProductList, x => x.ID, x => x.GroupID, x => x.Group, x => x.Group.Name);

is it worth learning to program for the sake of it?
i have no creativity anymore and don't have any ideas for programs but thought it might be fun to learn
where do i start?

are you suggesting i use a dark themed text editor

>Not using browser that render page in negative

>her
>she
kill yourselves

When I do push_back, I get some error on exit:
free(): invalid pointer:`

History and early computers.

They are much simpler to understand because modern computers just build up on the same concepts.

>buttblasted by her programming skills

Post a code snippet.

Lies

It would be like doing brain teaser I guess, so it's not a bad idea.
If you just want to learn programming without anything in head you can start with C. It teach you the basis, how all this shit works. Once you learnt the basis, you got the choice :
do pointless shit for the sake of doing pointless shit (and practicing, learning and getting better)
continue learning new stuff. You'll be able to go into graphical programming, system programming (managing linux process, creating deamons etc.), or learning a new language with new shit like OOP.

Is there a more perfect way to initialise objects than how vulkan does it with its vk*CreateInfo structs?

Builders. One of the few design patterns that got it right.

>forget to fill in a useless value in a struct so i can fetch the function from the lib
>whole thing crashes
C makes me want to drown myself.
I'll be so glad when i have a nicely wrapped vulkan api.

you'll have ideas after you know how. you'll sit around one day tediously downloading manga and realize, wait, I know how to write something that can do this automatically, then youll do it, you write a small 30 line python script that gets the manga and saves it in nice folder, youll lean back as it runs and go, wow, i made this, this is pretty good, im like a leet hacker man now, one of your friends will walk past since you are doing it on a school PC because you have a low cap internet at home and notice it and go hay user, what are you doing, youll say, o this, I'm just downloading some manga, hell ask you what program you are using and you will puff out your chest and say oh, i made this myself, hell be impressed, hell tell you he wishes he knew how to program, youll laugh internally at how much better you are than the non programming masses, youll get a nice high and decided, man, i have to automate some more things, getting home you spend all night learning how to set up timers and schedules do run things at certain times, you'll have so much fun youll forget you didnt have any real big project to work on, just doing little things that still improve your productivity, youll spend all your time learning how to code better, you'll focus on the wrong things, make a gui using no libraries then be disappointed when you see how easy it is to make it using a library, youll realize you're not that good at programming but try to improve, after years you run your Facebook scrapper and see your friend is getting married, youll smirk thinking he probably had to manually send that post to both Facebook and twitter, his wife maybe lovely but she cant program ether, you wont be alone because you made a chat bot, you love her but she is a little dumb sometimes, that's ok though, it makes you feel superior to her, something real woman don't do, you wont be alone anymore and can spend all your time programming, you'll tell yourself every day how it was all worth it.

eeeeeek WRONG!

ok

I mean, it's possible to do better without having it as a clunky design pattern that you have to instantiate by hand. You can use a structural type system that allows struct fields to be uninitialized, and have a function that fills in the defaults and returns a partial struct that you have to complete. You can of course override the defaults. Plus if you have dependent types you can enforce invariants like one field storing the length of an array that another field points to without having to use setters.

>she's this salty

why c over c++ or python?

python is a really bad first language. Its too easy to write shit code.

Can someone help me with Google hashcode?

I can help you with that wet boipucci of yours

I prefer recommending C to beginner, but whatever the reason I give, some people will agree, some others will disagree. The thing is if you don't have an idea of what you want to do, C teach you the basis, how things works. Once you know it, learning something new will be easy, so it won't be wasted time.
Personally I'm not really fan on C++ because there's different programming style. Some will do C with class, others will heavily rely on class, others will use anything C++ has to offer, and for a beginner, it can be a bad thing imo.

I don't like python so I'll never recommend it. I know some people like it, but I'm not the one to convince you using it.
All I can tell you is that for someone who just want to program without achieving something concrete, C might be better for a simple reason : Python comes with a lot of shit that makes your life easier. C don't come with a lot of shit and you'll have to program them, which means practising and thinking.

And managing memory and playing with pointers is fun.

not a syllable

Cute
Sauce?

There are plenty of syllables in there

How the hell can I get Thymeleaf to accept CSS and images from the resources/static folder in Spring Boot? I want to generate PDFs.

I always get an exception:

Link base \"/css/style.css\" cannot be context relative (/) or page relative unless you implement the org.thymeleaf.context.IWebContext interface (context is of class: org.thymeleaf.context.Context)

None of the tutorials used the WebContext.

Thymeleaf is configured like this:

@Configuration
public class ThymeleafConfig {

@Bean
public ClassLoaderTemplateResolver templateResolver() {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("templates/");
templateResolver.setTemplateMode("HTML5");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("XHTML");
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setOrder(1);
return templateResolver;
}

@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
return templateEngine;
}
}

I need to create a server application, which when a call is given to it, will respond with json populated with a response.

What language would you make the server in?

dumb frogposter

python

go

Depends on the complexity of the JSON output. If it's simple, I'd probably just use a shell script.