Archive for the ‘Dev’ Category

Posted by Tatyana at 6 February 2012

Category: Dev, Java

Tags: , , , , , , , ,

Controllers in Spring MVC are desined to be shared between requests. Each controller has a default singleton scope so if you are using controllers you neeed to be aware of that. The easiest way to make sure your controller is thread-safe is to not to have class variables. F.ex. this example from Spring MVC tutorial:

@Controller
@RequestMapping("/editPet.do")
public class EditPetForm {

    private final Clinic clinic;

    public EditPetForm(Clinic clinic) {
        this.clinic = clinic;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(@RequestParam("petId") int petId, ModelMap model) {
        Pet pet = this.clinic.loadPet(petId);
        model.addAttribute("pet", pet);
        return "petForm";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(
            @ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {

        new PetValidator().validate(pet, result);
        if (result.hasErrors()) {
            return "petForm";
        }
        else {
            this.clinic.storePet(pet);
            status.setComplete();
            return "redirect:owner.do?ownerId=" + pet.getOwner().getId();
        }
    }
}

In this example we can have a serious issue regarding thread-safety: private variable clinic. If there will be a situation where to different requests access the controller simultaniously, one of them will instanciate the controller and begin to process a form, then the other one comes inn. The result from processing of the first request will be sent to the other one, thus the requests receive fail data or nothing.

The solution to the problem may be the following:
1. Annotate Controller with @Scope(“request”) or @Scope(“session”)
2. Move private variable into one of the methods or save it in session or model.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 12 January 2012

Category: Dev, Java

Tags: , , , , ,

Well, maybe not in theory, but in practice – definitely.

Test-drive development is a way to program where you write an automated unit test that fails first, then you write code and check that the test runs ok. Brilliant theory for an ideal world (doesn’t exist). In practice however it is very seldom that you as a programmer have a full and clear understanding of what is it you are gonna do.

Of course I’m not talking about cases where you need to calculate the result of 2+2. Sure you can write a test case here.

And here comes a hard reality where you come to the real place, f.ex. a bank that needs a new program. And here you are with a task that states smth like this “Create a form that have these and these fields and calculates that and that”. You begin with a test case? You are right! That’s what happens if you do this: you kill several days  trying to understand how you build this test case, what fields you need to fill inn to calculate the result. If you’ll try to check a more specific result then you need several extra days to find a person who maybe knows how the value must be calculated.

Because it is very seldom in the real world that programmers work together with persons who both know and can explain to the programmer how the things should be done. Simply because those persons do not exist.

So you wrote the test and now you need to write a calculation algorithm… Hmm, how the hell do we do that? We start building it and magic happens! The algorithm that can calculate the value needs all totally different input values then those you’ve written in your test case… Ouch! It happened again?

At the end you’ve used double time to write the code and update the test case in parallel plus the time you’ve killed on the test at the beginning.

So why is it so popular to talk about it and constantly try to use it? Do not know. You need to write test cases when you program difficult logic. That is the fact. But doing it FIRST? It’s just a waste of time and killing of enthusiasm. You won’t be clever and you’ll not write better code if you kill time with the test first.

What really needs to be done before you start programming is to draw a solution.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 20 September 2011

Category: Dev, strips

Silly: Hi guys!
Silly: Here is the specification of you new task!
SPEC: We want a “Calculate” button that calculates when you push it.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 9 September 2011

Category: c++, Dev

Tags: , ,

Extract the sources to some folder, open the command prompt and go to that directory.

Then enter following commands…

> bootstrap.sh
> bjam.exe --toolset=msvc --link=static --runtime-link=static --build-type=complete stage
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 5 September 2011

Category: Dev, Java, Tip

To see all the sqls that your application do during execution, insert the following property in your test xml property file:

<bean id="sessionFactory"
		class="my.class.MyEntitySessionFactory">
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
		<property name="dataSource" ref="dbDataSource" />
</bean>
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 4 September 2011

Category: Dev, Java, strips

Core: How do I make Hibernate to not to retreive all objects at the same time?
Mag: Do i lazy.
Silly: Yeah, don’t work too hard!

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 3 September 2011

Category: Dev, strips

Core: I HATE tests!
Tester: What?
Mag: He said he HATES TESTERS.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 2 September 2011

Category: Dev

Tags: , , , ,

If you’ve upgraded Perl on your Gentoo box to 5.12, and tries to reemerge ImageMagick, you might get this error:

Could not find a typemap for C type 'Image::Magick' in Magick.xs, line 2404
make[3]: *** [Magick.c] Error 1
make[3]: Leaving directory `/var/tmp/portage/media-gfx/imagemagick-6.7.1.0/work/ImageMagick-6.7.1-0/PerlMagick'
make[2]: *** [install-exec-perl] Error 2
make[2]: Leaving directory `/var/tmp/portage/media-gfx/imagemagick-6.7.1.0/work/ImageMagick-6.7.1-0'
make[1]: *** [install-am] Error 2
make[1]: Leaving directory `/var/tmp/portage/media-gfx/imagemagick-6.7.1.0/work/ImageMagick-6.7.1-0'
make: *** [install] Error 2
 * ERROR: media-gfx/imagemagick-6.7.1.0 failed (install phase):
 *   emake failed
 *
 * If you need support, post the output of 'emerge --info =media-gfx/imagemagick-6.7.1.0',
 * the complete build log and the output of 'emerge -pqv =media-gfx/imagemagick-6.7.1.0'.
 * The complete build log is located at '/var/tmp/portage/media-gfx/imagemagick-6.7.1.0/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/media-gfx/imagemagick-6.7.1.0/temp/environment'.
 * S: '/var/tmp/portage/media-gfx/imagemagick-6.7.1.0/work/ImageMagick-6.7.1-0'

>>> Failed to emerge media-gfx/imagemagick-6.7.1.0, Log file:

>>>  '/var/tmp/portage/media-gfx/imagemagick-6.7.1.0/temp/build.log'

Reemerge with:

 # USE="-perl" emerge -av imagemagick

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] media-gfx/imagemagick-6.7.1.0  USE="bzip2 corefonts cxx jpeg openmp png tiff truetype xml zlib -X -autotrace -djvu -fftw -fontconfig -fpx -graphviz -gs -hdri -jbig -jpeg2k -lcms -lqr -lzma -opencl -openexr -perl -q32 -q64 -q8 -raw -static-libs -svg -webp -wmf" 0 kB

Total: 1 package (1 new), Size of downloads: 0 kB

Would you like to merge these packages? [Yes/No] 

After some minutes:

>>> Recording media-gfx/imagemagick in "world" favorites file...
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.

You might also want to update /etc/portage/package.use with “media-gfx/imagemagick -perl” if you don’t need Perl with ImageMagick.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 31 August 2011

Category: Dev, Java, Tip

/** @deprecated this one must be resolved differently */
@Deprecated
public void setModeChange()
{
   this.mode = Mode.CHANGE;
}
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 9 March 2011

Category: Dev

Tags: , ,

From TDWTF.

Inept management hires inept arrogant conceited glory hogging twit

Inept management promotes twit at twit’s urging

Twit hires more twits for personal gain

Twit blames remaining competant workers for downward spiral

Remaining competant worker leaves

Company does well-deserved tail spin, crashes and burns

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share