• 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

I figure this is the best place to ask. What's the best way to create a website that allows users to submit text and then have an admin approve it to show up on the page? Would creating something like this from scratch be too much for someone with very little programming experience (in C++)?

Are there any scripts already made that I could install and customize? I'm trying to think of the name for this type of thing, but comments and review doesn't really encompass it although it could be modified for that.

Website that users can just enter text that admin must approve is not too much of work, but implementing a known CMS (http://en.wikipedia.org/wiki/Web_content_management_system) would not only be easier*, but also safer and more secure.

* YMMV
 

oxrock

Gravity is a myth, the Earth SUCKS!
This is sort of my yearly python re-learning exercise, so I gave it a shot as well:
Code:
#!/usr/bin/env python

from itertools import islice

prime_count = int(raw_input())
if prime_count < 0:
  raise ValueError('Cannot find a negative number of primes.')

n_values = []
for i in xrange(prime_count):
  n = int(raw_input())
  if n < 1:
    raise ValueError('When finding the nth prime, '
      'n cannot be less than one.')
  n_values.append(n)

largest_n = max(n_values) if n_values else -1

def is_prime(value, smaller_primes):
  for prime in smaller_primes:
    if value % prime == 0:
      return False
  return True

value = 3
prime_list = [2]
max_index = 0
while len(prime_list) < largest_n:
  if (max_index < len(prime_list) - 1 and
    prime_list[max_index] ** 2 <= value):
    max_index += 1
  if is_prime(value, islice(prime_list, max_index)):
    prime_list.append(value)
  value += 2

for n in n_values:
  print prime_list[n-1]

Outperformed my code my 0.05 seconds on the hardest test, how dare you! :p
 

Pau

Member
^ Depends on the web host. If you're going to get a generic one, most feature PHP, so you'll have to use it.

On a server with PHP you can install WordPress, which is a blog-type system, which allows you to create posts/pages and then have people comment on them. You can then make the posts only show up if they're approved.
I figured WordPress would be difficult to scale down to what I want, but I'll take a look.

Website that users can just enter text that admin must approve is not too much of work, but implementing a known CMS (http://en.wikipedia.org/wiki/Web_content_management_system) would not only be easier*, but also safer and more secure.

* YMMV
Yeah, that makes sense. Thank you for the link. I wasn't sure what these things were called. :)
 
Could someone give me a hand with this part of the Code Academy HTML course? Currently looking at the "Sorting your friends" activity for CSS classes and IDs, and at the end of it, it's invited me to play around with it.

Essentially I'm looking to shrink down a picture to place in one of the circular divs, and yet the height and width commands in the CSS file don't seem to shrink it? Which one should I be using?

Code:
	<body>
		<div class="friend" id="best_friend"><a href="https://www.google.co.uk/search?q=inbetweeners&client=opera&hs=nkc&source=lnms&sa=X&ei=TQfMU5DMDaK30QXFv4Bw&ved=0CAUQ_AUoAA&biw=1920&bih=972&dpr=1"> <img src="http://xenovive.files.wordpress.com/2011/09/tumblr_laq2f3cn5r1qzhf66o1_500.jpg"/></a></div>
		<div class="friend"></div>
	    <div class="family"><p>family</p></div>
	    <div class="elves"><p>elves</p></div>
	    <div class="vidya"><p>vidya</p></div>
	    <div class="enemy"></div>
	    <div class="enemy" id="archnemesis"><p></p></div>
	   
	</body>

Code:
div {
	display: inline-block;
	margin-left: 5px;
	height:100px;
	width:100px;
	border-radius:100%;
	border-width:2px;
	border-style:solid;
	border-color:black;
}
.friend{
    border-style:dashed;
    border-width:2px;
    border-color:#008000;
}
.family{
    border-style:dashed;
    border-width:2px;
    border-color:#0000ff;
}
.enemy{
    border-style:dashed;
    border-width:2px;
    border-color:#ff0000;
}
.elves{
    border-style:solid;
    border-width:4px;
    border-color:#008999;
}
.vidya{
    border-style:dashed;
    border-width:8px;
    border-color:#978590;
}
#best_friend{
    border-style:solid
    border-width:4px;
    border-color:#00c957;
}
#archnemesis{
    border-style:solid
    border-width:4px;
    border-color:#cc0000;
}
 
Could someone give me a hand with this part of the Code Academy HTML course? Currently looking at the "Sorting your friends" activity for CSS classes and IDs, and at the end of it, it's invited me to play around with it.

Essentially I'm looking to shrink down a picture to place in one of the circular divs, and yet the height and width commands in the CSS file don't seem to shrink it? Which one should I be using?

Either place the image as the background-image for the div and use backround-size: contain; or add "overflow:hidden" to your div and manually adjust the img elements with max-width: XXXpx; max-height: XXXpx;

http://jsbin.com/kimahexa/1/
 

Slavik81

Member
When using vim, if I do :make I have a hard time finding where my output begins when I have a lot of errors. Any idea how people usually handle this?
 

wario

Member
Could someone give me a hand with this part of the Code Academy HTML course? Currently looking at the "Sorting your friends" activity for CSS classes and IDs, and at the end of it, it's invited me to play around with it.

Essentially I'm looking to shrink down a picture to place in one of the circular divs, and yet the height and width commands in the CSS file don't seem to shrink it? Which one should I be using?

Code:
div {
	display: inline-block;
	margin-left: 5px;
	height:100px;
	width:100px;
	border-radius:100%;
	border-width:2px;
	border-style:solid;
	border-color:black;
        [B]overflow:hidden;[/B]
}
[B]a, img {
        height: inherit;
        width: inherit;
}[/B]
.friend{
    border-style:dashed;
    border-width:2px;
    border-color:#008000;
}
.family{
    border-style:dashed;
    border-width:2px;
    border-color:#0000ff;
}
.enemy{
    border-style:dashed;
    border-width:2px;
    border-color:#ff0000;
}
.elves{
    border-style:solid;
    border-width:4px;
    border-color:#008999;
}
.vidya{
    border-style:dashed;
    border-width:8px;
    border-color:#978590;
}
#best_friend{
    border-style:solid
    border-width:4px;
    border-color:#00c957;
}
#archnemesis{
    border-style:solid
    border-width:4px;
    border-color:#cc0000;
}

made the changes in bold

the 'overflow:hidden' confines the div contents to its dimensions. then you need to set the nested a and img tags to the same height and width of the parent div tag.

note: since the image isn't a perfect square, it will be squashed horizontally inside the div.
 
Either place the image as the background-image for the div and use backround-size: contain; or add "overflow:hidden" to your div and manually adjust the img elements with max-width: XXXpx; max-height: XXXpx;

http://jsbin.com/kimahexa/1/

made the changes in bold

the 'overflow:hidden' confines the div contents to its dimensions. then you need to set the nested a and img tags to the same height and width of the parent div tag.

note: since the image isn't a perfect square, it will be squashed horizontally inside the div.

Cheers guys. I'll have to bookmark that jsbin site, seems very useful!

The only thing was I couldn't get the width/height:inherit method to work? I just ended up with the corner of the full size image that wasn't hidden from the overflow:hidden command. The max-height & max-width functions worked perfectly though!
 

Roflobear

Member
Need some help with a program I'm making in Java. I'm supposed to make my own linked list class, where each element in the node represents a department store item with five variables: its name, its RFID number (as a string), its original location in the store, its current location, and its price (as a double).

A certain method in my list class is supposed to "move" an item by changing its current location to something the user specifies. The user chooses this item by specifying its RFID number and its current location before it is changed. For some reason, my method only changes the first node that matches the user's criteria but doesn't change any of the others. I'm assuming it's a problem with how my method iterates through the list, but I just can't seem to figure it out. Here's what the method code looks like:

Code:
public boolean moveItem(String rfidTag, String source, String dest) throws CheckedOutException {
		cursor = head;
		while (cursor.getNext() != null) {
			if (cursor.getInfo().getRfidTagNumber().equalsIgnoreCase(rfidTag)) {
				if (cursor.getInfo().getCurrentLocation().equalsIgnoreCase(source)) {
					if (cursor.getInfo().getCurrentLocation().equalsIgnoreCase("out")) {
						throw new CheckedOutException();
					}
					try {
						cursor.getInfo().setCurrentLocation(dest);
					} catch (IllegalLocationException e) {
						System.out.print(e.getMessage());
					}
					return true;
				}
			}
			cursor = cursor.getNext();
		}
		if (tail.getInfo().getRfidTagNumber().equalsIgnoreCase(rfidTag)) {
			if (tail.getInfo().getRfidTagNumber().equalsIgnoreCase(rfidTag)) {
				if (tail.getInfo().getCurrentLocation().equalsIgnoreCase(source)) {
					if (tail.getInfo().getCurrentLocation().equalsIgnoreCase("out")) {
						throw new CheckedOutException();
					}
					try {
						tail.getInfo().setCurrentLocation(dest);
					} catch (IllegalLocationException e) {
						System.out.print(e.getMessage());
					}
					return true;
				}
			}
		}
		return false;
	}

So the parameters are the RFID number, the current location before its changed called "source", and the current location the user wants to change it to called "dest". The code inside the while loop is supposed to iterate through the list, making the changes so long as the item isn't checked out (throws a CheckedOutException if it is) and it matches the user's criteria.

The last half of the code (in the if statement), does the exact same thing to the tail, the last node in the list, since I don't think the while loop gets to it. Any idea why only the first node to match the user's criteria gets changed instead of all of them?
 
D

Deleted member 30609

Unconfirmed Member
Are you definitely setting next correctly on insert? Post the entire class. :)

Also, by convention, "next()" both returns the next item and moves the iterator (cursor) along. But it depends on your implementation!
 
note: since the image isn't a perfect square, it will be squashed horizontally inside the div.

You could use height:auto on the image to make it scale better if you don't mind the container growing as a result.
or move the image to a background and use background-size:cover/contain

The only thing was I couldn't get the width/height:inherit method to work? I just ended up with the corner of the full size image that wasn't hidden from the overflow:hidden command. The max-height & max-width functions worked perfectly though!

Did the image have width and/or height attributes? Inline style or attributes overwrite CSS from your head, unless you use !important in the declaration.
Code:
img { height: inherit !important; width: inherit !important; }
 

Roflobear

Member
Are you definitely setting next correctly on insert? Post the entire class. :)

Also, by convention, "next()" both returns the next item and moves the iterator (cursor) along. But it depends on your implementation!

Well, this is the node class I made. I just used the standard getter/setter for next. To advance the cursor, I would do cursor = cursor.getNext(). Also made a minor update to my code in my previous post, just switching around the order of if statements. Didn't make a difference though =\

Code:
public class ItemInfoNode {
	
	private ItemInfo info;
	private ItemInfoNode prev;
	private ItemInfoNode next;

	public ItemInfoNode(ItemInfo info, ItemInfoNode prev, ItemInfoNode next) {
		this.info = info;
		this.prev = prev;
		this.next = next;
	}

	public ItemInfo getInfo() {
		return info;
	}

	public void setInfo(ItemInfo info) {
		this.info = info;
	}

	public ItemInfoNode getPrev() {
		return prev;
	}

	public void setPrev(ItemInfoNode prev) {
		this.prev = prev;
	}
	
	public ItemInfoNode getNext() {
		return next;
	}

	public void setNext(ItemInfoNode next) {
		this.next = next;
	}

}
 
D

Deleted member 30609

Unconfirmed Member
Well, this is the node class I made:

I just used the standard getter/setter for next. To advance the cursor, I would do cursor = cursor.getNext()

Oh, you're returning in the middle of the loop rather than iterating through the list (in the moveItem method). I'd check for your special case (a single item list) before you do anything else.
Code:
if( cursor.getNext() == null ) {
     return false;
}

// the rest of the method

Also, consider checking whether or not cursor == null beforehand. :)
 

Roflobear

Member
Oh, you're returning in the middle of the loop rather than iterating through the list (in the moveItem method). I'd check for your special case (a single item list) before you do anything else.

Also, consider checking whether or not cursor == null beforehand. :)

Oh wow it's so obvious now! Thanks so much for pointing that out!

Also thanks for the suggestion. I totally forgot to consider if the user invoked the method on an empty or single-item list.

Edit: well the method works perfectly now. Thanks again for your help!

Double edit: turns out the method already works as is on single item lists. The only extra case was the empty list
 

oxidax

Member
Ok GAF im sad.

A friend of mine owns a business and he hired some guy to work on an app for it. Apparently they know each other and hes gonna do his app for free.
He called me last night and told me that he wanted me, him and the guy to go out for a drink because he wanted me to meet him. I thought ok..thats weird why would I want to meet him? Well after an hour and a half of talking about all the IT stuff I do on the side because its not really my day job, the motherfucker tells me he actually works for Google!

My buddy told me that the reason why he wanted me to meet him is because the guy told him that he could put a good word of me over there if I ever wanted to apply. Because why not have a good reference AT GOOGLE!

The guy then asked me, do you code? My answer? FUCKING NO! :(

GAF, I probably wont ever get a Job at Google, but that shit made me sad. IT has always been my thing. I read and learn about all the new things that come out, but i cant believe that I still don't know how to code!

I see all the different languages and websites on the OP, but were do I start? which site is actually the best site thats gonna teach me to code and that I can actually use that knowledge for a career opportunity?
 
D

Deleted member 30609

Unconfirmed Member
Ok GAF im sad.

A friend of mine owns a business and he hired some guy to work on an app for it. Apparently they know each other and hes gonna do his app for free.
He called me last night and told me that he wanted me, him and the guy to go out for a drink because he wanted me to meet him. I thought ok..thats weird why would I want to meet him? Well after an hour and a half of talking about all the IT stuff I do on the side because its not really my day job, the motherfucker tells me he actually works for Google!

My buddy told me that the reason why he wanted me to meet him is because the guy told him that he could put a good word of me over there if I ever wanted to apply. Because why not have a good reference AT GOOGLE!

The guy then asked me, do you code? My answer? FUCKING NO! :(

GAF, I probably wont ever get a Job at Google, but that shit made me sad. IT has always been my thing. I read and learn about all the new things that come out, but i cant believe that I still don't know how to code!

I see all the different languages and websites on the OP, but were do I start? which site is actually the best site thats gonna teach me to code and that I can actually use that knowledge for a career opportunity?

My answer is going to be very book-centric. Some people don't take well to reading about this sort of thing, and do better in practical situations with other people. I don't have much of value to offer there other than consider tertiary education.

Anyway, the short answer: pick a reasonably popular language that supports basic OO design (C++, Java, Python, C#, etc) and start working through some basic online tutorials. I know next to nothing about it, but don't some universities offer free online courses nowadays? I can't vouch for their value, but look into it. I've heard good things about "Dive Into Python" (available for free online).

Pick your poison, basically.

It's hard to understand early on, but the language you're using is secondary to actually thinking algorithmically or architecturally. Books like "The Mythical Man Month" and "Peopleware" are (still!) invaluable. After you've spent some time working on some projects, books like "Design Patterns" and "Refactoring" --- when read as guidelines rather than gospel --- help you think about your design.

Failing all this, find a friend and work through some problems together. It sounds obvious, even with a team of two, you'll start to butt up against some of the interesting problems working with other people ensue.

Once you have a solid understanding of a language, come back to this and follow up with some of the books mentioned here, or feel free to ask more questions. There's so many employer-specific intricacies when it comes to work environment, configuration/issue management, team process and so on that it's impossible to point to something and say "this is where you should start"*. Again, these books are useful, but the thing that makes you most attractive to employers will always be demonstrable experience. Well, that's broad. Evidence of constant, genuine critical thinking is probably the thing I'm most excited by, but if you have a good way of gauging that on a resume/interview, I'd love to hear it. :p

*: I can point you toward the wikipedia pages for, say, the waterfall model (which, warts and all, at least gives you a decent overview of the broad steps most project faces at one time or another) or an agile methodology, but don't get too hung up on them to start with. If you're interested, feel free to ask or have a look around yourself.
 
Guys I'm pretty hyped. Got some interest from a major agency for a grant idea. The guy interested is essentially the head of the grant decision making body.

The idea will require an application that does the following:

"Passively monitor and record social network communications (Facebook, initially) of specific users who opt in for the service. Communication records would then be sifted for key words and phrases and then compiled for submission to an agency."

So this could be either a single application that collects and sifts through data, or just collects the data and exports it for sifting by another, simpler, program.

We're working on the qualitative portions of our grant proposal, but we honestly have no idea what something like this would cost.

1. What is a reasonable ball park estimate to create something like this?
2. What would be the best way to find an interested developer?
 

Fantastical

Death Prophet
I'm going to be a senior majoring in Computer Science. I have a good amount of programming experience. I feel somewhat confident in my skills.

I want to explore some 2D game development. Where should I start? As I said, I have a good background in programming. I don't need something built for absolute beginners, but I've never tried to make a game before. Any suggestions would be appreciated.

EDIT: I mostly know C++ and Java if that matters.
 
D

Deleted member 30609

Unconfirmed Member
I'm going to be a senior majoring in Computer Science. I have a good amount of programming experience. I feel somewhat confident in my skills.

I want to explore some 2D game development. Where should I start? As I said, I have a good background in programming. I don't need something built for absolute beginners, but I've never tried to make a game before. Any suggestions would be appreciated.

EDIT: I mostly know C++ and Java if that matters.
I'm only just starting to get my feet wet re games programming, but if you're looking for a decent introduction to game engines and the like, Unity's tutorial suite is impressive and free. I haven't dabbled with it yet, but the $20/month Unreal 4 suite with tutorials and the like looks competitive.

Keep in mind, just jumping into game engine tutorials is kind of engaging, but they try to address an audience with an absurd variety of skill-levels across completely unrelated fields. You'll go from finding the coding stuff to being maddeningly high-level and unhelpful to the animation/art related material being completely out of your comfort zone. They are a decent starting point, though.

I'm currently reading the kindle version of Real Time Rendering, which seems decent so far, but it someone in another thread who probably knows more than me thought it might be overkill if you're looking to experiment with 2D games. I'm waiting on this book to arrive, which is apparently more of an overview of all the different parts of a game engine, but I can't vouch for it yet.

I wish I could be more helpful. I'm in the same boat as you!
 

Aureon

Please do not let me serve on a jury. I am actually a crazy person.
I'm going to be a senior majoring in Computer Science. I have a good amount of programming experience. I feel somewhat confident in my skills.

I want to explore some 2D game development. Where should I start? As I said, I have a good background in programming. I don't need something built for absolute beginners, but I've never tried to make a game before. Any suggestions would be appreciated.

EDIT: I mostly know C++ and Java if that matters.

THE best unity introduction is this: http://catlikecoding.com/unity/tutorials/
 

oxrock

Gravity is a myth, the Earth SUCKS!
I'm going to be a senior majoring in Computer Science. I have a good amount of programming experience. I feel somewhat confident in my skills.

I want to explore some 2D game development. Where should I start? As I said, I have a good background in programming. I don't need something built for absolute beginners, but I've never tried to make a game before. Any suggestions would be appreciated.

EDIT: I mostly know C++ and Java if that matters.

If your main language is C++, then I would certainly suggest the unreal engine.
 
Guys I'm pretty hyped. Got some interest from a major agency for a grant idea. The guy interested is essentially the head of the grant decision making body.

The idea will require an application that does the following:

"Passively monitor and record social network communications (Facebook, initially) of specific users who opt in for the service. Communication records would then be sifted for key words and phrases and then compiled for submission to an agency."

So this could be either a single application that collects and sifts through data, or just collects the data and exports it for sifting by another, simpler, program.

We're working on the qualitative portions of our grant proposal, but we honestly have no idea what something like this would cost.

1. What is a reasonable ball park estimate to create something like this?
2. What would be the best way to find an interested developer?

1. I think we'd need a much more specific set of project requirements to give you an analysis of what something like this would cost. It can really vary widely. It sounds like it could be as simple as a matter of calling some web services, storing the information into a database, and then writing queries for the data. I'm not personally familiar with the APIs for the major social media platforms as that isn't something I deal with, so I can't say how feasible that is. From the sound of it though the database aspect would most likely be a NoSQL solution. It would be in your best interest to meet with a tech consultant to plan out your use cases for the project, and maybe come up with a technology stack for the implementation.

2. This depends on the scope of the project as well. If it's a simple, grant based thing with low funding your best bet may be to work with some undergrads or grad students. You could contact your local social groups or tech media for developers as well. You could go full on recruitment via Dice.com.
 

oxidax

Member
My answer is going to be very book-centric. Some people don't take well to reading about this sort of thing, and do better in practical situations with other people. I don't have much of value to offer there other than consider tertiary education.

Anyway, the short answer: pick a reasonably popular language that supports basic OO design (C++, Java, Python, C#, etc) and start working through some basic online tutorials. I know next to nothing about it, but don't some universities offer free online courses nowadays? I can't vouch for their value, but look into it. I've heard good things about "Dive Into Python" (available for free online).

Pick your poison, basically.

It's hard to understand early on, but the language you're using is secondary to actually thinking algorithmically or architecturally. Books like "The Mythical Man Month" and "Peopleware" are (still!) invaluable. After you've spent some time working on some projects, books like "Design Patterns" and "Refactoring" --- when read as guidelines rather than gospel --- help you think about your design.

Failing all this, find a friend and work through some problems together. It sounds obvious, even with a team of two, you'll start to butt up against some of the interesting problems working with other people ensue.

Once you have a solid understanding of a language, come back to this and follow up with some of the books mentioned here, or feel free to ask more questions. There's so many employer-specific intricacies when it comes to work environment, configuration/issue management, team process and so on that it's impossible to point to something and say "this is where you should start"*. Again, these books are useful, but the thing that makes you most attractive to employers will always be demonstrable experience. Well, that's broad. Evidence of constant, genuine critical thinking is probably the thing I'm most excited by, but if you have a good way of gauging that on a resume/interview, I'd love to hear it. :p

*: I can point you toward the wikipedia pages for, say, the waterfall model (which, warts and all, at least gives you a decent overview of the broad steps most project faces at one time or another) or an agile methodology, but don't get too hung up on them to start with. If you're interested, feel free to ask or have a look around yourself.

Thank you so much! Yeah, reading is not really my thing but I can do it specially when is for something so useful as this. I really appreciate it.
 

PlayDat

Member
This sounds like you didn't configure the build path: configuring where to find the dependencies in your project.


Sounds like you need to re-read on packages ; )
http://docs.oracle.com/javase/tutorial/java/package/managingfiles.html

This is a really old post, but that link was super helpful. I got sidetracked by a summer course I was taking.

I finished recreating Minesweeper in Java. Works almost (doesn't keep a record of your fastest time, doesn't let you make custom game boards, but it does have the main 3 difficulty settings and has a timer for the game in progress) exactly the same as the real one, just looks a little different since I'm using JButtons.

It's a pretty small project but at my level this felt like a big accomplishment.
 
How do you guys go about finding another job while you're still employed? Anyone else find it difficult? Only so many interviews one can go on.
 

Fantastical

Death Prophet
I'm only just starting to get my feet wet re games programming, but if you're looking for a decent introduction to game engines and the like, Unity's tutorial suite is impressive and free. I haven't dabbled with it yet, but the $20/month Unreal 4 suite with tutorials and the like looks competitive.

Keep in mind, just jumping into game engine tutorials is kind of engaging, but they try to address an audience with an absurd variety of skill-levels across completely unrelated fields. You'll go from finding the coding stuff to being maddeningly high-level and unhelpful to the animation/art related material being completely out of your comfort zone. They are a decent starting point, though.

I'm currently reading the kindle version of Real Time Rendering, which seems decent so far, but it someone in another thread who probably knows more than me thought it might be overkill if you're looking to experiment with 2D games. I'm waiting on this book to arrive, which is apparently more of an overview of all the different parts of a game engine, but I can't vouch for it yet.

I wish I could be more helpful. I'm in the same boat as you!

Thank you! Yeah I think I'm going to try to dive into Unity, but it's very true about the wide variety of skill-levels. It gets weird when you think you find a good tutorial and it seems to be aimed at highschoolers / early programmers who know almost nothing about programming. Not that that's bad, but I'm not at that audience.

THE best unity introduction is this: http://catlikecoding.com/unity/tutorials/

This looks fantastic. Thanks for the link.

If your main language is C++, then I would certainly suggest the unreal engine.

I'll take a look at it. The $20/month is making me hesitant. I'll probably start with Unity and maybe consider it down the road. Thanks!
 

Roflobear

Member
I have another Java question that's confusing me. Say if I have two strings, string1 and string2. I set string1 equal to "hello" and string2 equal to string1. Now if I change string1 to "world", string2 still remains as "hello".

Now say I have a node class called ItemInfoNode with two instance variables: ItemInfo (that contains a string called name and a double called price) and another ItemInfoNode that is a reference to the next node in the list. If I make an ItemInfoNode object called node and set its name to "hello" and price to whatever, then another node called cursor and set it equal to node, then finally change node's name to "world", this time cursor's string value changes along with node's.

Why is string2 unchangeable in the first case but cursor's name changeable in the second case? Or why is String immutable and cursor simply a reference?
 
D

Deleted member 30609

Unconfirmed Member
I have another Java question that's confusing me. Say if I have two strings, string1 and string2. I set string1 equal to "hello" and string2 equal to string1. Now if I change string1 to "world", string2 still remains as "hello".

Now say I have a node class called ItemInfoNode with two instance variables: ItemInfo (that contains a string called name and a double called price) and another ItemInfoNode that is a reference to the next node in the list. If I make an ItemInfoNode object called node and set its name to "hello" and price to whatever, then another node called cursor and set it equal to node, then finally change node's name to "world", this time cursor's string value changes along with node's.

Why is string2 unchangeable in the first case but cursor's name changeable in the second case? Or why is String immutable and cursor simply a reference?
The references in the string1, string2 example are explicitly to strings. When you reassign a string, you're essentially calling the string constructor. These statements are equivalent:

Code:
String one = "1";
String two = one;
String two = "2";

and

Code:
String one = "1";
String two = one;
String two = new String("2");

In any case, while strings are immutable, you node class isn't. Two pointers to the same node, yes, but within that same node you're reassigning the same string reference.

This crude, inconsistent excuse for a diagram might help:

Code:
(Node Reference 1) -----> (Node) -------> (String)
(Node Reference 2) -----------^
 

Roflobear

Member
That clears it up nicely. Also that diagram is great. Thanks again Rez!

Also I'm assuming if you make your own classes, they're always gonna be mutable?
 
D

Deleted member 30609

Unconfirmed Member
That clears it up nicely. Also that diagram is great. Thanks again Rez!

Also I'm assuming if you make your own classes, they're always gonna be mutable?

Don't get too hung up on the behaviour of strings. They're a special case, designed as such so that they behave more like the primitive data types in the language.

And you can write immutable classes. If you write a class that doesn't have any methods that modify any of its class-level variables (I think Java calls these methods "mutators" or "setters"), then your class is immutable. They're set once at construction and that's it.
 

Roflobear

Member
Don't get too hung up on the behaviour of strings. They're a special case, designed as such so that they behave more like the primitive data types in the language.

And you can write immutable classes. If you write a class that doesn't have any methods that modify any of its class-level variables (I think Java calls these methods "mutators" or "setters"), then your class is immutable. They're set once at construction and that's it.

Ah ok gotcha
 
Guys I'm pretty hyped. Got some interest from a major agency for a grant idea. The guy interested is essentially the head of the grant decision making body.

The idea will require an application that does the following:

"Passively monitor and record social network communications (Facebook, initially) of specific users who opt in for the service. Communication records would then be sifted for key words and phrases and then compiled for submission to an agency."

So this could be either a single application that collects and sifts through data, or just collects the data and exports it for sifting by another, simpler, program.

We're working on the qualitative portions of our grant proposal, but we honestly have no idea what something like this would cost.

1. What is a reasonable ball park estimate to create something like this?
2. What would be the best way to find an interested developer?

The requirements are really too vague to give a ballpark estimate. So many questions would need to be answered first:

What services/APIs does it need to interact with (and any and all fees associated with them)? What existing open source tools are out there that the developer could leverage? How scaleable does it need to be? What future maintenance work would be required? (Things like this generally aren't one and done, so chances are you would need someone to come in in the future to make updates, fix bugs, etc.) How would the data be stored, and what level of redundancy and backups would be required? How exactly are you going to be "monitoring" them? A browser extension? Something else? How does one opt in or out? Who is available to fix when it breaks? What's doing the "sifting", and how complex are its requirements? You would need someone to setup a server to do that, as well as all of the database engines and whatever else is needed. Do you want a laymen to be able to update the business rules related to the "sifting" without direct help from the developer? (Setting that up would likely not be a simple task.) Those are just some of the questions that would need to be answered.

You could probably get somebody on oDesk or whatever to do it for cheap, but it's likely not going to be well engineered or tested. I would definitely suggest not skimping on developer costs, as doing so would likely cost more in the future. But those considerations are also related to the scale of the project and the answers to the questions above.
 
Ah ok gotcha

Note that it's important to realize strings aren't different here than anything else. Assignment is assignment is assignment. There is nothing fundamentally different between

Code:
int a = 1;
int b = a;
a = 2;
// a and b no longer equal

String x = "1";
String y = x;
x = "2";
// x and y no longer equal

Foo foo1 = new Foo("whatever");
Foo foo2 = foo1;
foo1 = new Foo("changed"); 
// foo1 and foo2 no longer equal

In all cases, you have variables that for a moment in time share a value. Those variables are not linked, do not depend upon one another, do not change with one another. They simply refer to values. What those values are may differ (primitive bits, references to objects, etc.), but in any event, reassigning those variables with other values is not behaving differently in any of the code displayed.

People often make strings more complicated than they need to be. There is bellyaching and much handwaving regarding immutability, when in most cases, such disclaimers are not only unnecessary, but entirely misleading. Yes, they're immutable, but that's not all the relevant in coding questions that quite often take the form shown above. When you understand the view of "assignment is assignment," it should be unsurprising when your string variables do not change with one another.

This differs from perhaps what you're doing with your node. Let's take the following code sample (disregard violations of encapsulation here)

Code:
ItemNode first = new ItemNode();
first.name = "Foo";

ItemNode second = first;

first.name = "Bar";

In this case, second.name will also equal "Bar", and it's not because of any magic. first and second still contain the same value, which is a reference to an object. Since the value of first and second is the same, first and second's fields are also the same. (Consider if there were two Human variables referencing you. The owner of one variable changes your name field. The owner of the other variable would see that updated name. If one owner then points their variable to a different human, changes to that human do not apply to you and are therefore not visible in the other variable.) You've done nothing to reassign either first or second, so any changes* you make to one are going to impact the other. That would differ if you would simply alter the code

Code:
ItemNode first = new ItemNode();
first.name = "Foo";

ItemNode second = first;

first = new ItemNode(); // NEW -- reassignment of first, could easily also be 'first = someOtherNode;'
first.name = "Bar";

Again, nothing special, it's just like the code shown for ints, strings, and Foos. Assignment is assignment is assignment. The variable first now contains a new value, a different value than second, referencing a different object. Changes* made to first after that new assignment aren't going to impact second, because they no longer share anything in common.

People confuse this frequently enough, so if I'm 'splaining things you are already comfortable with, please excuse me.

----

*It's helpful to remember that in the example of first and second, outside of reassignment, you're technically not changing the variable. You're changing a field on the object referenced by the variable. The variable itself isn't getting modified by anything you're doing except when you actually reassign the variable to a new object, another instance, or null.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
THE best unity introduction is this: http://catlikecoding.com/unity/tutorials/

+1 for this site. I used this when I was learning Unity, and it helped a ton. There are some bugs in the tutorials that will teach some debugging skills as well.
or infuriate you, or both

I'll take a look at it. The $20/month is making me hesitant. I'll probably start with Unity and maybe consider it down the road. Thanks!

FYI, with UE4 you can subscribe for one month, ($20), then cancel. You still get the full engine, all the source code, and can mess around with it to your hearts content. All you are prevented from doing is getting updates and probably publishing.
 
The requirements are really too vague to give a ballpark estimate. So many questions would need to be answered first:

What services/APIs does it need to interact with (and any and all fees associated with them)? What existing open source tools are out there that the developer could leverage? How scaleable does it need to be? What future maintenance work would be required? (Things like this generally aren't one and done, so chances are you would need someone to come in in the future to make updates, fix bugs, etc.) How would the data be stored, and what level of redundancy and backups would be required? How exactly are you going to be "monitoring" them? A browser extension? Something else? How does one opt in or out? Who is available to fix when it breaks? What's doing the "sifting", and how complex are its requirements? You would need someone to setup a server to do that, as well as all of the database engines and whatever else is needed. Do you want a laymen to be able to update the business rules related to the "sifting" without direct help from the developer? (Setting that up would likely not be a simple task.) Those are just some of the questions that would need to be answered.

You could probably get somebody on oDesk or whatever to do it for cheap, but it's likely not going to be well engineered or tested. I would definitely suggest not skimping on developer costs, as doing so would likely cost more in the future. But those considerations are also related to the scale of the project and the answers to the questions above.

Thank you for the response, let me see if I can provide some more information in the hopes of getting a ball park for a workable solution.

The initial social media platform targeted would be Facebook. We had originally thought this would need to be done with a Facebook application, but your idea of using a browser extension is possibly way better.

If it's a Facebook application it wouldn't need to be scalable. If it was a browser extension it would need to be scalable as we added new social media platforms (as I consider this the idea of using a browser extension is more and more attractive).

I can see things going either way in terms of whether it sifts data at the app/extension level or it just captures data on a server where a separate tool sifts, gets rid of what isn't relevant, and saves what is relevant for review. Probably the latter would be easier, but I'll defer to more experienced opinions on this.

Words and phrases for red flagging would need to be maintained by someone experienced with computers and systems administration, but not an actual coder.

The initial project should be a relatively stripped down proof of concept. Something that can capture Facebook posts and messages successfully. Once we prove we can do that, we can then expand with a server for storage/sifting or scale up functionality to do the sifting on the app/extension end.
 
This might (probably is) be a stupid question, but I could never figure it out: how do you compile C++ in Xcode?

Depends upon the kind of application you're making. I haven't really written any non iOS stuff, so I can't say for those. But on iOS you either name the file .cpp and include the appropriate headers or if you want a mixed Obj-C/C++ file you name the file .mm and go from there.

QUOTE=Fantastical;122099026]I'm going to be a senior majoring in Computer Science. I have a good amount of programming experience. I feel somewhat confident in my skills.

I want to explore some 2D game development. Where should I start? As I said, I have a good background in programming. I don't need something built for absolute beginners, but I've never tried to make a game before. Any suggestions would be appreciated.

EDIT: I mostly know C++ and Java if that matters.[/QUOTE]


Maybe check out Cocos2D-X: http://www.cocos2d-x.org/download the documentation is horrid, but its a pretty good rendering layer with some game engine functionality. Its primarily aimed at mobile games but you can compile and run as a Windows or OS X desktop app. I like it better for pure 2D development than the poop that is Unity.

Alternatively, download DirectX 9 and roll your own engine/tools.
 
Hey GAF, I'm looking for some books to help me in my Masters, do you guys have any recommendations for books/resources about:

  • Unity
  • The new 2D part of Unity
  • C#
  • OpenGL (with something about GLFW, I knew some things about glut but I've heard that's is severely outdated)
I prefer actual books but if there are none, I would love to know about some online resources.
Thanks in advance!
 
Hey GAF, I'm looking for some books to help me in my Masters, do you guys have any recommendations for books/resources about:

  • Unity
  • The new 2D part of Unity
  • C#
  • OpenGL (with something about GLFW, I knew some things about glut but I've heard that's is severely outdated)
I prefer actual books but if there are none, I would love to know about some online resources.
Thanks in advance!

Books are almost entirely useless for Unity. Its updated far too often and too heavily for any book on it to be useful for more than 6 months.

The 2D Unity stuff is even newer and you're kind of limited to whatever documentation Unity has written and/or whatever samples/tutorials you can find online.

C# I don't have recommendations sorry.

OpenGL, I could recommend some OpenGLES books, but those are only useful if you're primarily into mobile. The OpenGL Super Bible is a pretty decent resource for all flavors of OpenGL in my experience: http://www.openglsuperbible.com/
 

oxidax

Member

For anyone just getting their start with programming, I can't recommend this course enough.

$150 a month for all that is not bad at all! I just looked though the catalog and its like a whole school semester in there or more. I think im going to give it a try. Thank you very much, guys!
 

oxrock

Gravity is a myth, the Earth SUCKS!
$150 a month for all that is not bad at all! I just looked though the catalog and its like a whole school semester in there or more. I think im going to give it a try. Thank you very much, guys!

You don't have to pay for it, you can work through it at your own pace and submit/test your answers through their website. Paying I think gives you a certificate upon completion and allows you to post on the forum. I think that's the deal anyway. Nothing wrong with supporting a good site however, there's some good stuff.

I wish for the life of me that I could find something similar for C#
 

TurtleTracks

Neo Member
This is a guide for the standard tools that come with the JVM: http://docs.oracle.com/javase/8/docs/technotes/guides/tsgvm/ . It's terse but it'll give you an idea of what to look for. There are tons of easy/quick tutorials to follow.

That's good advice, but the low hanging fruit is really just using a database, I think. You can look into Hibernate for a start.

Thanks guys! I managed to get a web page to connect to a Java servlet using Tomcat. I will try tackling memory management and databases soon, but first I was wondering if anyone knew how I could load all the data and variables ahead of time and keep them in memory so that I don't have to call them into memory every time a user does a search? I've been trying to get this working with two servlets, one to initialize, and one to run the user search, but they don't seem to share information with each other, so it all gets thrown out anyway.

EDIT: I figured it out. Now I've gotta start looking into databases and stuff. I'm not really sure how I'm supposed to set everything up in a database to make it more efficient, but NetBeans seems to have Hibernate built in, so I'll try that.
 
We are also running into an issue where we are limited by the number of pages we can run the search on at a time. After about 5,000 pages we hit an Out of Memory Error with Java, even when we max out the virtual memory. We have been running the search engine on my laptop which has 8GB of physical memory, with the stored page files occupying about 124MB on disk. Is there anything we can do to get around the memory issue? I've heard about using databases but I don't really know how that works, as I've never dealt with one before.

Been reading to catch up with what you've been working on. The JVM comes with a default amount of memory allocated, and if you are running into OOM errors you can most likely get around them by increasing the memory allocation. Use the -Xms and -Xmx flags when starting the VM to set the amount of memory you want to allocate. I wouldn't be surprised if the JVM is only using a max of 128MB or 256MB of memory. By increasing this amount you should be able to alleviate your problem, but as you know the real answer to your problem is a database.

You can get SQL Server Express or MySQL for free. Some SQL Server features are locked out of SQL Server Express, but it's probably easier to use than MySQL for someone new to databases. MySQL is free and full featured and I recommend it.

However, for what you are doing with a search engine it may also be beneficial for you to use a NoSQL solution like cassandra. You can use the Datastax jdbc drivers to interface with a Cassandra database and it's really pretty simple. Beware however, the terminology between NoSQL and SQL is VERY similar but the concepts are quite different and it can be difficult to grasp the differences between them.
 

NotBacon

Member
Looking to start a holy war here:

I'm going to make a backend that serves clients on mobile and maybe through a web browser. Clients will be able to post a picture and some text. Clients can also view other peoples posts in the nearby area. So similar to craigslist.

SQL or NoSQL?
 
Top Bottom