Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → Documentation! (Programmers only need apply)
12
Documentation! (Programmers only need apply)
2007-04-26, 11:12 AM #41
Having loads of getters and setters is bad, except I'm working with Spring/Hibernate/Javabeans which requires use of them quite extensively.

Almost every database table gets mapped to an object which is populated automatically by Hibernate using getters and setters. Even if the database is well-normalised (which admittedly it's not, but this is a database that was around before I started work) there are still a lot of classes which are nothing but getters and setters. These don't get comments.

I also don't comment any other code unless it doesn't look obvious what it means. The kind of code that gets commented is the kind of algorithm that has many similar variables such that even decent naming conventions don't really clarify what's going on. These algorithms tend to get refactored into something nicer at some point though.

I also fully comment any code i've copy-pasted from somewhere else that's not my own work, this is so that I personally understand what's going on.
Detty. Professional Expert.
Flickr Twitter
2007-04-26, 11:23 AM #42
Originally posted by Detty:
Having loads of getters and setters is bad, except I'm working with Spring/Hibernate/Javabeans which requires use of them quite extensively.


C# has internal support for properties.

So you can write a getter/setter with something like

Code:
private int iVariable;
public int Variable
{
        get
        {
                return iVariable;
        }

        set
        {
                iVariable = value;
        }
}



And then Variable can be accessed directly as though it were a normal integer. You can put any code you want in the getter and setter and either are optional, so a variable can be viewed as a constant by code that's external to the class.

The benefits of this are numerous and obvious.
2007-04-26, 11:26 AM #43
Unfortunately I don't think I'm going to be persuading my employers to move away from Java anytime soon.

In my opinion Java is just not agile enough as a language for web development which ultimately is pretty straightforward.
Detty. Professional Expert.
Flickr Twitter
2007-04-26, 5:22 PM #44
Originally posted by Jon`C:
// is a C++ comment. C only supports /* */ comments.

The C99 standard allows for // comments in code. Most C compilers should support this; I know GCC does.
[This message has been edited. Deal with it.]
2007-04-26, 6:03 PM #45
comments? I don't even use newlines
2007-04-26, 6:26 PM #46
what about languages without end-of-statement operators? Python comes to mind..
"it is time to get a credit card to complete my financial independance" — Tibby, Aug. 2009
2007-04-26, 6:31 PM #47
you can probably imagine how i feel about python
2007-04-26, 6:57 PM #48
/me jumps on the bandwagon...

Code:
 #holy kak, this thing is nasty...
sub ParseTemplate 
{
	my ( $template, $params ) = @_;
	$params = MergeParams ( $params );
	$template =~ s/\[\(([\w\.]+)\)\]/OpenTemplate($1)/egm;
	$template =~ s/\{\{([\w\|]+)\}\}/ParseConditional($1,$params)/egm;
	$template =~ s/\[\[(\w+)\]\]/CheckRef($params->{$1})/egm;
	return $template;
}
And when the moment is right, I'm gonna fly a kite.
2007-04-26, 7:14 PM #49
I feel left out :(

Code:
function generateTimetable() {
	if (xmlhttp.readyState==4) {
		var response = xmlhttp.responseXML;
		if (!response.documentElement && xmlhttp.responseStream) {
		response.load(xmlhttp.responseStream);
		}

		var days = new Array('Monday','Tuesday','Wednesday','Thursday','Friday');

		for (day in days) {
			var currentclass = 0;
			var currentday = response.getElementsByTagName(days[day].toLowerCase());
			var classes = currentday[0].getElementsByTagName('class');

			var newRow = document.createElement('tr');

			for (var i=0;i<=20;i++) {
				var newCol = document.createElement('td');
				if (i == 0) {
					var textNode = document.createTextNode(days[day]);
					newCol.appendChild(textNode);
					newCol.className = 'headercell';
				}
				else if (classes[currentclass] != null) {
					if (i == timeToColNum(classes[currentclass].getElementsByTagName('start')[0].firstChild.nodeValue)) {
						newCol.colSpan=classes[currentclass].getElementsByTagName('duration')[0].firstChild.nodeValue/0.5;
				   		var vals = new Array(classes[currentclass].getElementsByTagName('name')[0].firstChild.nodeValue,classes[currentclass].getElementsByTagName('tutor')[0].firstChild.nodeValue,classes[currentclass].getElementsByTagName('type')[0].firstChild.nodeValue + ' in ' + classes[currentclass].getElementsByTagName('room')[0].firstChild.nodeValue);
				   		for (val in vals) {
					   		var text = document.createElement('p');
						    var textNode = document.createTextNode(vals[val]);
							text.appendChild(textNode);
							newCol.appendChild(text);
				   		}
						newCol.className = (classes[currentclass].getElementsByTagName('type')[0].firstChild.nodeValue == 'Lecture') ? 'lecture' : 'practical';
				   		i +=(classes[currentclass].getElementsByTagName('duration')[0].firstChild.nodeValue/0.5)-1;
				   		currentclass++;
					}
				}
				newRow.appendChild(newCol);
			}
			newRow.id = days[day].toLowerCase;
			var dayrow = document.getElementById(days[day].toLowerCase());
			dayrow.parentNode.replaceChild(newRow,dayrow);
		}
	}
}

function timeToColNum(time) {
	//convert time to the number of the column of that slot.
	//e.g. 9:30 becomes 2
	return (((time.split(':')[0] + '.' + (time.split(':')[1] == 30 ? 5 : 0))-9)*2)+1;
}


I should probably comment more :P
TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
k
WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
N
iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW
2007-04-26, 7:34 PM #50
Originally posted by gbk:
/me jumps on the bandwagon...

Code:
 #holy kak, this thing is nasty...
sub ParseTemplate 
{
	my ( $template, $params ) = @_;
	$params = MergeParams ( $params );
	$template =~ s/\[\(([\w\.]+)\)\]/OpenTemplate($1)/egm;
	$template =~ s/\{\{([\w\|]+)\}\}/ParseConditional($1,$params)/egm;
	$template =~ s/\[\[(\w+)\]\]/CheckRef($params->{$1})/egm;
	return $template;
}

I know! Perl is downright horrid!

:D

Edit:
Originally posted by TheJkWhoSaysNi:
I feel left out :(

Code

I should probably comment more :P

Do mine eyes spy a O(n[sup]3[/sup]) function?
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.
2007-04-26, 7:35 PM #51
perl is horrid, but this is not why
2007-04-26, 7:38 PM #52
Code:
Rectangle rectangle = new Rectangle(); /*Creates a rectangle*/

It's very unneeded. In fact, I usually don't comment, unless I'm supposed to for the assignment...
2007-04-26, 8:36 PM #53
Might as well.

Code:
void Gum::Widget::blit(Flat::Surface dest, int x, int y)
{
	if (!dest) return;
	if (!surf) return;
	if (flag_set(Gum::Flags::hidden)) return;
	
	Gum::Widget::clist local_children(children.begin(),children.end());

	if (!flag_set(Gum::Flags::no_blit) && is_dirty()) //if no blit, why waste time drawing yourself?
	{
		if (flag_set(Gum::Flags::clear)) Flat::fill_surface(surf,clear_color);
		if (custom) custom->on_redraw(surf);
		for (clist::iterator I = local_children.begin(); I != local_children.end(); ++I)
			if (!(*I)->flag_set(Gum::Flags::floating)) (*I)->blit(surf,(*I)->x,(*I)->y);
		if (flag_set(Gum::Flags::masked) && mask) Flat::blit(mask,surf,0,0,Flat::BlendFuncs::apply_alpha_mask);
		if (is_disabled()) Flat::filter_surface(surf,Flat::Filters::grayscale);
	}

	if (flag_set(Gum::Flags::no_blit)) //treat all children as floaters
		for (clist::iterator I = local_children.begin(); I != local_children.end(); ++I)
			(*I)->blit(dest,(*I)->x + x,(*I)->y + y);
	else
	{
		//if parent is dirty, we need to blit ourselves. 
		//if we are a floater, we need to blit ourselves.
		//if our parent is no_blit, we treat ourselves as a floater and blit ourselves.
		//But if dest == surf, we must be root, and shouldn't blit.
		if ( ( (parent && (parent->is_dirty() || parent->flag_set(Gum::Flags::no_blit))) 
				|| flag_set(Gum::Flags::floating) ) 
			&& dest != surf)
		{
			if (flag_set(Gum::Flags::fast_blit)) Flat::fast_blit(surf,dest,x,y);
			else Flat::blit(surf,dest,x,y,Flat::BlendFuncs::blend);
		}
		for (clist::iterator I = local_children.begin(); I != local_children.end(); ++I)
			if ((*I)->flag_set(Gum::Flags::floating)) (*I)->blit(dest,(*I)->x + x,(*I)->y + y);
	}

	set_flag(Gum::Flags::dirty,false);
	
	if (static_info->root == this)
	{
		int mx, my;
		Jemgine::Hand::query_mouse(mx,my);
		if (static_info->mouse_visible)
		{
			Flat::Surface mouse_graphic;
			if (static_info->hover && static_info->hover->custom)
			{
				int lx = mx;
				int ly = my;
				static_info->hover->resolve_to_local_coords(lx,ly);
				mouse_graphic = static_info->hover->custom->mouse_graphic(lx,ly);
			}
			Flat::fast_blit(
				mouse_graphic ? mouse_graphic : static_info->mouse_graphic,
				dest,
				mx,
				my);
		}
	}
}
Wikissassi sucks.
12

↑ Up to the top!