• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

BeforeU

Oft hope is born when all is forlorn.
I have a Laptop with 4k display, I want to do some java development in Eclipse or NetBeans and none of them scale properly. Like wtf?

in 2016, how is it that these popular IDE does not support 4k display? I thought by now 4K displays will be common. Fucking shame.

What should I use? Any suggestions?
 
Check this stackoverflow question. I think for what you want, the StringBuilder solution is the most suitable one, as the binary string may vary its length (it's not always 7 digit).

Well this got me almost there.

String bin = String.format("%8s", Integer.toBinaryString(ch1)).replace(' ', '0');

Now I am getting 8 numerals with padded zero. I probably won't get the split into 2 sets of 4 though. I probably will lose 2 points out of 100 for it.

Thanks for the link.
 

X05

Upside, inside out he's livin la vida loca, He'll push and pull you down, livin la vida loca
I have a Laptop with 4k display, I want to do some java development in Eclipse or NetBeans and none of them scale properly. Like wtf?

in 2016, how is it that these popular IDE does not support 4k display? I thought by now 4K displays will be common. Fucking shame.

What should I use? Any suggestions?
Use IntelliJ, best IDE around not named Visual Studio.
 

Koren

Member
1001 1100 also all my binaries are 7 digit, which I just realized. Any helpful hints?
Others have replied about adding padding zeroes, but ASCII technically *is* a 7 bits code, not eight.

(but special chars can have less than 7, like space, so it doesn't solve anything)
 

Kansoku

Member
I'm building a search engine with Java for a class. We started with the crawler, in which we use the Wikipedia API to get the pages and it's categories, and we also get the external links and send them to Crawler4J. It uses kinda of a pipeline design; a thread uses the API to get the page and it sends the page info to another thread which writes on the DB and the external links to another thread with Crawler4J (which too sends to the DB thread), and finally it also sends the text striped out of the HTML tags to another thread which puts it into a Solr instance. However, after ~30min or so, an OutOfMemory Exception is raised on the "Solr thread", I imagine due to the long texts in the ConcurrentLinkedQueue. The program don't stop running, I have to do that manually, BUT, no thread does any work. So my question is, is there a way to pause all other threads when that happen, except the Solr thread, which I want to keep running, processing whatever is on the queue until it's empty, so that I can un-pause the other threads?

Well this got me almost there.

String bin = String.format("%8s", Integer.toBinaryString(ch1)).replace(' ', '0');

Now I am getting 8 numerals with padded zero. I probably won't get the split into 2 sets of 4 though. I probably will lose 2 points out of 100 for it.

Thanks for the link.

Just use substring, no? First 4 characters + space + last 4 characters.
 

Prosopon

Member
https://www.codecademy.com/learn/python

Have fun. When you're done, see if you can make a small console (command prompt) game like a text adventure.

Honestly, that's like the most vague of an answer possible. As for what you should do to start, I personally suggest udacity's intro to programming.

Definitely a smorgasbord of stuff, and maybe not exactly what you're looking for, but this has plenty of links to CS lectures. From 101 level stuff up to some advanced topics. Great if you just want exposure to CS.

Thank you I'll check this out.
 
I'm building a search engine with Java for a class. We started with the crawler, in which we use the Wikipedia API to get the pages and it's categories, and we also get the external links and send them to Crawler4J. It uses kinda of a pipeline design; a thread uses the API to get the page and it sends the page info to another thread which writes on the DB and the external links to another thread with Crawler4J (which too sends to the DB thread), and finally it also sends the text striped out of the HTML tags to another thread which puts it into a Solr instance. However, after ~30min or so, an OutOfMemory Exception is raised on the "Solr thread", I imagine due to the long texts in the ConcurrentLinkedQueue. The program don't stop running, I have to do that manually, BUT, no thread does any work. So my question is, is there a way to pause all other threads when that happen, except the Solr thread, which I want to keep running, processing whatever is on the queue until it's empty, so that I can un-pause the other threads?

From your description, it sounds like the Solr thread is taking too long to process each element from the queue, making it too big to fit into memory. The simplest approach would be to just increase the heap size of the JVM. The default size is usually fairly conservative.

If that's not an option, you could have a check in each thread that looks at how much stuff is in the queue for the Solr thread and if it's too much, it waits for a while. One way of doing this would be to have a counter (AtomicLong) shared across all the threads where the thread that fetches the data from the API adds the number of characters the article has and the Solr thread subtracts the number of characters it just processed once it's finished a given workload. That way, the counter should reflect, approximately, how much stuff is in the queue at any given point in time. In the other threads, you check that counter before you start a new workload and if that counter is over some value, you wait until it gets lower. This is not something I've ever had to implement myself and I'm far from an expert on concurrency, but this might help.
 

Two Words

Member
I'm having some trouble helping students understand object-oriented design. I tutor CS at my university, and this is one of the areas where it has been hard to get students to understand. They often want to just make super classes or make their main method do work for them. What often happens is that I'll illustrate a good OOP model to use for their classes. Essentially, I'm giving them an informal UML diagram. They'll buy into it, then have trouble implementing what I've described to them, and regress to making Franken-classes. So, I either have to let them do that or instruct them on how to implement it. But at that point, I'd be essentially doing their project for them. Any suggestions on how to tutor students on how to implement good OO design without actually doing the implementation for them?


I tried using this analogy, but I think it didn't stick with them. Do you think this is a sound analogy? Imagine your program is a cube. Let's just say it's volume is its complexity and its surface area is the amount of code. Let's say we just make a monolithic class. So this one class will be very complex since it contains all of the volume of the cube. Now, let's make this program into multiple classes. So now our program cube will be divided up into something that looks like rubics cube. The total sum of the volume of each cube will be the same as the monolithic cube. This is because the end result of both programs essentially do an equivalent amount of complex tasks as a whole. However, each individual sub-cube has much smaller volume, and hence less complexity. The sum of the surface area of each subcube will be greater than the surface area of the monolithic cube. Hence, the multi-class program will require a lot more code. Or at least, it will require a lot more "prep code". And it's this part that students seem to want to run away from like the plague without realizing how much of a mess the alternative is.

Does this analogy seem to illustrate the point well?
 
I'm having some trouble helping students understand object-oriented design. I tutor CS at my university, and this is one of the areas where it has been hard to get students to understand. They often want to just make super classes or make their main method do work for them. What often happens is that I'll illustrate a good OOP model to use for their classes. Essentially, I'm giving them an informal UML diagram. They'll buy into it, then have trouble implementing what I've described to them, and regress to making Franken-classes. So, I either have to let them do that or instruct them on how to implement it. But at that point, I'd be essentially doing their project for them. Any suggestions on how to tutor students on how to implement good OO design without actually doing the implementation for them?


I tried using this analogy, but I think it didn't stick with them. Do you think this is a sound analogy? Imagine your program is a cube. Let's just say it's volume is its complexity and its surface area is the amount of code. Let's say we just make a monolithic class. So this one class will be very complex since it contains all of the volume of the cube. Now, let's make this program into multiple classes. So now our program cube will be divided up into something that looks like rubics cube. The total sum of the volume of each cube will be the same as the monolithic cube. This is because the end result of both programs essentially do an equivalent amount of complex tasks as a whole. However, each individual sub-cube has much smaller volume, and hence less complexity. The sum of the surface area of each subcube will be greater than the surface area of the monolithic cube. Hence, the multi-class program will require a lot more code. Or at least, it will require a lot more "prep code". And it's this part that students seem to want to run away from like the plague without realizing how much of a mess the alternative is.

Does this analogy seem to illustrate the point well?

emot-iiaca.gif


All this is just IMHO but to be really honest, I think that analogy is quite terrible and no wonder your students are running away from it. It's not about even it being sound or wrong or right, but it's rather complex, long but doesn't really answer the biggest question of "why".

Same with "informal UML diagrams". Even if it's "informal", it's still a UML diagram, a thing that's notoriously hard thing to grasp or use effectively even if the concept behind it should be really simple, right?

How about you try to show them instead: Show them why their mega god classes suck, show cases where their classes will become un-usable or hard to refactor, show them how to improve them. You cannot just except that the magical UMLs "click" at some point and hope that they are then writing class after class of perfect OO code.
 
emot-iiaca.gif


All this is just IMHO but to be really honest, I think that analogy is quite terrible and no wonder your students are running away from it. It's not about even it being sound or wrong or right, but it's rather complex, long but doesn't really answer the biggest question of "why".

Same with "informal UML diagrams". Even if it's "informal", it's still a UML diagram, a thing that's notoriously hard thing to grasp or use effectively even if the concept behind it should be really simple, right?

How about you try to show them instead: Show them why their mega god classes suck, show cases where their classes will become un-usable or hard to refactor, show them how to improve them. You cannot just except that the magical UMLs "click" at some point and hope that they are then writing class after class of perfect OO code.

A million times this. Always hated those textbook examples when I was starting out. For a beginner the hardest part of programming is understanding that half of the work is about organizing your code before writing it, and that's where OOP comes in.


Btw, another entry for the "I evidently suck at making loops" series: I'm working on a 2D array of booleans:
Code:
static boolean[][] lights = new boolean[1000][1000];

for (int i=0;i<=lights[0].length;i++){
                   for(int j=0;i<=lights[1].length;j++){
                       System.out.println(lights[i][j]);
                   }
               }

anytime I try to iterate on it in any way (even just printing the values), I automatically get an ArrayIndexOutOfBoundsException. I don't understand where I'm going out of bounds and how. Reading around it might have to do about how 2D arrays are handled in Java.
 

Kansoku

Member
From your description, it sounds like the Solr thread is taking too long to process each element from the queue, making it too big to fit into memory. The simplest approach would be to just increase the heap size of the JVM. The default size is usually fairly conservative.

If that's not an option, you could have a check in each thread that looks at how much stuff is in the queue for the Solr thread and if it's too much, it waits for a while. One way of doing this would be to have a counter (AtomicLong) shared across all the threads where the thread that fetches the data from the API adds the number of characters the article has and the Solr thread subtracts the number of characters it just processed once it's finished a given workload. That way, the counter should reflect, approximately, how much stuff is in the queue at any given point in time. In the other threads, you check that counter before you start a new workload and if that counter is over some value, you wait until it gets lower. This is not something I've ever had to implement myself and I'm far from an expert on concurrency, but this might help.

Hmm, didn't think of that. It kinda defeat the purpose of separating them, but if it's only once in a while itmight do. Thanks.

Btw, another entry for the "I evidently suck at making loops" series: I'm working on a 2D array of booleans:
Code:
static boolean[][] lights = new boolean[1000][1000];

for (int i=0;i<=lights[0].length;i++){
                   for(int j=0;i<=lights[1].length;j++){
                       System.out.println(lights[i][j]);
                   }
               }

anytime I try to iterate on it in any way (even just printing the values), I automatically get an ArrayIndexOutOfBoundsException. I don't understand where I'm going out of bounds and how. Reading around it might have to do about how 2D arrays are handled in Java.

Change the "<=" to "<". Since arrays start at 0, an array with 1000 elements go from position 0 to position 999. Your for is going from 0 to 1000 however.

I also think I see another problem (unless I misinterpreted what you're trying to do), but I'll let you find that out :p
Hint:
make a non square matrix (like 5x2), and print the lengths you're using on the for.
 

dabig2

Member
Hmm, didn't think of that. It kinda defeat the purpose of separating them, but if it's only once in a while itmight do. Thanks.



Change the "<=" to "<". Since arrays start at 0, an array with 1000 elements go from position 0 to position 999. Your for is going from 0 to 1000 however.

I also think I see another problem (unless I misinterpreted what you're trying to do), but I'll let you find that out :p
Hint:
make a non square matrix (like 5x2), and print the lengths you're using on the for.

All of this and you have a typo in your 2nd for loop. You typed an i instead of a j in your test condition. As it is now, that 2nd for loop won't exit since that condition will always be true as i doesn't increment in that loop. That's probably where the exception is happening as j will increase beyond the limits of your array. But as Kansoku said here, there's a couple other things to look at.
 
ok I had realized that I should have used < instead of <=. The typo, however...is kind of baffling. I guess I didn't have enough coffe today. As it turns out I must have made that typo several times , because fixing it removed the error.
Kansoku about your suggestion,I need to keep track of each and every element in the array, over several iteations. Counting the elements I'm working with is not the point, unfortunately :/
 

Two Words

Member
emot-iiaca.gif


All this is just IMHO but to be really honest, I think that analogy is quite terrible and no wonder your students are running away from it. It's not about even it being sound or wrong or right, but it's rather complex, long but doesn't really answer the biggest question of "why".

Same with "informal UML diagrams". Even if it's "informal", it's still a UML diagram, a thing that's notoriously hard thing to grasp or use effectively even if the concept behind it should be really simple, right?

How about you try to show them instead: Show them why their mega god classes suck, show cases where their classes will become un-usable or hard to refactor, show them how to improve them. You cannot just except that the magical UMLs "click" at some point and hope that they are then writing class after class of perfect OO code.
I did explain why their mega-classes would be bad. I was trying to show them with an informal UML diagram how they can make each class take care of themselves and whenever they need to do something more complex, they have a lot of tools to make objects do work on themselves and whatnot.
 

Somnid

Member
Design skills like not using big classes is something you need to experience, you can tell people all day it's bad but it doesn't sink in until someone hands you a thousand line monstrosity and asks you to fix a small bug and you waste a couple 8 hours days doing it. Toy problems aren't going to cut it and realistically what they are doing isn't necessarily bad, a typical approach should be naive and refactored as more is added. The skill comes in anticipation of changes but if the shipping product is known upfront and you'll never work on it again (as it is with programming assignments) you can safely not bother cleaning things up. You probably just want to accept it's nothing you can teach in a limited setting, but you can warn.
 

Two Words

Member
Design skills like not using big classes is something you need to experience, you can tell people all day it's bad but it doesn't sink in until someone hands you a thousand line monstrosity and asks you to fix a small bug and you waste a couple 8 hours days doing it. Toy problems aren't going to cut it and realistically what they are doing isn't necessarily bad, a typical approach should be naive and refactored as more is added. The skill comes in anticipation of changes but if the shipping product is known upfront and you'll never work on it again (as it is with programming assignments) you can safely not bother cleaning things up. You probably just want to accept it's nothing you can teach in a limited setting, but you can warn.
To give you some context. It's making a board game called Reversi. I'm basically saying to have a game class that has a board object, and 2 player objects. The board class has a 2D array of position objects. The position class has a disc object. And player objects have a reference to the same board object. A lot of students just want to make a 2D character array to represent the board and whatnot even though the assignment is an OOD project with OOD requirements.
 

V_Arnold

Member
To be fair, any board game implementation would have a very primitive n*m simple numeric array behind it at some point. If not, that is what I would call overdesigned object-oriented approach.
 

JeTmAn81

Member
To give you some context. It's making a board game called Reversi. I'm basically saying to have a game class that has a board object, and 2 player objects. The board class has a 2D array of position objects. The position class has a disc object. And player connects have a reference to the same board object. A lot of students just want to make a 2D character array to represent the board and whatnot even though the assignment is an OOD project with OOD requirements.

It takes time to develop the instincts that tell you how to break software requirements into object-oriented structures, and to understand how useful that can be. The students might have to take your wisdom as a given and roll with it for now. Some rules of thumb for organizing their projects could help:

1. Classes and functions should be small and only do one thing.

2. Class cohesion should be high, i.e. each class function should use as many of the instance variables as possible.

3. If you've got a group of functions only operating on a subset of the instance variables, it could be an opportunity to extract those out into their own class.

Etc.
 
I feel like I'm making this a lot harder than it needs to be..

I'm trying to read a file that looks like this:
Code:
{1, 2}
{2, 3}
{3}
{}

to fill a double int array (int[][] lines, for example). What is the simplest method to do so? I'm working in Java if it makes any difference.
 

Hylian7

Member
Programming GAF help me. Am I just stupid?

I have to do a coding test for an interview, and part of it uses Gradle. I'm following the instructions on the Gradle website to install it and it's not working. WTF am I doing wrong?

I'm following these instructions: https://docs.gradle.org/current/userguide/installation.html

Java, Download, and Unpacking, I got all that for sure.

The Environment Variables though, what the FUCK am I doing wrong?!

It says:

3.4. Environment variables
For running Gradle, firstly add the environment variable GRADLE_HOME. This should point to the unpacked files from the Gradle website. Next add GRADLE_HOME/bin to your PATH environment variable. Usually, this is sufficient to run Gradle.

Okay, so...

kUWJDjd.png

PeXHNZP.png


And then try it...

qu9KD6T.png


Aaaaaaaand what?!
 
FUCK

That worked.

Thank you.

A proccess's environment is initialized when the process is created. That place where you set it in Windows is just setting the value used to initialize each process's environment.

You can set it inside of a command prompt by using the SET command in dos, but then it won't be there next time.

So yea, when you make changes in Windows, restart all proccess's that depend on having the new value
 

JeTmAn81

Member
I feel like I'm making this a lot harder than it needs to be..

I'm trying to read a file that looks like this:
Code:
{1, 2}
{2, 3}
{3}
{}

to fill a double int array (int[][] lines, for example). What is the simplest method to do so? I'm working in Java if it makes any difference.

Pseudocode -

int lines[];
String textlines[] = textfile.Split("{");

for (int row = 0; row < textlines.size; row++)
{
String numbers[] = textline[row].split(",");

for (int column = 0; i < numbers.size; column++)
lines[row][column] = ConvertToInteger(numbers[row]);
}



RE: CPP_is_king's name change. Dumb stuff on the mods' part. Political views aside, if what someone posts is really unacceptable the thing to do is ban them, not do a stupid name change.
 
RE: CPP_is_king's name change. Dumb stuff on the mods' part. Political views aside, if what someone posts is really unacceptable the thing to do is ban them, not do a stupid name change.

Yea, people aren't allowed to do political satire around here I guess. Doesn't help that certain mods (I know who you are!) don't like me, but oh wellz.
 

sgjackson

Member
i took a java course a few years ago and ended up taking a break from school. i've mostly been using c or c++ since then and haven't touched java. what's the best way i can give myself a refresher on java (along with the basics of objects/classes and ui design)? i'm sure this has been asked a million times but i didn't read through 320 pages and didn't see anything in the op.
 

Hylian7

Member
I've been having a problem with something.

Is anyone here familiar with Dropwizard?

I'm using it with an H2 Database, and based on all the documentation I've read, I need the class "DataSourceFactory". I've got the io.dropwizard.db in my build, but then if I try to import or use DataSourceFactory, it's not recognized. Why is this?
 
I've been having a problem with something.

Is anyone here familiar with Dropwizard?

I'm using it with an H2 Database, and based on all the documentation I've read, I need the class "DataSourceFactory". I've got the io.dropwizard.db in my build, but then if I try to import or use DataSourceFactory, it's not recognized. Why is this?

No clue what any of the stuffed you're talking about is, but my guess is you need to add an #include, import, using, or some other kind of similar statement to your file.
 
Anyone here familiar with Visual Studio 2015 and Code Blocks? As well as linux?

My C code compiles on Visual Studio 2015 and my school's linux server (Flip). But won't compile on code blocks. It seems like there's some syntax error. But I can't find any.

I can't post the code here directly. Would anyone be willing to PM me?
 
Anyone here familiar with Visual Studio 2015 and Code Blocks? As well as linux?

My C code compiles on Visual Studio 2015 and my school's linux server (Flip). But won't compile on code blocks. It seems like there's some syntax error. But I can't find any.

I can't post the code here directly. Would anyone be willing to PM me?

You could put it in an email tag, or link a private unlisted pastebin. But yea otherwise pm me
 

cheezcake

Member
JS gaf. What's the best tool for real time plotting of pretty large data sets? D3 seems to be the go but I know next to nothing about frontend/javascript.
 
Top Bottom