[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 325
Thread images: 26

File: 1481234393653.png (102KB, 1000x1071px) Image search: [Google]
1481234393653.png
102KB, 1000x1071px
What are you working on, /g/?

Old thread: >>58084335
>>
>>58091373
First for C#
>>
Second for F#
>>
>>58091373
Trying to cross-compile a library for 3DS Homebrew

It's suffering.
>>
!(Thank you for using an anime image)
>>
File: mask - output.png (3MB, 2012x1000px) Image search: [Google]
mask - output.png
3MB, 2012x1000px
>>58091373
I'm creating simple 2D textured maps.

Pretty simple using a BMP C lib. The next step is generate the mask randomly using a perlin noise algorithm.
>>
So I've been working on a chess program.

I have everything implemented except for castling and en-passant pawn taking, but I'm wondering about my checking for checkmate function.

Right now I'm using a O(n^2) (n = 64) method of trying to move every piece to every spot and checking if the king is out of check afterward. Is there a more efficient solution?
>>
> go to interview
> interviewer ask me a programming question
> know Haskell because /g/ told me it was the best language
> start to solve it in haskell
> "umm, anon i don't know haskell, can you do it in other language?"
> "uh sure..."
> remeber seeing some C code on /dpt/
> don't remeber anything
> start sweating
> drop my spaghetti
> got the hell out of there
>>
>>58091333
When you work with other people and they use your classes and shit, you have control over what they can fuck with and what they can't. If everything was public, then they could go in and fuck with every member variable and they could just fuck everything up.

But if you're using github they'll have source code, so why couldn't they just go in and change it manually anyway?
>>
>>58091513
How the fuck did you get an interview with just Haskell and no other language

Teach me your ways
>>
>>58091531
>things that never happened
>>
>>58091513
Wow you posted it again, well done
>>
>>58091513
Hahahahahaha, that's so funny.
>>
Also we have a functional programming thread:
>>58076404
>>
>>58091495

Looks like you've got a lot of sand in your ocean, there, boss.
>>
template<typename T>
T average(T a, T b)
{
return a/2 + b/2 + (a%2 & b%2);
}

Did we finally do it? Did we finally create an average function in C++?
>>
>>58091819
>(a%2 & b%2)
>&
dropped
>>
File: REEEEEEEE.png (5KB, 407x55px) Image search: [Google]
REEEEEEEE.png
5KB, 407x55px
>>
>>58091919

Nice.
>>
>>58091840
Why dropped?

Find a better way to compare two ints for a true value.
>>
Does anybody know how to implement correct async/await method in WPF so that my program doesn't freeze? Program works but i can't do Thread.Sleep(n) in a while function

Here's a small section that is giving me trouble

private async void Button_Click(object sender, RoutedEventArgs e)
{
string car;
string price;
string link;

var task = Task.Run(() =>Thread.Sleep(10000));

// ----Simulating GET request for website scraping, this part works----


//-----End Simulating GET----

myList.ItemsSource = myClients;
string searchCar = txtBlock.Text + " " + txtBlock2.Text;


var articleNodes = htmlDoc.DocumentNode.SelectNodes($"//*[@id='main_content']/div[1]/div[2]/ul[1]//*[text()[contains(., '{searchCar}')]]");

while (articleNodes != null && articleNodes.Any())
{
foreach (var articleNode in articleNodes)
{
car = WebUtility.HtmlDecode(articleNode.InnerText);
price = WebUtility.HtmlDecode(articleNode.ParentNode.ParentNode.SelectSingleNode("span").InnerText);
link = WebUtility.HtmlDecode(articleNode.ParentNode.ParentNode.Attributes["href"].Value);
myClients.Insert(0, new User(car, price, link)); //inserts new item on top of ObservableCollection
}
await task;
}
}}
>>
>>58091790
Yeah, I remove it. No worries senpai
>>
>>58091951
Ok, i have managed to do it with
 await Task.Delay(10000)
>>
>>58091951
>>58092054

Oh shit, everything works, but i just realized if i press the button again with different selection, the last selection will continue working

How do i stop button from doing while loop?
>>
>>58091951
>
async void

STOP RIGHT THERE, CRIMINAL SCUM

Read this before you go any further:
https://msdn.microsoft.com/en-us/magazine/jj991977.aspx

And you should be using
Task.Delay()
instead of
Thread.Sleep
.
>>
>>58091819
>all those assumptions
>it still doesn't work
>>
>>58092093
Disregard that, I suck cocks and didn't see that this was a button event handler.

>>58092090
If I were you, I would disable the the button or display a loading screen until the first one is done.

Otherwise, you're going to have to have a listener that stops the task execution when the button is pressed while it's doing the initial work.
>>
>>58091946
>Find a better way to compare two ints for a true value.

>ints
>generic template argument

>ints
>assumes two's complement

DROPPED
R
O
P
P
E
D
>>
>>58091819
>average<int>
>returns int
>>
>>58092105
>I would disable the the button or display a loading screen until the first one is done.

Currently, the program is designed to scan the site every 10sec, it should work continuously, but it would be the best if started searching for different parameters if textblocks are changed.

Otherwise, if you have to click the button again, i have no idea how to stop the last while
>>
>>58091951
You shouldn't be using Thread.Sleep() with GUI applications. I think you have to create a new thread and run the asynchronous method in that thread.
>>
>>58092187
>>58092054
Solved it seconds after posting

Now the problem is
>>58092090
>>
GC allocators are faster than malloc
>>
>>58091513
>implying C isn't so easy practically anyone can write it
Either way. Realistically if the interviewer asks for C for his convenience pseudo code is a good middle ground.
>>
>>58092113
>generic template argument
fine, here
template < class T,
class = typename std::enable_if<std::is_integral<T>::value>::type>
T average(T a, T b)
{
return a / 2 + b / 2 + (a%2 & a%2);
}


>assumes two's complement
Do you have a better way to be compatible across all platforms?
>>
>>58092209
They're not.
>>
>>58092209
That's completely irrelevant because any decent MMM doesn't do straight alloc's
>>
I got A- in Java midterm are you proud of me :3?
There were 3 A- 1 C rest F and D. wew lad
>>
>>58092224
Are too

>>58092241
Made me think what you meant by that
>>
>>58092242
It tends to look that way. Somehow. It's beyond me how people manage to get D's in programming courses.
>>
File: 250px-Trie_example.svg.png (15KB, 250x234px) Image search: [Google]
250px-Trie_example.svg.png
15KB, 250x234px
I'm writing a trie.

I need each node to have a "size" parameter that tells you how many entries there are below it.
How do i insert an entry into without going through the word twice?

class Node {
Map<Character, Node> next;
int size;
Entry entry;
}

void insert(Node root, String word, Entry entry) {
// insert entry into root
// if entry didn't exist, add sizes to all nodes from root to leaf (here you're going through the word again)
}
>>
>>58092140
http://stackoverflow.com/a/1481577/4479934
>>
>>58092209

Memory arenas are faster than both.
>>
>>58092209
And yet naively mallocing and freeing everything will never lead to multi-ms-long application pauses.

>>58092245
You're a retard.

I actually am fine with GC when it's opt-in and is used regionally. That way you don't end up with stop-the-world and can save GC for when it's really needed (rarely).
>>
>>58092259
Well fuck me, i'm just a beginner, this shit is way over my head
>>
>>58092245
Nobody who gives half a shit does memory management in a way that means they system-call allocate each resource on demand. A common model would be a https://en.m.wikipedia.org/wiki/Region-based_memory_management
Basically the issue with comparing GC to malloc is that they're not corresponding to each other.

Also you could interpret that a complete run of your GC is faster than a single malloc call.
Which I don't buy. Many applications would actually just need a single heap allocation believe it or not.
>>
>>58092294
Well, what you're proposing is to stop a running thread.

You never want to do that straight up, because no one knows what that could potentially do.

Simply add the flag to your method to activate if there's already a running method of the same call, then in your while loop, abort the loop and handle an unfinished run if it sees that flag as 'true'.
>>
>>58092222
>Do you have a better way to be compatible across all platforms?
Yes, don't rely on two's compliment.

>>58092245
>Are too
They're not. malloc is basically just a call to mmap.
>>
>>58092255
What kind of data are you storing? How is it ordered, I mean.

Basic principle is to start off with the root node, and as you recurse throughout inserting, increment the size as you find the place for the node
>>
>>58091506
The way I had mine setup was with a bitboard.

I had a function which would see if the king was in check. It just generated a series of bitmasks for where each of the opponents pieces could move next turn and checked against the king.

Then I had an iterator for all the pieces and an iterator for all the moves for each piece. It would filter results with that check function.

Checkmate was easy to implement, it was just the case where you had no more moves and was in check.
>>
File: 1472164812189.jpg (24KB, 390x234px) Image search: [Google]
1472164812189.jpg
24KB, 390x234px
>mfw GCucks still have to manually free resources other than memory because their shit languages don't bother with RAII
>>
>>58092350
While you're busy hand-optimizing your allocations, we're making productive programs.
>>
>>58092328
Its just a regular trie. What Entry is, doesn't matter.
If you always increment the size, the following happens:

insert(root, "abc", new Entry()); // root size is now 1
insert(root, "abc", new Entry()); // root size is now 2, new entry overrides the old one
delete(root "abc") // root size is now 1 even though no entries in the trie
>>
>>58092222
>Do you have a better way to be compatible across all platforms?

>(a%2 & a%2)

a % 2 != 0
>>
>>58092350
>mfw sepplemales have to write C++
>>
File: 635611592922924817.png (142KB, 1360x705px) Image search: [Google]
635611592922924817.png
142KB, 1360x705px
>>58092360
>sorry user, I was being productive but I've decided that I'm now going to take a 30 ms break

>>58092376
>implying I use C++
>>
>>58092350
>RAII
>good software
Pick one.
Not even a GC fag.
>>
>>58092403
What's wrong with it C baby?
>>
>>58092350
>RAII fags STILL have to explicitly define destructors as well as the other resources owned by the object in question
>>
>>58092426
>explicitly define destructors
Not if the type is only made up of RAII'd or non-resource parts.

>as well as the other resources owned by the object in question
Well, obviously. Do you expect the compiler to just read your mind and program for you?
>>
>>58092311
Looking at the stackoverflow >>58092259

I see this code
private object m_lock = new object();
private bool m_isRunning = false;
private bool m_isAbortRequested = false;

public void OnButtonClick(object sender, EventArgs e) {
lock ( m_lock ) {
if ( m_isRunning ) {
m_isAbortRequested = true;
} else {
m_isAbortRequested = false;
m_isRunning = true;
ThreadPool.QueueUserWorkItem(BackgroundMethod);
}
}
}

private void BackgroundMethod() {
try {
DoRealWork();
} finally {
lock (m_lock) {
m_isRunning = false;
}
}
}

private void DoRealWork() {
...
if ( m_isAbortRequested ) {
return;
}
}


Now, I guess this is a flag system that checks if i want thread to close or not, and if i don't it performs my method (in my case, web scrape).

How would i sign that i want to close the thread, assign new button that changes m_isAbortRequested to true?
>>
class Constructs t k m where
construct :: k -> m t
class Destroys t m where
destroy :: t -> m ()


raii :: (Constructs t k m, Destroys t m, Monad m) => k -> (t -> b) -> m b
raii args f = do
x <- construct args
y <- f x
destroy y
pure x



>inb4 muh applicative functors
>>
>>58092457
*pure y
>>
>>58092442
I expect not to have to deal with trivial bullshit constantly.

If I need the performance advantages attained by the disadvantages of needing to manually determine the lifetimes of all of my resources, as well as manually managing memory, I will go and write a C or C++ module to perform this singular task.

Until then, I'll be happy and productive in a language that gets the fuck out of my way and lets me describe what I want the program to do, without having to babysit all of the tedious details.
>>
>>58092384
>>implying I use C++

What other language has RAII?
>>
>>58092255
Not sure what you're trying to achieve.

node.size = (entry == null ? 0 : 1) + sum([n.size() for n in next])
>>
>>58092473
D and Rust (most popular ones that aren't C++), in which case you're free to laugh at that anon.
>>
>>58092473
>What other language has RAII?
Not him, but Python for one
>>
>>58092486
Python does not have actual RAII.
>>
>>58092316
>Yes, don't rely on two's compliment.
I'm not relying on anything. Relying on two's compliment would be
a & b & 1

My code is
a%2 & b%2

If a and b are both odd, then they should have the same value. Meaning a%2 == b%2, and when that's guaranteed for a%2 & b%2 to have a int value of 1

>>58092367
Second a should be a b
>>
>>58092490
It does. GC is of course default, but there is implicit reference counting allowing you to implement RAII style objects that delete their own reference when the refcount is 0.
>>
>>58092470
If you can use libraries and whatnot and not have to touch memory or FFI directly (which would be the case the majority of the time) then the resource management and lifetimes and whatnot is done for you, you just have to follow the restrictions of the API.

>>58092473
Rust
inb4 irrelevant ESS JAY DUBBLE YOOS GitHub discussion link
>>
>>58092486
You mean
 with __ as ___:
? I'm not sure I would call that RAII.
>>
>>58092408
Well the primary reason it's bad is because it's uneccesary and it's only purpose is to provide convenience for bad programmers.

I don't think I've written an application with RAII where RAII helped me more than it wasted my time.
I don't do 'resource' allocation and deallocation all over the place. And where I do the issues are trivial to catch my self if they ever were to appear. As a general principle (as the name implies and proponents generally argue, you use it wherever you can) it's faulty.

I don't oppose the idea that if you have a file accessor reference of some sort you'd like to close the file when that reference goes out of scope for instance. But that's the edge case. Your program should ideally open and close files only at a few places in the program. Relying on the system to read data to you in a timely fashion by spreading the file accessors all over the place is simply not sane.

It would be better if it could all be done implicitly. But it can't obviously. So you're kinda fucked.

It's just another programming misstep. Just like OOP. Though RAII has far less negative consequences.
>>
>>58092485

GCC has a cleanup attribute that could be used to simulate RAII :)
>>
>>58092486
>>58092503
That isn't RAII any more than C#'s "using" blocks are RAII.
>>
>>58092476
Pseudocode of what i'm doing currently

void insert(Node root, String word, Entry entry) {
if (entry == null) throw new IllegalArgumentException();
Node node = root;
for (char c : word) node = node.next.getOrCreate(c);
if (node.entry == null) {
node = root;
root.size++;
for (char c : word) { node = node.next.get(c); node.size++; }
}
}


This loops through the word twice.
>>
could anyone link me that site that had all the code for useless projects on it? I'm sorry I can't be more specific as I can barely remember it but I recall there being, for example, a phone number guesser that randomly took a sequence of 11 digits from the decimals of pi and then asked if that was the correct number

there was various other stuff like that, too
>>
>>58092538
http://better-dpt-roll.github.io/
>>
>>58092514
I'd rather not have to catch exceptions, free the resources of that frame, then rethrow manually. I'm already deciding when my shit is going to be freed, I just don't have to supply the intricate details myself.

Can you give some actual reasoning why it's "faulty"? I can't see how RAII could possibly waste time.
>>
>>58092497
>My code is
>a%2 & b%2
In this case, it is wrong.

average<int>(-3, -6) yields -4 and average<int>(3, 6) yields 4.

Should be -3 and 4.
>>
>>58092504
Never quite understood the Rust / SJW association.
>>
>>58092573
It's because it's a Mozilla project so you get a little more political correctness thrown around in the GitHub issues. Does it actually affect anything? Of course not.
>>
>>58092497
>If a and b are both odd, then they should have the same value. Meaning a%2 == b%2, and when that's guaranteed for a%2 & b%2 to have a int value of 1
That's wrong.

In one's complement, for a 16-bit int, both 0x0000 and 0xffff represent 0

This means that if the result of {a,b} % 2 is 0 and represented by 0xffff, then your calculation will be wrong.
>>
>>58092573
This:
https://github.com/rust-lang/rust/pull/25640

Among other examples. If I recall, the guy with the eggplant got banned from GitHub entirely due to the uproar the Rust community created over it.
>>
>>58092509
No, I'm talking about this: https://docs.python.org/2/c-api/refcounting.html
>>
File: anal beads.png (74KB, 727x1051px) Image search: [Google]
anal beads.png
74KB, 727x1051px
>>58092602
>>
>>58092614
>Philosophers must be wise asians
Isn't that kinda stereotypic aka racist?
>>
>>58092602
Banned from Github?
>>
>>58092635
It was Node.JS

https://archive.is/7b1iG
>>
>>58092553
>exceptions
Well naturally you should never have exceptions in flight.
Anyone who can avoid them should. They're one of the false reasons to use RAII.
>I can't see how RAII wastes time
Well any time you write a constructor/destructor is an example.
It'd be hard to see when you're in an environment that relies heavily on RAII or OOP how you can live without constructors and destructors but they really do waste a lot of time and I'm my opinion convolutes the code. But if you imagined that every time you declare a type you don't need to implement a bunch of stuff just for the sake of it and you just start using the type. Sometimes you do need initialization for a type. And you write your small init function. And sometimes your data is a container of some sort that need special care for deallcoation. That's when destructors are appropriate.
But not in general. You have so many situations where you don't need that stuff that it really adds up. And it'd be hard to appreciate without measuring. But I certainly feel much more productive when I don't do that stuff compulsively. And I don't have more bugs because I spend that time on my actual problems.

I'm sorry it's hard to be giving good examples. It's not a small topic.
>>
File: 16.jpg (48KB, 640x480px) Image search: [Google]
16.jpg
48KB, 640x480px
>>58091373
why is every 'dpt' thread image an anime girl?
do you ever use bulma? she's technology
>>
>>58092650
Exceptions are quite performant when used well.
>>
>>58092614
I'm fine with them writing that but changing it is certainly petty.

But I'd secretly like to pretend every smart person is a woman because the idea is attractive to me. Even if it's not the case.
So I'm odd.
>>
>>58092666
>exceptions are great!
t. satan
>>
>>58092661
She doesn't program.
>>
>>58092676
I'm not Satan
>>
>>58092681
you sure? i thought she invented and programmed things herself
I only watched endless eight, I don't know much about OP girl, does she program?
>>
File: 1479458265883.png (133KB, 525x585px) Image search: [Google]
1479458265883.png
133KB, 525x585px
>>58092686
that's exactly what satan would say
>thinking you could fool me like that
>>
>>58092650
>Well naturally you should never have exceptions in flight.
Nice meme. The only thing exceptions do is make executable size marginally larger, as long as they're only used for truly exceptional reasons (e.g. not because an optional data file is missing). That said, RAII is still incredibly useful when you use CPS error handling or anything with CPS, really.

>the second paragraph
Like I said earlier, you don't actually have to write constructors and destructors if you don't need them. If an aggregate type has fields of types that have destructors, a destructor will essentially be automatically generated for that type that calls the destructors on the necessary fields. In a decent language, instead of a constructor, you simply initialize the struct (assuming there's no other invariants).

It's only if you're implementing something that owns an unmanaged resource or has invariants it needs to preserve that you need to write constructors/destructors that actually do anything. Though I don't see how non-RAII languages do it better, you have functions that act as constructors and functions that act as destructors and you have to write more code to ensure the "destructors" are actually called.
>>
>>58092556
By what measure should -3 and -6 become -3?

Integer average rounds towards zero.
eg:
-3 + -6 = -9
-9 / 2 = -4.5
rounded to zero = -4
>>
>>58092666
Anon really please. Exceptions are terrible.
And your exceptional code should not be concerned a performance critical part of your program and if it were exceptions simply aren't good enough.
Andrei Alexandrescu has a talk on systematic error handling. About half way through he talks about exceptions. It's worth a look.
>satan
Aahhh. Almost had me there.
>>
>>58092720
Andrei hasn't even heard of Either or ExceptT yet he attacks Haskell by saying Maybe isn't enough in that talk.
>>
>>58092720
how to catch all exceptions in python

try:
#code
except:
#error
>>
man I want to get really good

but the road is long

one step at a time
>>
>>58092730
He thinks it's not enough. But he clearly goes in that direction.
Doesn't mean he's wrong in the talk it just means he's wrong about maybe.
And I only referenced his complaints about exceptions.
>>58092734
And what was the point of them then? Why catch all of them? That should clearly just be a crash because you don't know the state of your program if you don't handle them.
>>
>>58092738
Hello Pajeet
>>
Are OOP users so far gone that they believe:
>The canonical example of dependency injection I've seen is when it comes to logging shit, instead of putting a bunch of printfs in your code you pass some kind of logger as a parameter so that you can easily change where all the logged text goes later just by changing the line that passes the logger to begin with.
is a "design pattern"?
>>
>>58092772
Who are you quoting?
Genuinely curious.
>>
>>58092784
An AGDG fag.
>>
File: lobster-019.jpg (95KB, 1300x754px) Image search: [Google]
lobster-019.jpg
95KB, 1300x754px
>>58092738
A lobster, when left high and dry among the rock, does not have the sense enough to work his way back to the sea, but waits for the sea to come to him.

If it does not come, he remains where he is and dies, although the slightest effort would enable him to reach the waves, which are perhaps within a yard of him.

The world is full of human lobsters.

People stranded on the rocks of indecision and procrastination, who, instead of putting forth their own energies, are waiting for some grand billow of good fortune to set them afloat.
>>
>>58092752
But that's exactly the point, he hasn't heard of Either or Except. His issue with Maybe is resolved by using Either or Except.
>>
>>58092772
just use the writer monad
>>
>>58092809
Obviously, but in the end that's still just applying arguments to functions which I really hope is not and never will be considered a design pattern.
>>
>>58092796
Ok. So? It's a lack or knowledge not a problem with the talk itself. Also, iirc it was fairly long ago. Was that stuff in?
>>
lobste.rs > /r/programming > news.ycombinator.com
>>
>>58092772
I would say that a globally accessible logging class that has guaranteed contracts on its usage, while being able to change the underlying behavior is a pretty damn good example of a Singleton done right.
>>
>>58092818
A lack of knowledge isn't a problem with the talk?

>X is great but if only there were some kind of Y
>unfortunately ___this doesn't exist___ so here's a shitty OOP alternative
>>
I'm fighting APScheduler
I have about 200 small tasks (~1-5s) that have to be run every 15, 30 or 60 seconds.
It doesn't really matter when they are run, as long as they have regular intervals.
There are plenty of worker threads available to handle it, but I need to find a way to spread them out evenly.
>>
>>58092825
it's just basic indirection though
there's nothing uniquely OOP about that
>>
>>58092825
>globally accessible
Now you've locked yourself to a single log unless you want the singleton to actually be responsible for multiple logs and have every logging invocation choose which log to write to.
>>
>>58092825
>singleton
Why? It gives you nothing here.
Atleast have a global scope function that returns a logger reference. So you can swap it out at runtime if you so choose.
>>
>>58092834
A "Singleton" is certainly one of many OOP design patterns.

Sure, the concept is not "uniquely" OOP, and no one is claiming that it is.

The fact that you're assuming that anything with the OOP "label" must not have any other analogous counterpart in any other paradigm is quite telling; almost as if you're part of some cult that hates anything that might be considered OOP, so you feel the need to try to refute that anything you may use has anything to do with OOP.

>>58092835
Well, that would be part of the definition for the logger. If you want to write to multiple places simultaneously, you could easily change that behavior without any other code knowing the difference.

If you want to add functionality to change the location of the logs, or type of logs, or anything of that nature, you can add optional parameters or default publicly-settable properties to the calling statements without requiring that anyone know about the new options.
>>
how do you write a function that returns the sum of two integers /dpt/?
>>
>>58092867
Just pass the fucking log in, no need to complicate matters for no benefit.
>>
hey, some years ago I was playing around with python perl and php but only really got the basics down, never really dedicating myself to a language.
what would be a good first language to go all in for? book recommendations appreciated.
>>
>>58092872
in Haskell this is just (+)
>>
>>58092872
Who gets to decide what the integers are?
>>
>>58092867
>>58092874
Also what >>58092834 is referencing is the original concept of just passing the log in which was called a design pattern. He wasn't talking about your singleton bullshit.
>>
>>58092872
 
long long sum(int a, int b)
{
return a+b;
}
>>
This is probably a long shot, but i've googled and it didn't really help. I'm trying to find the image path of an OLE object data type in a MS ACCESS database. When I export it to csv, the field is blank. Text and integer types show up just fine. Is there anyway I can see what image path it's "pointing" to for each record? Quite desperate at the moment because there's thousands of these images and to do this manually would take years.
>>
>>58092872
python
sum = lambda x,y:x+y

calling
sum(8,8)

prints
16
>>
>>58092905
>>58092914
why so verbose?
>>
>>58091448
>cross-compile
>suffering
Yup.
>>
>>58092924
what do you mean?
>>
>>58092872
DWORD sum(tuple<int, int> parameter) {
return get<0>(parameter) + get<1>(parameter);
}


call it like this
sum(make_pair<int, int>(1, 3));


don't forget to include Windows.h
>>
>>58092930
in ML languages >>58092887
>>
>>58092943
>haskell its just +
>calling hundreds of lines in the back to do the same


k
>>
>>58092614
>removing link to the paper.
some priorities they have.
>>
File: 1472763822766.png (633KB, 688x997px) Image search: [Google]
1472763822766.png
633KB, 688x997px
>>58092943
>meta language languages
>>
>>58092960
Because now they're not using the example (forks and spaghetti) from it? Learn to read.

It does make more sense for them to have chopsticks because you can't eat with only one chopstick and I don't see how two forks could possibly help with eating spaghetti.
>>
>>58092957
Can you think of an original comment please?
You've given this same response before as to why your language is shit but it's ok somehow.

Except, wait, (+) on unboxed ints doesn't call hundreds of lines of code!
>>
What's the point of singletons?

If you only want one object, just create one object.
>>
>>58092991
long long sum(int a, int b) 
{
return a+b;
}

and
sum = lambda x,y:x+y


it's not verbose.

just because haskell does that with +, doesn't mean that other languages that use a simple sum function are verbose

kys
>>
>>58093018
Singletons are a hack to implement global variables and scopes in classical OOP IN LOO languages.
>>
>>58093025
>it's not verbose
yes it is
every time you want to pass (+) as an argument to a function you have to rewrite all of that, same for every other operator
>>
File: 1350594293765.jpg (111KB, 500x500px) Image search: [Google]
1350594293765.jpg
111KB, 500x500px
Does anyone has any idea on how you print a multiplication of two numbers on this shit https://schweigi.github.io/assembler-simulator/?
>>
File: 1480742279855.png (339KB, 500x500px) Image search: [Google]
1480742279855.png
339KB, 500x500px
Thinking of writing a Game Boy emulator in Java as a portfolio project, but I've never written an emulator before.

How hard is it?
>>
>>58093057
https://schweigi.github.io/assembler-simulator/instruction-set.html
>>
>>58093018
Well really if you only have one of something you shouldn't even make a class for it because there's no duplication to worry about.
>>
>>58093057
move first number into eax
move second number into edx
mul instruction
convert result in edx:eax to a string
print it to screen like it prints hello world
>>
>>58093053
>yes it is
No its not.
>>
>>58093067
Java is horrible, pick a different language
>>
>>58093067
>running a virtual machine in a virtual machine
Start by not using Java.
>>
>>58093067
write it in a real language like haskell
>>
>>58091951
private async void Button_Click(object sender, RoutedEventArgs e)
{
string car;
string price;
string link;
wantToAbort = false;


// ----Simulating GET request for website scraping, this part works----


//-----End Simulating GET----

myList.ItemsSource = myClients;
string searchCar = txtBlock.Text + " " + txtBlock2.Text;


var articleNodes = htmlDoc.DocumentNode.SelectNodes($"//*[@id='main_content']/div[1]/div[2]/ul[1]//*[text()[contains(., '{searchCar}')]]");

while (articleNodes != null && articleNodes.Any())
{

if (wantToAbort)
{
return;
}

foreach (var articleNode in articleNodes)
{
car = WebUtility.HtmlDecode(articleNode.InnerText);
price = WebUtility.HtmlDecode(articleNode.ParentNode.ParentNode.SelectSingleNode("span").InnerText);
link = WebUtility.HtmlDecode(articleNode.ParentNode.ParentNode.Attributes["href"].Value);
myClients.Insert(0, new User(car, price, link)); //inserts new item on top of ObservableCollection
}
await Task.Delay(10000) ;
}
}}


I added a new Button called STOP, which just changes the bool value of wantToAbort to true

Is this the correct way to do this? Everything works but this is the first time i'm doing something with Threads
>>
>>58092905

Or, if you prefer not to have demons in your nostrils:

long long sum (int a, int b)
{
return (long long) a + (long long) b;
}
>>
>>58093073
I still can't figure out how to do it after reading it like 10 times.

>>58093081
How you convert it to string? That's what I have been trying but I just can't figure it out.
>>
>>58093171
split it into digits and add the character '0'
>>
>>58093079
Contracts.
>>
>>58093171
>>58093189
e.g.

repeat this n times
'0' + (number & 1) -> this

number >>= 1

and you get the (reversed) string
>>
>>58093193
Unnecessary because nothing uses the system, it's all inline. Unless you mean to include assertions and types under that umbrella, in which case you still don't need to tear it out.
>>
>>58093141
The main issue I see is that you're potentially having the user wait for 10 seconds for nothing if they abort after the check in the while loop, but this shouldn't matter as long as it is non-blocking for anything you're doing.

Why not do the
wantToAbort
in the while statement? If you put it there first, the false will short-circuit the check, preventing the unnecessary checks to
articleNodes
.
>>
>>58093067
It doesn't look too difficult but it's a lot of work to get it all right.
Look for the gameboy CPU manual. It's a good resource.

Also I wouldn't aim to make it perfect. Just make it work most of the time and that's good enough.
>>
>>58093153
Why would this be necessary?
>>
what should i name the function that does all the work of finding all the pairs of sums in a list that are divisible by a certain number?
>>
>>58091373
Writing a Python script to write a header file. Kill me.
>>
>>58092911

n-nobody? h-halp
>>
>>58093266
Would it be easier to write a chip-8 emulator instead?

Had considered it, but as I have no experience using chip-8, thought GB might be a bit more familiar
>>
>>58093382
I told you that it's a fucking pain.

I told you that.

You didn't listen. You never listened
>>
>>58093245
but
wantToAbort
is in while statement?
>>
Pretty much everything I've worked on up to this point have just been specialized tools without a lot of framework. I'm starting on a larger project now and I want to plan it out before I start. Is there any software that can help?
>>
>>58093422
while (!wantToAbort && articleNodes != null && articleNodes.Any())
>>
>>58093382
but why?

what's the purpose?
>>
>>58093433
microsoft word
>>
>>58093382
Anon you really should look into writing something that makes that easier if it's such a pain.
>>
>>58093433
Wikidpad.
>>
>solve problem on hackerrank with haskell
>3 lines of code, one of them is the type annotation
>same solution but in java:
        for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
}
for(int a_i=0; a_i < n-1; a_i++){
for(int a_j=a_i+1; a_j< n; a_j++){
if( (a[a_i]+a[a_j])%k==0)
cnt++;

}
}
System.out.println(cnt);
>>
>>58093456
I need to generate a bunch of constants at compile-time and this is the best way I can think of doing it. The Python script will compute them and save them in a global constexpr array.
>>
>>58093442
Oh shit, i'm retarded
>>
>>58093382
def root_mask(sq: int):


what? can python take arguments like this?
>>
What are some entry level programming jobs I can possibly get before graduating? I need something to replace my min wage part time stocker at a warehouse job.
>>
>>58093517
It's just a type annotation. I'm saying that sq should be an int.
>>
>>58093525
that only works in python 3?
>>
>>58093478
That looks interesting. I wonder if you can incorporate it with existing program documentation frameworks.
>>
>>58093525
def foo(a: int):
return a+10


i can call it like
foo(8.0)


and doesn't give errors. what gives?
>>
How to merge this two rules into one?
||youtube.com/pewdiepie$document
||youtube.com/*/pewdiepie$document
>>
>>58093532
Probably can do that quite well given it does html to some degree.

But I think its more appropriate organising notes or thoughts in general than documentation.
You can link to documentation in it or include bits of documentation using iframes.
Would be a good idea to install a proper viewer then. The preview feature doesn't do html by default.

It's nice to write in though.
>>
>>58093530
Yes.

>>58093544
It's not enforced by the interpreter. It's mostly useful so that devs reading your code know what type they should pass. It also helps your IDE do auto completion. Not super useful desu but I use it whenever a function parameter can really only accept one type.
>>
>>58093553
?
http://regular-expressions.mobi/optional.html
>>
>>58093581
interesting.

thanks
>>
i'll own all these haskell niggers off this site
>>
>>58093212
Thanks anon, I got it.
>>
>>58093586
||youtube.com/(*/)?pewdiepie$document
?
>>
the better you get at Java, the larger projects you write ...

... the more you realize how much of a forced pile of shit it actually is.
>>
>>58093687
fuk u java runs the world what the FUCK do u do????/
>>
Are there any interesting data sets for me to use for my 'stock' trading game? I need data that changes rapidly. I was thinking on count all words on 4chan as stock, but that doesn't sound much fun. Any other suggestions? Should I stop being autistic and use actual stock data?
>>
File: performance_lanugages.png (54KB, 1344x770px) Image search: [Google]
performance_lanugages.png
54KB, 1344x770px
java master race
>>
>>58091819
you're the first!
>>
File: leluezs2.jpg (84KB, 508x409px) Image search: [Google]
leluezs2.jpg
84KB, 508x409px
>>58093765

>Python gets slower with each release
>>
>>58093765
*Java meme race
>>
>>58093765

>this triggers the c and c with classes cucks
>>
>>58093765
If Java is so fast then why it's VM is so slow and clunky?
>>
>>58093807
Well there's nothing surprising there. You can JIT in C and get the same result.
It's just an advantage or JIT.
>>
>>58093807
JIT compilers are the future of standalone languages. I can admit this as a C (and LuaJIT) fanatic. However, C and C++ won't die for a long time. OS and library development are dependent upon it.
>>
How cool is this?

http://geoff.greer.fm/vim/#realwaitforchar
>>
How do I implement a function that returns a boolean, and, in case it returns true, performs another action?
>>
>>58093765
so whats it actually testing?
>>
>>58093834
>>58093843
This is why my language is going to have a strong module system (like OCaml's) with support for hotloading and JIT.
>>
>>58093859
http://blog.carlesmateo.com/2014/10/13/performance-of-several-languages/
>>
>>58093871
>my language

autism
>>
>>58093843
>JIT is the future
I disagree.
Anything that's JIT is suboptimal. You might have standalone languages with built in JIT to some extent. Like you'd tell the compiler to JIT a certain part of the program (and with that comes the vagueness you require to do JIT well).
That's a use for JIT. For sections where the programmer explicitly doesn't care.
>>58093871
Stop pushing your stupid bullshit.
>>
>>58093859
It's a highly bias test obviously. Nobody who looks at that can think otherwise.
>>
>>58093871
It better have a C FFI.

>>58093889
>Anything that's JIT is suboptimal
Actually, JITing is theoretically (and actually in some cases, see a few replies up) more optimal than AOT compiling.
>>
>>58093852
in Haskell this is just
timeout msecs getChar
>>
>>58093910
see >>58093874
>>
>>58093923
k
>>
is it considered good coding style to split everything into methods/functions as small as possible?

e.g., make sure there are no ultra-complex methods/functions?
>>
>>58093889
It's mostly for hotloading but support for JIT goes along with that. Also JIT can be better than AoC, though I would never use it for the whole program. You also better not be assuming that by "JIT" I mean "interpreted but JITted sometimes", because I certainly don't.

>>58093921
>It better have a C FFI.
Obviously.
>>
>>58093937
if you're writing haskell
>>
>>58093937
You don't want to do that for its own sake, but rather you want to split things up to reduce duplication as much as possible and to separate responsibilities as much as possible.
>>
>>58093937
Not really. There's a chapter in Code Complete on exactly this, and it seems the tipping point, bug wise, is about ~200 lines in a routine max, and ~20 lines minimum.
>>
File: Screenshot - 201216 - 19:00:30.png (50KB, 500x720px) Image search: [Google]
Screenshot - 201216 - 19:00:30.png
50KB, 500x720px
>>58093937
yes

its good practice
>>
>>58093765
>faster than assembly
lol
>>
>>58093921
>JIT is theoretically more optimal
No that's not true.
If you write your code to account for the runtime circumstances that the JIT does then you obviously don't have to do the operations the JIT does to come to those conclusions.

It's really just profile guided optimization at runtime, but profile guided optimization tends to be fairly weak nowadays.

The problem with JIT languages is the mentality you show here. They prefer the JIT over the programmer. Which in most cases where you have decent programmers simply isn't wise.
>>
>>58093141
>>58093245
>>58093442

I had to change program a bit. My html GET was outside any loop so i was checking the same portion of the site every N seconds, which does nothing now it's something like this

private async void Button_Click(object sender, RoutedEventArgs e)
{
string car;
string price;
string link;
wantToAbort = false;


while (!wantToAbort)
{
// ----Simulating GET request for website scraping, this part works----

//-----End Simulating GET----

myList.ItemsSource = myClients;
string searchCar = txtBlock.Text + " " + txtBlock2.Text;


var articleNodes = htmlDoc.DocumentNode.SelectNodes($"//*[@id='main_content']/div[1]/div[2]/ul[1]//*[text()[contains(., '{searchCar}')]]");

if (articleNodes != null && articleNodes.Any())
{
foreach (var articleNode in articleNodes)
{
car = WebUtility.HtmlDecode(articleNode.InnerText);
price = WebUtility.HtmlDecode(articleNode.ParentNode.ParentNode.SelectSingleNode("span").InnerText);
link = WebUtility.HtmlDecode(articleNode.ParentNode.ParentNode.Attributes["href"].Value);
myClients.Insert(0, new User(car, price, link)); //inserts new item on top of ObservableCollection
}
await Task.Delay(10000) ;
}
}}
}


Shit works.

I'm wondering, is there a way to check whether the last item in ObservableCollections is the same as the item last entered, and if it is, it's discarded?
>>
the worst thing about c++ is how horrible the compiler error messages are.
>>
>>58093924
>see
Yeah. I did. Before I wrote that. I don't see how you could read that link and understand it and say its not bias.
Maybe you didn't read it or you didn't understand it?
>>
>>58093991
retard

see >>58093874
>>
After a method returns a value, it is over, amirite?
No further code is executed.
>>
>>58094033
No.

The code that follows the return statement, it will be executed at least 3 times.
>>
>>58094033
Yes. A return is the end of a function.
>>
>>58094021
yeah, no. there's nothing faster than assembly besides physically making better hardware
retard
>>
>>58093654
Doesn't work.
>>
>>58091373
I actually don't like that image, I feel the original just has such a dymamic feel to it, that it loses when you flatten it out
>>
>>58094071
Languages aren't fast or slow, implementations are.

retard
>>
>>58094097
It is definitely a shitty image
>>
>>58091513
Why did you bring spaghetti to an interview?
Did you have your lunch in your bag?
>>
>>58094097
thank you for letting us know
>>
File: pokerstats.png (386KB, 708x593px) Image search: [Google]
pokerstats.png
386KB, 708x593px
Building a poker HUD for puzzle pirates. Successfully calculating VPIP, PFR, and AF!
>>
>>58094104
what's the point of a comparison graph if the implementations aren't the same?
full retard
don't reply anymore, you're embarrassing yourself
>>
File: 1427325174842.png (98KB, 430x180px) Image search: [Google]
1427325174842.png
98KB, 430x180px
>>58094118
>>
>>58094004
Just compare it to the element you want to compare against.

Maybe something like:
var tempUser = new User(car, price, link);
if (!myClients.First().Equals(tempUser)) // insert new user


or even

if (!myClients.Any(x => x.Equals(tempUser))) // insert

which would search the whole list for any one that matches, using the definition for Equals()

You might have to implement/override .Equals() on your User class.
>>
How comes complete retards get so much money and why do I have to work for them to feed myself?
>>
>>58094001
>If you write your code to account for the runtime circumstances that the JIT doe
But how do you know what architecture you'll be running on? JIT can compile your code to use all available features on the CPU it's running on, and not just a safe subset.
>>
>>58094144
because you're not like them.
>>
Haskell should be illegal
>>
>>58093874
so java runs faster because it unrolls the inner loop, and the rest dont.
>>
What are your honest tips on concurrent programming?
>>
>>58094203
It depends on the language, you stupid ass.
>>
>>58094203
avoid shared mutable state as much as possible. Strive to be functional.
>>
>>58094185
>so java runs faster because
it's a contrived example.
>>
>>58094229
>nobody would ever nest a for loop in real code!
>>
>>58093502
>implying loc matters
for(int a_i=0; a_i < n; a_i++){a[a_i] = in.nextInt()}for(int a_i=0; a_i < n-1; a_i++){for(int a_j=a_i+1; a_j< n; a_j++){if( (a[a_i]+a[a_j])%k==0)cnt++;}}System.out.println(cnt);

3 times less loc than Haskell now :^)
>>
>>58094203
This >>58094221, and use an API like futures on top of a work stealing thread pool.
>>
>>58094238
How about I nest my fat hog four and a half inches deep up your fudgehole big boy?
>>
File: Practical_Language_Comparison.jpg (2MB, 2100x1400px) Image search: [Google]
Practical_Language_Comparison.jpg
2MB, 2100x1400px
I'm not a programmer but I'm looking to learn. How accurate is pic related? and what the fuck is the haskell one supposed to mean? [spoiler]please don't fight[/spoiler]
>>
>>58094253
It's completely biased, made by a Java faggot.
>>
>>58094238
It's a dead loop anon. Are you blind?
    for (i_loop1 = 0; i_loop1 < 10; i_loop1++) {
for (i_loop2 = 0; i_loop2 < 32000; i_loop2++) {
for (i_loop3 = 0; i_loop3 < 32000; i_loop3++) {
i_counter++;

if (i_counter > 50) {
i_counter = 0;
}
}
// If you want to test how the compiler optimizes that, remove the comment
//i_counter = 0;
}
}

The reason it's a contrived example in favor of JIT is because it's dead code made undead.

If this was an iterative process of some form that uses nested loops I doubt the JIT could 'fix' it.

I suspect the reason the author chose this example primarily is that he can't really win using Java unless he makes this dead code example.
>>
>>58094253
>what's this supposed to mean
Nothing. It's stupid.
>not a programmer
Just pick a language.
>>
>>58094253
completely retarded, start leaning with C so you know what the fuck is happening with every language you will learn after that
>>
>>58094140
This works wonderfully but it fails when first populating the ObsCollection, as it doesn't have the .First object to comapre it to
>>
>>58094253
start with racket
>>
>>58094274
better to just use a pure language
>>
>>58094298
>pure language
What do you mean by this?
>>
File: java-vs-haskell.png (102KB, 2435x913px) Image search: [Google]
java-vs-haskell.png
102KB, 2435x913px
wish the javafags would fuck off back to india or their freshman intro to comp sci class they just finished or w/e they came from
>>
>>58094253
>and what the fuck is the haskell one supposed to mean?
The end result is mythical because Haskell is a toy language focused on fancy mathematical theories that don't actually put up a shelf.
>>
>>58094283
should I learn it with the book "The C programming language"?
>>
>>58094309
I meant Haskell
>>
Im turning my old computer in a temporary server and I want to run tomcat on it for some various stuff. is there a single reason not to keep win10 on it for this? or let me turn this around: why should I run linux for this?
>>
>>58094337
>the C programming language
It's for programmers who looked to move to C back when pascal was popular.
Find some other way.
Find something that interests you and learn through something working towards that.
For me I should probably have started with arduino if that was around back then.
>>
File: Programming Shelves.png (952KB, 2100x1400px) Image search: [Google]
Programming Shelves.png
952KB, 2100x1400px
>>58094253
>using the outdated version
>>
>>58094290
Use
.FirstOrDefault()
>>
>>58094253
Not very accurate at all. The basic meaning of the pic is as such
>assembly you need to do a lot of stuff only to fuck up
>same with C but less
>same with c++ but even less
>Java gives you exactly what you need and gets the job done
>python is lazy and end result is a stripped down Java
>Haskell has a of math but development is imaginary because noone uses it
If I had to choose the bottom ones.
C/C++ would be a Ferrari, pretty fast until you hit a pole you dumb fuck
Assembly is pretty much a car made up of multiple other cars, but still fine tuned for speed
Java is a Toyota Sienna. You can definitely put as many wetbacks and pajeets in the back as you want
Python is a tricycle with nos in the back
Haskell is still a unicorn.
>>
>>58094290
>>58094373
You might have to do something like:
if (!myClients.FirstOrDefault()?.Equals(tempUser) != null) // insert new user
>>
>>58094104
An assembly loop would literally be implemented something along the lines of

label:
jmp label


How could a Java or C loop be faster than that?
>>
>>58091819
>using % 2
>modulo 2
>modulo
>two

fuck this gay earth
>>
>>58094411
Unrolling.
>>
>>58094433
Well??????????
What's the alternative. Because signed integers cannot guarantee that a & b & 1 will work as the implementation of signed integers are compiler defined.
>>
>>58094411
strongly depends on what you want to achieve with that loop, newfriendo
>>58094447
>>
>>58094447
You can do that in any decent assembler using a REPEAT directive.
>>
>>58094361
>why should I run linux for this?
A lot of server stuff on windows is catered around windows server edition. Especially if you don't have a pro or ultimate edition.
Linux (regardless of distribution pretty much) is very well adapted to being server stuff. Lots of people use Linux for dedicated servers so there's more helpful information on how to interconnect things.

In my experience windows as a server environment is OK if you're doing the very very basic shit that has near explicit support built into it in the OS or you're using something like filezilla server. Beyond that there's a mess to dive into. Tons of different server applications rely on different frameworks for windows which you have to install manually and set up on their own. The process is usually done through GUI and you really have to hope your windows version is the right language (even GB/US matters) to not be confused. Versioning often makes it convoluted even when everything matches up.

On Linux you have a much cleaner view but you often find that people expect more of you. Things like understanding that you need to set certain files as executable when it complains about permissions etc etc.
But Linux forums in general tend to be very helpful. Even /flgt/ are helpful despite their very nasty appearance.

Ask more there though. This is not so much a /dpt/ question.
>>
File: snow.gif (2MB, 477x270px) Image search: [Google]
snow.gif
2MB, 477x270px
>>58094457
(You)
>>
>>58094461
Yeah well that's not what was posted.
>>
>>58093988
You're being sarcastic, I hope.
>>
>>58094484
So it's testing non-equivalent code? What's the point? Might as well have a graph comparing adding a bunch of numbers in C versus software rendering 2 billion cubes in JavaScript.
>>
>>58094481
nod an argument
>>
>>58094530
>How could a Java or C loop be faster than that?
That was the question that was asked and I answered it.
>>
>>58094530
Now you understand why arguing about any programming language benchmarks is completely unproductive.
>>
name three programming languages
>>
>>58094557
C
Pascal
Jackie Chan
>>
>>58094471
>This is not so much a /dpt/ question.
but it is for me. I just want to run tomcat so I can work on my servlet. Im just interested what the upside would be on running the tomcat on linux than windows.

>>58094557
html, css, erlang
>>
>>58094557
Lisp
>>
>>58094546
That was an answer, that was changing the nature of the question.
>>
>>58094551
>Now you understand why arguing about any programming language benchmarks is completely unproductive.
No it's not really that. It's that the programming benchmarks are usually these stupid examples. Not complete replicated software written to similar degrees of programmer facing complexity.

That way we'd get some measure of performance/effort.

And of course this would be a major effort just to get the benchmark done.

The performance differences between approaches are fairly obvious for any mediocre to good programmer.
>>
>>58094253
>Javafags actually believe this
>>
>>58094557
C
Brainfuck
Your mom
>>
>>58094585
What? I answered the question in >>58094411 which is about a potentially sub-optimal loop implementation in Assembly.
>>
>>58094585
A, B, and jackie Chan
shit
>>
>>58094557
C#
F#
C
>>
>>58094407
this works, but the program isn't finding any cars from the site

it stands like this now

                        var tempUser = new User(car, price, link);
if (!myClients.FirstOrDefault()?.Equals(tempUser) != null)
{
myClients.Insert(0, new User(car, price, link));}
>>
>>58094585
C
C++
C#
>>
>>58094580
Well I'd say stick with windows then. if you ever run into a situation where you're having issues that's on the OS front move to Linux, maybe your issue is solved there.

Sounds to me like it doesn't matter for you at all.
>>
>>58094633
>but the program isn't finding any cars from the site
What do you mean? It's still inserting duplicates? Keep in mind that is literally only checking to see if the object at index [0] is the same as tempUser.

I'd have to see your code, but you may be better served by .Any()
>>
>>58094574
3/3

>>58094580
3/3

>>58094582
3/3

>>58094601
3/3

>>58094621
2/3 see me after class
>>
I'm trying to get a junit test working, but I can't get assertEquals to work at all.

What I know is that when I put assertEquals the previous line magically gets a syntax error asking for a "}" and that it claims the assertEquals is missing the ";"

That, and all the examples want an import of org.junit... but I can't do that.
>>
File: 1476457397818.jpg (17KB, 233x217px) Image search: [Google]
1476457397818.jpg
17KB, 233x217px
>>58094699
look harder, faggot
>>
>>58094677

It's not inserting anything, ObsCollection is empty and it stays empty even though i checked the site and there are cars that should be in the list

my code

private async void Button_Click(object sender, RoutedEventArgs e)
{
string car;
string price;
string link;
wantToAbort = false;


while (!wantToAbort)
{
// ----Simulating GET request for website scraping, this part works----

//-----End Simulating GET----

myList.ItemsSource = myClients;
string searchCar = txtBlock.Text + " " + txtBlock2.Text;


var articleNodes = htmlDoc.DocumentNode.SelectNodes($"//*[@id='main_content']/div[1]/div[2]/ul[1]//*[text()[contains(., '{searchCar}')]]");

if (articleNodes != null && articleNodes.Any())
{
foreach (var articleNode in articleNodes)
{
car = WebUtility.HtmlDecode(articleNode.InnerText);
price = WebUtility.HtmlDecode(articleNode.ParentNode.ParentNode.SelectSingleNode("span").InnerText);
link = WebUtility.HtmlDecode(articleNode.ParentNode.ParentNode.Attributes["href"].Value);
var tempUser = new User(car, price, link);
if (!myClients.FirstOrDefault()?.Equals(tempUser) != null)
{
myClients.Insert(0, new User(car, price, link));}//i sense this is wrong, i should enter tempUser
}
await Task.Delay(10000) ;
}
}}
}
>>
>>58094699

because you stuck code in the middle of nowhere perhaps? try putting it in a test method, dumbo
>>
>>58094752
formatting is all fucked because i edited it in /g/...
>>
>>58094752

print out articleNodes to see if your xpath is correct
>>
NEW THREAD!

>>58094819
>>
>>58094809
Oh, it is correct, it works perfectly before that

                        var tempUser = new User(car, price, link);
if (!myClients.FirstOrDefault()?.Equals(tempUser) != null)
{
myClients.Insert(0, new User(car, price, link));}


If i leave it only with
myClients.Insert(0, new User(car, price, link));
it works perfectly but it repeats search results after N sec, which i want to solve
>>
>>58094752
Use Any()

if (!myClients.Any(x => x.Equals(u)))


The code using the safe navigation operator and comparing the boolean return to null is always going to return false.

Note that you need to define your Equals() method in your User class, or implement a deep-comparison object comparison method to compare all of the properties to each other.
>>
>>58094913
Now it stands like this
                        var tempUser = new User(car, price, link);
if (!myClients.Any(x => x.Equals(tempUser)))
{
myClients.Insert(0, tempUser);
}


Now it inserts new items on top, like before...still not correct
>>
>>58095174
That's because you haven't overridden
.Equals()
to compare car, price, and link.

You cannot use the default implementation; you must define the behavior of
.Equals()
.
>>
>>58095183
There must be an easier way than to define new method?
>>
>>58095213
Do you know what extension methods are?

If not, do some research, because they are really powerful and can make your life easy. I've got a toolbox of extension methods that I bring around with me.

You could declare an extension method like this that would work for any class:
public static bool DeepCompare(this object obj, object another)
{
if (ReferenceEquals(obj, another)) return true;
if ((obj == null) || (another == null)) return false;
//Compare two object's class, return false if they are difference
if (obj.GetType() != another.GetType()) return false;

var result = true;
//Get all properties of obj
//And compare each other
foreach (var property in obj.GetType().GetProperties())
{
var objValue = property.GetValue(obj);
var anotherValue = property.GetValue(another);
if (!objValue.Equals(anotherValue)) result = false;
}

return result;
}


if (!myClients.Any(x => x.DeepCompare(u)))
>>
File: anal beads.png (30KB, 709x797px) Image search: [Google]
anal beads.png
30KB, 709x797px
>>58095213
>>58095309
I did a quick proof of concept to verify that the DeepCompare is going to do what you want. Works like a charm.

Notice the duplicate of the input list was not added.
>>
post memes plz
>>
>>58095309
>2016
>using object instead of a generic type
What a filthy code monkey!
>>
>>58095599
Golang
>>
>>58095731
Better?

public static bool DeepCompare<T>(this T obj, T another)
{
if (ReferenceEquals(obj, another)) return true;
if ((obj == null) || (another == null)) return false;
//Compare two object's class, return false if they are difference
if (obj.GetType() != another.GetType()) return false;

var result = true;
//Get all properties of obj
//And compare each other
foreach (var property in obj.GetType().GetProperties())
{
var objValue = property.GetValue(obj);
var anotherValue = property.GetValue(another);
if (!objValue.Equals(anotherValue)) result = false;
}

return result;
}
>>
>>58095755
Please stop coding filthy code monkey.
>>
>>58095788
No I need to eat food and money is required for this.
Thread posts: 325
Thread images: 26


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.