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
hey mom its 420
May 12, 2007

Unless the requirements of your problem explicitly state several conditions on which different things occur, there's almost always a more elegant way than using big if else trees or big switch statements.

Adbot
ADBOT LOVES YOU

haveblue
Aug 15, 2005
Probation
Can't post for 3 hours!
Toilet Rascal
Aren't case statements faster than long else-if chains?

hey mom its 420
May 12, 2007

I doubt you'd find any noticeable performance difference either way.

Vanadium
Jan 8, 2005

chocojosh posted:

1) The standard of using only up to 80 columns seems to be quite outdated. I had a prof who actually took off marks for this. My monitor supports up to 140 columns (visual studio 2003) at the default font and 1280*1024 resolution. Now, I know different people use different text editors, different font sizes, and so on, but could we please update the standard to 120/130? And then actually ENFORCE it so that I don't have to read stored procedures with lines of 200+ characters.

No, mail software still breaks at ~80 characters and terminals and consoles and whatever are still 80 characters in width. :shobon:

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

chocojosh posted:

Josh's random thoughts of the days while working on "Yet another boring web page in this enterprise application".

1) The standard of using only up to 80 columns seems to be quite outdated. I had a prof who actually took off marks for this. My monitor supports up to 140 columns (visual studio 2003) at the default font and 1280*1024 resolution. Now, I know different people use different text editors, different font sizes, and so on, but could we please update the standard to 120/130? And then actually ENFORCE it so that I don't have to read stored procedures with lines of 200+ characters.

No, absolutely not. If the file took the entire width of the screen you couldn't put two files side-by-side for comparison.

quote:

2) Is it normal that I don't use switch statements? I just find if/else if/else if/else much easier to read and less verbose than a switch statement. The only time I have used a switch statement is for a WinMain loop.. and that's because it's the convention I see everywhere.

As long as you're not repeating an expression in every test, that's fine.

HB posted:

Aren't case statements faster than long else-if chains?

No, because the compiler's perfectly capable of optimizing.

JoeNotCharles fucked around with this message at 17:26 on May 29, 2008

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

6174 posted:

There is probably a better way to do it, but you could do something like
code:
mv `ls -t1 DHR* | head -n 1` newdir/DHR.xls
The -t1 on ls sorts by last modified and puts the resulting files each on their own line. Since you want the most recent only, you take the first line of the results, hence the head command. Finally that is back tick escaped so it will execute before the mv command.

That checks the actual time the file was written, though - I think he wanted to sort by the date in the filename. (Makes a difference if the whole thing was backed up or copied, for instance, which might give them all the same last modified date.)

6174
Dec 4, 2004

JoeNotCharles posted:

That checks the actual time the file was written, though - I think he wanted to sort by the date in the filename. (Makes a difference if the whole thing was backed up or copied, for instance, which might give them all the same last modified date.)

Very true. To do it based on filename would potentially be much more complicated based on how the files are actually named.

other people
Jun 27, 2004
Associate Christ

JoeNotCharles posted:

Unless you're already really familiar with databases, I wouldn't bother with that. If it's low-volume enough that you can do it by hand right now you should be able to just store the .csv files somewhere and read them each time you want to process them. Python has an excellent CSV parsing module - I'd just save the .csv file into a directory tree organized by date, and write a Python script to read them and calculate stats.

EDIT: it all depends on what tools you're familiar with. If you already have some experience with databases, import the .csv files into SQLite (so you don't need to run a server or anything); if you're good with Excel macros, import them into that. I'm most familiar with programming/Python scripting, so that's what came to mind first.

The two languages I feel safe working in are php and python. My python experience is mostly with personal scripts to organize files and other assorted random things. I've never done anything too advanced with it related to sets of data and thing like that. I'm not even sure you can have a list as a value in another list?

More importantly, I have never done anything beyond simple console output with python. While I will probably be the person using this program the most, I would like it to be usable by others at work. A dos prompt will surely scare them off.

So that leaves me with php and some sort of web interface. Certainly not the best tool for the job, but doable, eh? I am not so sure about storing things in a db.

Gingerbread Wife
Dec 28, 2003

~*~ iM At ThE mOtHeRfUcKiN sToP n Go ~*~

JoeNotCharles posted:

That checks the actual time the file was written, though - I think he wanted to sort by the date in the filename. (Makes a difference if the whole thing was backed up or copied, for instance, which might give them all the same last modified date.)

It actually doesn't matter which one is used. As soon as the file is created and given the file name, it is placed in that directory and is not backed up or archived until this potential script is run. Doing it based on the time the file was written is fine.

I have yet to test that script out, but does that look like the best way to do it? Does anyone else have any other suggestions?

1550NM
Aug 31, 2004
Frossen fisk
I need advice on what to use to implement a program for managing participants, teams, various shooting classes, generating score tables etc for an shooting sport I'm involved in, what out there today is old and outdated, or is ill suited for what we're doing.

I'm currently set on learning a language, and had for some time been looking for a project to involve me in to really get into it, I have currently been dabbeling in Python which I really like but isn't entirely sure is the the right choice for this.

I have also looked a bit into using Visual Studio 2008 (Express), which gives me some
really nice tools for setting up the GUI, but precludes me from say using SQLite and
necessitates that I either learn C# or VB from scratch.

Is necessarily using some form of database for data storage a smart choice ?, I envisions that I need to
store about 2-3 fields of data for each participants(name,club,shorthandname),30-40 fields for scores for each participants for each shootingprogram(name, club, class, team, shootingprogram, targetgroup1(shots,subtarget,sum,weightedtarget)-10 etc) and some change.

Any advice would be of great help here.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Vanadium posted:

No, mail software still breaks at ~80 characters and terminals and consoles and whatever are still 80 characters in width. :shobon:
1) Mail software shouldn't edit e-mails after I tell it to send. 2) Unless you're talking about actual, physical teletypwriters, the width can easily be changed.

fankey
Aug 31, 2001

Is anyone aware of any algorithms that will generate nice looking gradients given a base color for buttons and whatnot ( Web 2.0! )? I've played with converting to HSV and then adjusting the saturation and value for the different stops of the gradient but it's a little tweaky - either the adjustment values work well for light desaturated colors or they work well for fully saturated ones, not both.

Right now I'm doing something like
code:
GradientStops.Add( Base.H, Base.S * 0.4, Base.V, 0.0 )
GradientStops.Add( Base.H, Base.S * 0.97, Base.V, 0.375 )
GradientStops.Add( Base.H, Base.S, Base.V, 0.375 )
GradientStops.Add( Base.H, Base.S, Base.V * 0.5, 1.0 )

Tomed2000
Jun 24, 2002

I don't know if this thread is the best place to ask this but:

What is the most common programming environment in the industry? By that I mean is it most common that you will be working in a Unix/Linux environment with some editor like Emacs are is it more common to have a Windows environment with something like Visual Studio?

csammis
Aug 26, 2003

Mental Institution

Tomed2000 posted:

I don't know if this thread is the best place to ask this but:

What is the most common programming environment in the industry? By that I mean is it most common that you will be working in a Unix/Linux environment with some editor like Emacs are is it more common to have a Windows environment with something like Visual Studio?

Because every part of this industry uses the exact same tool for everything :eng99:

edit: Seriously what kind of question is that? In my last job, one tiny part of "the industry," we used three commercial IDEs and one proprietary, and then some people used other stuff if they wanted to / were allowed to.

csammis fucked around with this message at 19:20 on May 30, 2008

tef
May 30, 2004

-> some l-system crap ->
If you are trying to pick the toolset to learn so as to aid your course in industry, pick the buggiest, most frustrating toolkit you can find. The patience you develop will be a useful skill.

Tomed2000
Jun 24, 2002

tef posted:

If you are trying to pick the toolset to learn so as to aid your course in industry, pick the buggiest, most frustrating toolkit you can find. The patience you develop will be a useful skill.

I'm not, just a student right now. I was having a conversation with a professor and he claims that 90% of the industry programs in a UNIX environment and I thought that was pretty inaccurate.

more falafel please
Feb 26, 2005

forums poster

Tomed2000 posted:

I'm not, just a student right now. I was having a conversation with a professor and he claims that 90% of the industry programs in a UNIX environment and I thought that was pretty inaccurate.

90% is inaccurate. But if you're doing web development, for instance, you can often work in whatever environment you want to, so many shops leave it open. If you're writing Java for a big iron machine, it doesn't matter if the development platform is Windows, OS X, Linux, whatever, if it runs Java it's probably a legitimate dev environment. For scripting languages (PHP, Python, Perl, Ruby) it doesn't really matter either, especially since it's probably only going to be run on the servers, not on your dev machine. In this case, your dev machine is essentially a text editor.

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>

Tomed2000 posted:

I'm not, just a student right now. I was having a conversation with a professor and he claims that 90% of the industry programs in a UNIX environment and I thought that was pretty inaccurate.

If he knows so much about the industry why doesn't he work there?

Incoherence
May 22, 2004

POYO AND TEAR

Tomed2000 posted:

I'm not, just a student right now. I was having a conversation with a professor and he claims that 90% of the industry programs in a UNIX environment and I thought that was pretty inaccurate.
It's a pretty broad brush you're painting with either way, and ideally you'd have some familiarity with different environments and the ability to pick up whatever one you find yourself in. And for some applications it doesn't matter what your environment is, so you can use whatever you want.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
My vague impression (not counting web development, since I know nothing about it):

- on Windows, absolutely everybody uses Visual Studio, except the Java people who use Eclipse
- on Mac, 80% of people use Xcode and the other 20% are Unix refugees who use command-line tools
- on Unix, it's very fragmented: some people use Eclipse (even for non-Java stuff), some people use KDevelop, some people use specialized IDE's for their own particular task or language, but probably a majority use the commandline and VIM or Emacs.

I would say Windows is still the most common, followed by Unix and then Mac trailing way behind.

If you're wondering which to start with, I'd recommend learning on the command line on Mac or Linux, because then Visual Studio/Xcode/whatever is just one more front-end instead of being the only way you know where to work. It's a lot harder moving the other way if you're used to Visual Studio doing a whole bunch of the work for you.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

JoeNotCharles posted:

If you're wondering which to start with, I'd recommend learning on the command line on Mac or Linux, because then Visual Studio/Xcode/whatever is just one more front-end instead of being the only way you know where to work. It's a lot harder moving the other way if you're used to Visual Studio doing a whole bunch of the work for you.

On the other hand, I for one would rather sit down and start coding instead of memorizing command line tools and other crap that stand between the program in my mind and the program-to-be on the computer. Plus, I love Visual Studio, so I'm biased here. I guess if you really love command line stuff, go for it, it certainly won't make you dumber.

E: VVV Really, such as? File->New Project too much? I think it's pretty intuitive.

Factor Mystic fucked around with this message at 01:41 on May 31, 2008

Vanadium
Jan 8, 2005

Factor Mystic posted:

On the other hand, I for one would rather sit down and start coding instead of memorizing command line tools and other crap that stand between the program in my mind and the program-to-be on the computer.

I for one would rather sit down and start coding instead of memorizing Visual Studio stuff that stands between the program in my mind and the program-to-be on the computer. :colbert:

Incoherence
May 22, 2004

POYO AND TEAR

Vanadium posted:

I for one would rather sit down and start coding instead of memorizing Visual Studio stuff that stands between the program in my mind and the program-to-be on the computer. :colbert:
Visual Studio is not so bad about this. Eclipse is rather bad about this unless you already think in Eclipse.

more falafel please
Feb 26, 2005

forums poster

Factor Mystic posted:

On the other hand, I for one would rather sit down and start coding instead of memorizing command line tools and other crap that stand between the program in my mind and the program-to-be on the computer. Plus, I love Visual Studio, so I'm biased here. I guess if you really love command line stuff, go for it, it certainly won't make you dumber.

E: VVV Really, such as? File->New Project too much? I think it's pretty intuitive.

With C++ at least, I never actually understood the build process, linking model, and even aspects of the language until I stopped using IDEs. It was only then that I understood what a "translation unit" was, really. In my opinion, going from command line to IDE is easier than the other way around, and I'm glad I can work in both environments.

JingleBells
Jan 7, 2007

Oh what fun it is to see the Harriers win away!

more falafel please posted:

With C++ at least, I never actually understood the build process, linking model, and even aspects of the language until I stopped using IDEs. It was only then that I understood what a "translation unit" was, really. In my opinion, going from command line to IDE is easier than the other way around, and I'm glad I can work in both environments.

As a java programmer I whole heartedly agree, at university we had to make sure our applications ran from the command line which put us in good stead. I always make sure my ant scripts run from the command line when writing stuff, and if I'm building small stuff or open source apps, I generally just use ant/maven from the command line, instead of faffing around with setting up a new project in eclipse/netbeans.

poopiehead
Oct 6, 2004

How can you make a program that runs in eclipse but doesn't run on the command line? Or do you just mean that you, personally, had to know how to build and run it?

JingleBells
Jan 7, 2007

Oh what fun it is to see the Harriers win away!

poopiehead posted:

How can you make a program that runs in eclipse but doesn't run on the command line? Or do you just mean that you, personally, had to know how to build and run it?

What I mean is that running from the command line you have to set the classpath up properly, you don't just go into a gui and locate your libraries. You also learn about some of the command options you can pass to java / javac. I'd certainly recommend learning java from the command line and moving up to an IDE. On my last project our client took the code in source form and built it on their own enviroments by calling the ant script from the command line, so it was important to ensure that the script ran outside of an IDE.

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.
I have a question about automake. My program's source code includes a header file which is automatically derived from another file by a Perl script. I want make to run the Perl script whenever the derived header file is out-of-date (i.e. when its modification timestamp is earlier the one on the file it is derived from). How do I do this?

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Mr.Radar posted:

I have a question about automake. My program's source code includes a header file which is automatically derived from another file by a Perl script. I want make to run the Perl script whenever the derived header file is out-of-date (i.e. when its modification timestamp is earlier the one on the file it is derived from). How do I do this?

Have a rule that creates the header file from the other_file, and has the header file depend on both the script and other_file:

code:
header_file: script other_file
        perl script other_file > header_file
make uses timestamps to figure out which files are out of date, so you get that last part for free.

ffuzz
Jul 8, 2004
My end goal is to have a Character or 128x64 Graphical LCD to display information from a headless Linux box through a USB Port.

The LCD will display information about attached USB Devices, and update when devices are plugged/unplugged (or soon thereafter). To start, something along the lines of 'lsusb | grep "XXXX"' listed on the LCD, or even the number of attached usb devices would work. Maybe thats not the right way to do it, i dont know! It just needs to be similar to a terminate-stay-resident or "service" in windows. Something that is always running in the background and kicks out new jams whenever the usb tree changes.

The LCD Display needs to be accessible via USB (or USB->Serial). I think something similar to this would work if I could find Linux drivers for it.

Here are the problems:

1. Ive never written anything for linux before. I dont even know where to start! I apt-got the poo poo out of build-essential on my ubuntu desktop but I don't know if something I build there will be able to run on the plain-old-debian-slimmed-down-headless target box.

2. Ive never written anything USB or hardware related.

Is this as easy as doing something or other with cron and lsusb and grep and routing it to serial somehow?

Pretty much I have no idea where to begin, and I'm looking for guidance on what to read up on.

Thanks in advance!

Atltais
May 21, 2004
And there was much rejoicing.
What's the easiest way of getting the terminal type from a remote client in a telnet session?

tef
May 30, 2004

-> some l-system crap ->

Atltais posted:

What's the easiest way of getting the terminal type from a remote client in a telnet session?

the TERM variable, try echo $TERM, however many terminals lie.

Atltais
May 21, 2004
And there was much rejoicing.

tef posted:

the TERM variable, try echo $TERM, however many terminals lie.

I meant more along the lines of the server poking the client for terminal information. Sorry if I wasn't clear enough.

ColdSnickersBar
Apr 7, 2005

I'm resigning to make myself more OO disciplined, and trying to follow perfect encapsulation. I'm making a video game that has a mysql backend. In the video game, hackers move about systems, and these systems are in regions.

I have the following class hierarchy:


The Region class has a SystemCollection object, a database id, and a name

The SystemCollection class has only a collection of Systems objects

The System object has details about systems


I'm making a method in the System class that procedurally creates itself. The Region object is told to make a region of random systems, it tells the system collection object to generate a random collection of systems, and the system object generates itself.

The problem is that the system table in the DB has to have a region id. When the system creates itself, it needs to not only record its region id, but also it needs to use a different generation algorithm depending on what region the system belongs in.

I'm having a hard time figuring out a best practice for this.

Here's some ideas that just don't sound right:

1. Have the region id passed along the hierarchy, and then the system object evaluates the id and selects an algorithm. I hate this idea.

2. Have the region object reference passed along the hierarchy, have the actual algorithm in the region class, and have the system object call the method from the region it receives, and record the database id from the region class itself. Different region classes inherit from a base region class, so the algorithm can be completely unique to the region. This sounds like it's not proper encapsulation. I don't know why this sounds wrong to me, but it does.

Keep in mind that I'm trying to keep good OO discipline in this project. I don't want to ask any getters for information - I only want to tell objects to do something, and have the object figure it out itself.

ColdSnickersBar fucked around with this message at 18:09 on Jun 3, 2008

TSDK
Nov 24, 2003

I got a wooden uploading this one
Create a base class for system generation algorithms. The region instances a derived class for a randomly selected generation algorithm and passes it to the system. The system then uses that algorithm to perform the generation.

ColdSnickersBar
Apr 7, 2005

Okay, so, kind of like this:

code:
abstract class Generator

class FagGenerator inherits Generator
{
(has algorithm for the fag region)
}

abstract class Region
{
(has basic region stuff)
SystemCollection systems;
Generator algorithm;
abstract function generateSystem();
}

class FagRegion inherits Region
function FagRegion()
{
this.algorithm = new FagGenerator();
}
function generateSystem()
{
systems.generateSystem(this.algorithm);
}

And that gets passed down eventually to the System object that executes the algorithm it's given. I like that solution.

ColdSnickersBar fucked around with this message at 19:27 on Jun 3, 2008

TSDK
Nov 24, 2003

I got a wooden uploading this one

ColdSnickersBar posted:

Okay, so, kind of like this:
Not quite. You'll end up with one region class per generator and one generator class per algorithm. You should be looking to end up with one Region class, one System class and one concrete Generator class per algorithm (ignore the SystemCollection class for now, that should just be a dumb container and not have any 'intelligence' built in). There are dozens of different styles you could choose to implement this, and none of them are particularly more 'correct' than the others.

Here are a few style suggestions:

1) Generator used to parameterise a common construction template:
code:
class Generator
{
    virtual blah DoSomething1() = 0;
    virtual blah DoSomething2() = 0;
};
class GeneratorFoo : Generator { ... };
class GeneratorBar : Generator { ... };
class GeneratorBaz : Generator { ... };

class System
{
    void System( Generator *p_gen )
    {
        m_what = p_gen->DoSomething1();
        if ( p_gen->DoSomething2() )
        {
            ...
        }
    }
};

class Region
{
    void Region()
    {
        for ( num_systems )
        {
            Generator *p_gen = CreateRandomGenerator();
            m_systems.Add( new System( p_gen ) );
            delete p_gen;
        }
    }
    Colection< System * > m_systems;
};
This assumes that there are a lot of common elements of System construction that should be shared, and that System itself is a relatively self-contained and complex class. It also assumes that the algorithm can be sufficiently generalised.

2) Generator used to build Systems wholesale:
code:
class System
{
    void Setter1( int  );
    void Setter2( int  );
};

class Generator
{
    virtual System *CreateSystem() = 0;
};
class GeneratorFoo : Generator { ... };
class GeneratorBar : Generator { ... };
class GeneratorBaz : Generator { ... };

class Region
{
    void Region()
    {
        for ( num_systems )
        {
            Generator *p_gen = CreateRandomGenerator();
            m_systems.Add( p_gen->CreateSystem() );
            delete p_gen;
        }
    }
    Colection< System * > m_systems;
};
This is treating the System objects more like dumb value types and is placing more of an emphasis on the generation algorithm than the 'intelligence' or complexity in the System class.

3) Inheritance-is-king 90's style Systems:
code:
class System
{
    void System( Generator *p_gen )
    {
        m_what = DoSomething1();
        if ( DoSomething2() )
        {
            ...
        }
    }

    virtual blah DoSomething1() = 0;
    virtual blah DoSomething2() = 0;
};

class SystemFoo : System { ... };
class SystemBar : System { ... };
class SystemBaz : System { ... };

class Region
{
    void Region()
    {
        for ( num_systems )
        {
            m_systems.Add( CreateRandomSystem() );
        }
    }
    Colection< System * > m_systems;
};
Note that this is similar to style 1, except that concrete classes derived from System take place of the Generator classes. The difference between these two styles is that it implies that there's quite a tight coupling between the generation algorithm and the internals of the System base class.


Take your pick, or make your own, YMMV.

Lexical Unit
Sep 16, 2003

bash:

let's say I've got a command that returns a list of files, something like this:

foobar -xvfzw

And I want to iterate over this list of files in a for loop:

for I in `foobar -xvfzw`; do ...; done

But this doesn't work when some files have spaces in their names. Like if I have a file called "this is a test" then the for loop iterates over the values this, is, a, test in order.


So in general, how do I write a loop like this in such a way that I get correct values for $I when dealing with the possibility of files with spaces in them?

6174
Dec 4, 2004

Lexical Unit posted:

So in general, how do I write a loop like this in such a way that I get correct values for $I when dealing with the possibility of files with spaces in them?

See points 1 and 2 at http://wooledge.org:8000/BashPitfalls

Adbot
ADBOT LOVES YOU

Lexical Unit
Sep 16, 2003

I'm aware of both of those pitfalls. I am using "$I" but the problem is that the values of $I are given "this", "is", "a", and "test". Not "this is a test".

I'm also aware of the tricky hack that let's you do things like for I in *.ext; ... instead of using ls. My problem is that I'm not trying to use ls. Like I said, I want a general solution that I can apply to any possible command, here symbolized by the hypothetical foobar command. In other words, the solution that replaces `ls *.ext` with *.ext is not a solution to my problem.

Edit: To clarify further...

You have this situation:
code:
$ foobar -pants
this is a test
file1
file2
Write a bash script that iterates over the result of evaluating the command foobar -pants such that "this is a test" is a single value, not four consecutive values.

Lexical Unit fucked around with this message at 21:08 on Jun 3, 2008

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