Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Optimus Prime Ribs
Jul 25, 2007

Golbez posted:

for ($NumberOfIterations = 0; $NumberOfIterations <= 100; $NumberOfIterations++) {

Surely you mean for ($CurrentPositionInIteration = 0; $CurrentPositionInIteration <= 100; $CurrentPositionInIteration++) {

Adbot
ADBOT LOVES YOU

1337JiveTurkey
Feb 17, 2005

In a modern IDE even if the method is some huge mess, syntax highlighting will tell you the scope so there's no need for any of that pFoo mBar fBuzz crap some ancient contractor left in the code that I'm trying to maintain right now. Getting the original declaration and associated comments are just a keystroke away and in a language with annotations it should display them as well. Annotations like @NotNull are far superior to some sort of naming convention that people may or may not follow.

ToxicFrog
Apr 26, 2008


Volte posted:

Unless you're in some kind of untyped wasteland, that sort of naming convention is completely useless. That's not even Hungarian notation. Hungarian notation affixes some kind of meaningful descriptor to the variable (like cnt for counter, fh for file handle, etc), not the type.

There's "apps hungarian" (which is what you describe) and "systems hungarian". The former did in fact originate in an "untyped wasteland" but got carried over into the MS Applications team (hence the name). The popular one, however - and the one most people mean when they say "hungarian notation" - is systems hungarian, which just prefixes each variable name with the language type of the variable.

And yes, it is completely useless. That's why everyone hates it.

Bunny Cuddlin
Dec 12, 2004

Optimus Prime Ribs posted:

Surely you mean for ($CurrentPositionInIteration = 0; $CurrentPositionInIteration <= 100; $CurrentPositionInIteration++) {

a lot of for loops in the codebase where I work have (int ii = 0; ii < whatever; ii++) and I just realized why this is.

Opinion Haver
Apr 9, 2007

1337JiveTurkey posted:

In a modern IDE even if the method is some huge mess, syntax highlighting will tell you the scope so there's no need for any of that pFoo mBar fBuzz crap some ancient contractor left in the code that I'm trying to maintain right now. Getting the original declaration and associated comments are just a keystroke away and in a language with annotations it should display them as well. Annotations like @NotNull are far superior to some sort of naming convention that people may or may not follow.

How much do you want to bet that Perl scope is undecidable?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

yaoi prophet posted:

How much do you want to bet that Perl scope is undecidable?

It's perfectly decidable outside of contrived examples where a BEGIN block may or may not alter how something parses.

Opinion Haver
Apr 9, 2007

Jabor posted:

It's perfectly decidable outside of contrived examples where a BEGIN block may or may not alter how something parses.

I mean, given that parsing it in general is undecidable I figured it wouldn't be that much of a stretch.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

yaoi prophet posted:

I mean, given that parsing it in general is undecidable I figured it wouldn't be that much of a stretch.

perl parses Perl just fine - I think I already mentioned that the only undecidable cases are contrived examples where executing a BEGIN block can change how it parses.

Pretty much the same thing as how executing preprocessor statements can change how a piece of C parses, really.

fritz
Jul 26, 2003

Bunny Cuddlin posted:

a lot of for loops in the codebase where I work have (int ii = 0; ii < whatever; ii++) and I just realized why this is.

If you haven't done that yourself, you haven't written enough scientific code.

Bunny Cuddlin
Dec 12, 2004

fritz posted:

If you haven't done that yourself, you haven't written enough scientific code.

I'm not sure what you mean, but what I mean is they're using Hungarian notation on the temporary integer i by prefixing it with i, thus making.. ii.

They use Systems Hungarian everywhere else so I'm fairly sure this is what's going on.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Bunny Cuddlin posted:

I'm not sure what you mean, but what I mean is they're using Hungarian notation on the temporary integer i by prefixing it with i, thus making.. ii.

They use Systems Hungarian everywhere else so I'm fairly sure this is what's going on.

Scientific research code is notoriously horrible in quality.

A great deal of it is still written in forth, and is written by researchers, not developers.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Zombywuf posted:

The default encoding of ISO-8859-1 was set back in the dawn of time before the UTF encodings were hewn from the very rock of the IETF standards mines.

(i.e. no-one could be bothered implementing unicode back in the day when the internet was a lot more racist and changing it is hard)

And by this you mean "the default encoding of ISO-8859-1 except when we decide to send windows-1252 without telling anyone because we thought it was the same thing".

Opinion Haver
Apr 9, 2007

Jabor posted:

perl parses Perl just fine - I think I already mentioned that the only undecidable cases are contrived examples where executing a BEGIN block can change how it parses.

This is the coding horror thread, what makes you think I care about the contrivedness of any examples? :v:

fritz
Jul 26, 2003

Bunny Cuddlin posted:

I'm not sure what you mean, but what I mean is they're using Hungarian notation on the temporary integer i by prefixing it with i, thus making.. ii.

They use Systems Hungarian everywhere else so I'm fairly sure this is what's going on.

What I mean is your indexing variables go i, j, k, then ii, jj, kk, and then maybe iii, etc.

Goat Bastard
Oct 20, 2004

fritz posted:

What I mean is your indexing variables go i, j, k, then ii, jj, kk, and then maybe iii, etc.

Does scientific code not have functions or something?

Just kidding, why would it?

hobbesmaster
Jan 28, 2008

Goat Bastard posted:

Does scientific code not have functions or something?

Just kidding, why would it?

Functions would just slow things down!

Qwertycoatl
Dec 31, 2008

Bunny Cuddlin posted:

a lot of for loops in the codebase where I work have (int ii = 0; ii < whatever; ii++) and I just realized why this is.

I'd have thought it was so someone could search for 'ii' and find the loop variable, rather than trying to search for 'i' and finding every drat thing.

Opinion Haver
Apr 9, 2007

So search for \bi\b instead unless you're using a text editor so lovely that it doesn't support regex search. In which case, get a better editor, and then search for \bi\b.

That Turkey Story
Mar 30, 2003

fritz posted:

If you haven't done that yourself, you haven't written enough scientific code.

Maybe if that language doesn't support high-order functions.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
If you're using functions you haven't written enough scientific code

1337JiveTurkey
Feb 17, 2005

yaoi prophet posted:

How much do you want to bet that Perl scope is undecidable?

I don't have much experience with perl in particular, but given that members of objects in other dynamic languages can be path dependent, my gut feeling goes towards undecidable.

Zombywuf
Mar 29, 2008

pokeyman posted:

And by this you mean "the default encoding of ISO-8859-1 except when we decide to send windows-1252 without telling anyone because we thought it was the same thing".

That's only Microsoft. Given that Microsoft's contributions to HTTP 2 have involved a submission describing upgrading a HTTP 1.1 connection to SPDY using both an UPGRADE response and websockets (only needing two additional headers) I think we can ignore their technical contributions here.

movax
Aug 30, 2008

Otto Skorzeny posted:

Asked the apps engineer at $chip_vendor that is writing their optimization guide if he had a recommendation for a profiler.




:ughh:

It's the vendor in your title isn't it?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

movax posted:

It's the vendor in your title isn't it?

Yes :(


:3: someone bought me a title

nielsm
Jun 1, 2009



Ugh, I need to vent about this thing I'm working on atm. It's not really an unusual WTF, it's just that I haven't worked on many old projects yet.

Zend Framework. Well it's PHP, the documentation for it is terrible, but it kinda works. However the things built onto it in this application makes me want to scream. Inverted responsibilities all over the places. Superclasses that are certainly "super", they contain half the functionality of all the classes derived from them. There is a single class derived from Zend_Db_Table which all of our custom database table classes then derive from in turn, and that intermediate class has all kinds of checks for "what actual class was this method called on", doing various kinds of magic depending on that.
I also just found a magic method pushed away in a corner that contains what seems to be a re-duplication of most of the collecting data for the frontend, except it's in another intermediate class, does everything slightly differently, and uses this pattern:

PHP code:
function getStuff()
{
  $errorReporting = error_reporting();
  error_reporting(0);

  //... entire body of method

  error_reporting($errorReporting);
}
:psypop: :smithicide:

Doctor w-rw-rw-
Jun 24, 2008

Well it's that or Symfony. Both have 2.0 versions now, though. I assume you're on 1.x?

ephphatha
Dec 18, 2009




BiohazrD posted:

code:
private Dictionary<CustomerInfo, Dictionary<string, List<FeedbackData>>> m_Database;
I wrote this. I'm so sorry.

I nearly was responsible for a horror like this :smith:.

Had a program I was writing that needed to save/load the current value of about 20 different types of control.

code:
	this->ui.aCheckBox->setChecked(settings.value(this->ui.aCheckBox->accessibleName(), this->ui.aCheckBox->isChecked()).toBool());
	this->ui.bCheckBox->setChecked(settings.value(this->ui.bCheckBox->accessibleName(), this->ui.bCheckBox->isChecked()).toBool());
	this->ui.abLinkButton->setChecked(settings.value(this->ui.abLinkButton->accessibleName(), this->ui.abLinkButton->isChecked()).toBool());
	this->abLinkToggled(this->ui.abLinkButton->isChecked());
(Repeat for 90 lines).

I thought "I could probably simplify this by using macros. Wait, I'm using C++, lets use an inline template function!"

So I wrote something like this: (Recreated from memory, I actually had it to a compilable state with proper types specified)
code:
template<typename T, typename U, typename V> loadValue(T control, QSettings settings, boost::function<T, U> setter, boost::function<T> getter, boost::function<QVariant, V> caster)
{
  setter(control, caster(settings.value(control->accessibleName(), getter(control))));
}
Which would have been called like so:
code:
loadValue(this->ui.aCheckBox, settings, boost::bind(&(this->ui.aCheckBox->setChecked), $1, $2), boost::bind(&(this->ui.aCheckBox->isChecked), $1), boost::bind(&(QVariant.toBool), $1, $2));
(Again, the actual implementation compiled and was much more horrible.)

About that time I realised what I was doing and nuked the loving thing.

Jewel
May 2, 2009

Star War Sex Parrot posted:

Of course you do.

I actually really enjoy the atmosphere and posts of yospos (especially that thread, holy poo poo is it great) but I'm afraid I'd be chewed up or something so I never post. Maybe one day :allears:

movax
Aug 30, 2008

Ephphatha posted:

I nearly was responsible for a horror like this :smith:.

Had a program I was writing that needed to save/load the current value of about 20 different types of control.

code:
	this->ui.aCheckBox->setChecked(settings.value(this->ui.aCheckBox->accessibleName(), this->ui.aCheckBox->isChecked()).toBool());
	this->ui.bCheckBox->setChecked(settings.value(this->ui.bCheckBox->accessibleName(), this->ui.bCheckBox->isChecked()).toBool());
	this->ui.abLinkButton->setChecked(settings.value(this->ui.abLinkButton->accessibleName(), this->ui.abLinkButton->isChecked()).toBool());
	this->abLinkToggled(this->ui.abLinkButton->isChecked());
(Repeat for 90 lines).

I thought "I could probably simplify this by using macros. Wait, I'm using C++, lets use an inline template function!"

So what's the "right" way to do this?

hobbesmaster
Jan 28, 2008

movax posted:

So what's the "right" way to do this?

Well if you have a bunch of different controls you have no option other than to hit each one to save them. If you are doing the same operation on a type of control then you can split that out into a function. Some frameworks automate this type of stuff for you.

Crazy Mike
Sep 16, 2005

Now with 25% more kimchee.
As my office switches to .NET, eventually we are going to have a talk about new naming conventions. Our current variable naming convention is <scope><datatype>_variablename like string ls_user_name or long ll select_count or boolean ib_read_only. What is the argument against having scope and datatype in your variable names?

If I have a variable in a method, how can I tell if it belongs to the method or the class if it is not prefixed with a 'l' for local or an 'i' for instance? (Apparently right-click, go to definition isn't the answer.)

Is using the m_ prefix for your fields the answer? It makes sense although all the books I see have private camelCase fields and public PascalCase properties instead. As the most junior programmer here I have a feeling any argument I give will not be enough to sway opinion, but since most of you seem opposed to it, I would at least like to know why.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

movax posted:

So what's the "right" way to do this?

Probably writing a new class to manage it, so even if the code is awful, it's awful in one place and everywhere else can interact with a nice API.

Jewel posted:

I actually really enjoy the atmosphere and posts of yospos (especially that thread, holy poo poo is it great) but I'm afraid I'd be chewed up or something so I never post. Maybe one day :allears:

Nobody's criticism actually matters in yospos, if you get chewed out ignore it and post post post.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Crazy Mike posted:

What is the argument against having scope and datatype in your variable names?

You're using an IDE that tells you all of that information instantly. Putting it in the variable name is at best redundant and at worst incorrect, when you realize that dbl_Foo is actually float_Foo.

If you're moving to .NET, just follow Microsoft's Naming Conventions and Guidelines for Names. Install ReSharper and/or StyleCop on everyone's dev environments to help enforce it. Problem solved.

[edit]
Visual Studio will show you the scope and type of a variable if you hover the mouse over it.

New Yorp New Yorp fucked around with this message at 19:16 on Dec 7, 2012

nielsm
Jun 1, 2009



Crazy Mike posted:

What is the argument against having scope and datatype in your variable names?

Plorkyeran posted:

In general I am of the opinion that if marking the scope of variables in their names is ever useful then you have far too many things in scope.

And if it would be a major pain to scroll to find where a variable is declared, then your function/class is likely getting too long.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
I like marking globals by prepending them with g_ to make them feel dirty (as they should) :engleft:

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I like marking globals by prepending them with //

Amarkov
Jun 21, 2010
Just use Java so globals are impossible to define :colbert:

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Amarkov posted:

Just use Java so globals are impossible to define :colbert:

Java code:
public static String g_String = "heh";

Amarkov
Jun 21, 2010
Nope, not in the global namespace so it doesn't count.

(Don't you dare import *)

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



Amarkov posted:

Just use Java so globals are impossible to define :colbert:

Just use BASIC so you don't have to worry about which scope to place your variables in. (Also gets your type markers on variable names for free!)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply