Friday, March 4, 2011

Can Dataset filtering be done from outside the dataset?

I have two TDBLookupComboBox controls that I'd like to connect to the same dataset, but have each one display a different subset of the data. If I only needed one box, I'd use filtering on the dataset, but I need to be able to display both of them at the same time, and I'm not aware of any way to do that. Does anyone know if it can be done, and if so, how?

From stackoverflow
  • If you're using a TClientDataSet, you can clone the cursor (TClientDataSet.CloneCursor) into another TClientDataSet that doesn't have the ProviderName property set. Both ClientDataSet now point to the same data in memory but can have their own filters.

Trouble getting GPO logon script to run using Active Directory Domain Services

I have just upgraded our company's domain controller from NT 4.0 to Windows 2008 Server. I used the in-place upgrade path, going first from NT 4.0 to Windows 2003 Server and then 2003 Server to 2008 Server. The orginal NT 4.0 domain was name Company. The new domain is Company.local. I have confirmed user and computer information was properly migrated, and the new domain has been in operation for a week with very few issues.

The problem I am having right now is with setting up a GPO user login script for a set of users. I believe I have set up the GPO correctly, but the script does not get executed on the client after login.

Upon investigation, I noticed I could execute the script (batch file) from the client manually after login if I navigated directly to the domain controller: \\*ServerName*\SysVol\*Company*.local\Policies\{GUID}\User\Scripts\Logon

However, if my understanding is correct, this path is not used by the client when executing the login sript, but instead the domain (forest?) name is used as the source (domain and forest name are the same in this case): \\*Company*.local\SysVol\*Company*.local\Policies\{GUID}\User\Scripts\Logon

When manually executing this batch file from the client I get a "Open File - Security Warning" dialog claiming the client cannot verify the publisher. The two paths above are essentially the same place, just accessed with different paths.

Any idea why the clients do not trust content from their own domain controller when accessed via \\*Company*.local and not \\*ServerName*? Are there any other places I should be looking for the probable cause?

From stackoverflow
  • The security warning is very likely a red herring. We can go into why it's coming up, but I'm more interested in talking about the script executing during logon first.

    Logon to a client computer with a user account that should be executing the script and run the "Resultant Set of Policy" tool (from a blank MMC, add the "Resultant Set of Policy" snap-in, then highlight and right-click the "Resultant Set of Policy" in the scope pane and choose "Generate RSoP Data..." Take all defaults...)

    I'm assuming you haven't played with the NTFS ACLs on the script or the ACLs on the GPO itself.

    My gut says that this is a GPO scoping issue. Have a look, after you've gathered the policies, and see if the script is being placed in the list of scripts to be executed for the user. Right-click the "User Configuration" node in the scope pane, after you've gathered the RSoP data, and examine the list of GPOs associated with the user. Do you see the GPO containing your script in that list?

    Assuming you do see the GPO applying and do see the script listed in the logon scripts to be executed for the user, I'd head over to the Application Event Log next and see if USERINIT is logging anything during logon about problems executing the script.

    Assuming you don't see your GPO applying to the user, I'd think about where you have the GPO linked in relation to the user accounts (this is the "scoping issue" I spoke about). The GPO must be linked at the OU the user object is located within, at a parent OU of the OU the user object is located within, at the top of the domain, or at the site object associated with the IP subnet from which the client computer's IP address has been assigned.

    If this doesn't make sense and you're still not seeing what you'd expect, post some description of the logical topology of the objects in question-- i.e. a tree diagram showing the domain, and any child OU's that contain the user objects in question, and an annotation about where you linked the GPO.

    Joe Waller : You nailed it on the head. The security warning was misleading, and the real problem was a GPO scoping issue as you suggested.
  • I recently had the exact same issue. I did find that the script ran, but "invisible". there is a option on the GPO to run scripts "visibly" by going to "Administrative Templates", "System", "Scripts"

How do I compile an Expression Tree into a callable method, C# ?

Hi, I have an expression tree I have created by parsing an Xml using the expression class in C#. See this question.

I only have Add, Subtract, Divide, Multiply, Parameters, And and Or in my Expression Tree. Is there a way to convert this ExpressionTree into a callable method? ...or do I have to emit the IL manually?

Kind regards,

From stackoverflow
  • You need to create a lambda - i.e.

    var lambda = Expression.Lambda<Func<float,int>>(body, param);
    Func<float,int> method = lambda.Compile();
    int v = method(1.0); // test
    

    where "body" is your expression tree (taking a float, returning an int) involving the ParameterExpression param.

    You might also find this and this helpful.

    SharePoint Newbie : The problem is ((x + 2) + y)/z When there are more than one parameters part of different sub expressions in the tree, what do I do?
    Marc Gravell : Multiple parameters are possible (it is a params array of ParameterExpression); for sub-expressions, you need to invoke the inner expression (Expression.Invoke?)
    Marc Gravell : You can also build the entire tree into a single expression; this is slightly more efficient, but is more complex to do.
    SharePoint Newbie : I was initially trying to build the entire tree into a single expression. Then could not figure out a way to get to the parameters in the sub-expressions. Any info on that will help.
    Marc Gravell : If you have a single expression, you can use as many ParameterExpression instances as you need. For sub-expressions, you simply need to map things in the outermost expression to parameters in the *inner* expression. For example, you might need to create a new ParameterExpression for the outer...
    Marc Gravell : ... and simply pass that into the parameters set when using Expression.Invoke - this then maps as the value into the inner expression (which must also be a LambdaExpression via Expression.Lambda)
    Marc Gravell : If you have a concrete example, I can fill in some blanks - but I have to nip off for a few hours... back in a bit ;-p
    SharePoint Newbie : Wouldn't wanna give up without trying your suggestions...thx
  • Here's an example of both approaches. If I have missed something, or you want more information, just let me know.

    static void Main()
    {
        // try to do "x + (3 * x)"
    
        var single = BuildSingle<decimal>();
        var composite = BuildComposite<decimal>();
    
        Console.WriteLine("{0} vs {1}", single(13.2M), composite(13.2M));
    }
    // utility method to get the 3 as the correct type, since there is not always a "int x T"
    static Expression ConvertConstant<TSource, TDestination>(TSource value)
    {
        return Expression.Convert(Expression.Constant(value, typeof(TSource)), typeof(TDestination));
    }
    // option 1: a single expression tree; this is the most efficient
    static Func<T,T> BuildSingle<T>()
    {        
        var param = Expression.Parameter(typeof(T), "x");
        Expression body = Expression.Add(param, Expression.Multiply(
            ConvertConstant<int, T>(3), param));
        var lambda = Expression.Lambda<Func<T, T>>(body, param);
        return lambda.Compile();
    }
    // option 2: nested expression trees:
    static Func<T, T> BuildComposite<T>()
    {
    
        // step 1: do the multiply:
        var paramInner = Expression.Parameter(typeof(T), "inner");
        Expression bodyInner = Expression.Multiply(
            ConvertConstant<int, T>(3), paramInner);
        var lambdaInner = Expression.Lambda(bodyInner, paramInner);
    
        // step 2: do the add, invoking the existing tree
        var paramOuter = Expression.Parameter(typeof(T), "outer");
        Expression bodyOuter = Expression.Add(paramOuter, Expression.Invoke(lambdaInner, paramOuter));
        var lambdaOuter = Expression.Lambda<Func<T, T>>(bodyOuter, paramOuter);
    
        return lambdaOuter.Compile();
    }
    

    Personally, I would aim towards the first method; it it both simpler and more efficient. This might involve passing the original parameter throughout a stack of nested code, but so be it. I have got some code somewhere that takes the "Invoke" approach (composite), and re-writes the tree as the first approach (single) - but it is quite complex and long. But very useful for Entity Framework (which doesn't support Expression.Invoke).

    SharePoint Newbie : That did the trick...Thanks a lot.

Are there Weak References in .NET?

I would like to keep a list of a certain class of objects in my application. But I still want the object to be garbage collected. Can you create weak references in .NET?

For reference:

Answer From MSDN:

To establish a weak reference with an object, you create a WeakReference using the instance of the object to be tracked. You then set the Target property to that object and set the object to null. For a code example, see WeakReference in the class library.

From stackoverflow
  • Yes, there's a generic weak reference class.

    MSDN > Weak Reference

  • Can you create weak references in .NET?

    Yes:

    WeakReference r = new WeakReference(obj);
    

    Uses System.WeakReference.

  • Yes...

    There is a pretty good example to be found here:

    http://web.archive.org/web/20080212232542/http://www.robherbst.com/blog/2006/08/21/c-weakreference-example/

    daub815 : FYI, the link above no longer works :(
    Andrew Rollings : Updated to refer to the wayback machine copy instead.
  • Here is the full implementation sample of WeakReference

    ClassA objA = new ClassA();
    WeakReference wr = new WeakReference(objA);
    // do stuff 
    GC.Collect();
    ClassA objA2;
    if (wr.IsAlive)
        objA2 = wr.Target as ClassA; 
    else
        objA2 = new ClassA(); // create it directly if required
    

    WeakReference is in the System namespace hence no need to include any special assembly for it.

how to check performance of a c++ api

my web server has a lot of dependencies for sending back data, when it gets a request. i am testing one of these dependency applications within the web server. the application is decoupled from the main web server, and only queries are going to it in the form of api's exposed.

my question is, if i wish to check these api's in a multithreaded environment (c++ functions with a 2 quadcore processor machine), what is the best wy to go about doing it?

do i call each api in a separate thread or process? if so, how do i implement such code? from what i can figure out, i would be duplicating the functioning of the web server, but i can find no other better way to figure out the performance improvements given by that component alone.

From stackoverflow
  • It depends on whether your app deails with data that's shared if it is run in parallel processes because that'll most likely determine where the speed bottleneck awaits.

    E.g, if the app accesses a database or disk files, you'll probably have to simulate multiple threads/processes querying the app in order to see how they get along with each other, i.e. whether they have to wait for each other while accessing the shared resource.

    But if the app only does some internal calculation, all by its own, then it may scale well, as long as all its data fits into memory (i.e. not virtual memory access, e.g. disk access, necessary). Then you can test the performance of just one instance and focus on optimizing its speed.

    It also might help to state the OS you're planning to use. Mac OS X offers tools for performance testing and optimization that Windows and Linux may not, and vice versa.

Tips for hiring good testers?

Hi all,

We're looking to add a few good testers (err "qa engineers") to our team.

It's been my experience in the past that the "10-1" rule for developers (good devs are 10 times more productive than mediocre devs) is even more prevalent for testers. Most testers I've worked with found a decent amount of issues, but there's a few stand-out testers that I've worked with that could rip applications apart and make the dev team cry.

So the question is -- how do you find these rockstar testers? The web is full of exams and tips to separate out the great from mediocre developers, but whats the magic interview questions and tests to find the amazing testers?

We're about to start the second round of interviewing with the people that have passed the phone screen (aka idiot test) and any suggestions you have for this challenge greatly appreciated.

From stackoverflow
  • Whip up a small obviously-demo application with a few obvious, less-obvious, and hidden issues. Let the candidate loose on it. Observe how they test it, maybe with a senior tester to help judge.

  • In addition to having them actually test things, have them write some bug reports.

    I can tell you that as a software developer, the bane of my existence is QA people who don't provide any useful information in their bug reports. Even if someone can find every bug in the universe, they're useless if they can't tell me how they did it!

    Finding the bugs is only part of the story. What's equally (if not more) important is the fact that they can effectively communicate the problems to the development team so that they can be reproduced and fixed.

    A poorly written bug report can waste a lot of a developer's time just trying to figure out what the bug is before they can even begin to work on fixing it. It's these poorly written bug reports that usually make the dev teams cry rather than the act of finding bugs.

    At a minimum, here's what I need as a developer to effectively do my job:

    1) Software version (and build number) where the bug occurred
    2) Description of the bug
    3) Detailed list of steps to reproduce the bug

    Bad QA people won't even provide #3 or will give you such vague information that it's not at all helpful and sometimes it's so bad that you don't even know what the hell they're talking about. You almost always wind up talking to a bad QA person several times before you can even start working on the bug.

    Good QA people will provide adequate information so that the developer can reproduce the bug without having to even talk to the person who filed the bug report.

    Great QA people will go the extra mile and try to really nail down the bug for you by trying alternate paths to the bug until they come to a very specific cause of it.

    Completely contrived example to show my point

    Let's say I have a print feature in an application. There are multiple ways to get to the print feature (File -> print, button on the toolbar, etc).

    There's a crash that happens when printing more than 9 pages of a specific document foo.txt but it only crashes when using the Print icon on the toolbar.

    Bad QA bug report: Application crashes when printing a document.

    Good QA bug report: Application crashes when printing foo.txt from the Print icon on the toolbar (and foo.txt is attached to the bug report). Printing other documents does not cause the crash.

    Great QA bug report: Application crashes when printing foo.txt from the Print icon on the toolbar (and foo.txt is attached to the bug report). Printing other documents does not cause the crash. Also found that printing from the File menu does not cause the crash and crash doesn't happen if I only print the first 9 pages of the document.

    Michael Stum : Absolutely Agreed, Bug Report Writing skills are often overlooked. I also want to add: English Skills (or whatever your official team language is) are important as well. It's great if your tester finds all bug and can write all the details, if his english is so bad it's not understanable at all.
    glenra : You can also elicit some of this by asking them about the best bugs they've found in past jobs. Great QA people tend to be excited about having nailed down really obscure bug conditions; they'll probably have a story or two about the most obscure/interesting bug they found and how they found it.
    17 of 26 : Good idea, glenra. It's very similar to a good programmer getting excited about an obscure bug that they fixed.
  • "whats the magic interview questions and tests to find the amazing testers?"

    If you think there are magic questions, then you are already in trouble. Do you use magic questions for hiring developers, too?

    If you aren't used to hiring testers, then find someone that is and have them help.

    Colin Mackay : Isn't that what the OP was doing... Asking for help from folks who are used to hiring developers?
  • Not interview questions, but just a few things to watch for, with no particular order:

    1. Testing instincts, you can find out about this using a demo application and see if the bugs are detected
    2. Shell scripting skills, testers with great scripting skill can be xx times more efficient than the ones who aren't.
    3. Communication skill, typical testers spend more time communicating the bugs and coordinating the fixes
    4. Testing mind set, e.g. does he/she enjoy coming up with devious thoughts?
  • In building a test team, you will no doubt want to hire people with a mix of talents. You will need testers which have subject matter expertise in your project's problem space. You will also need testers who are technical - have the coding skills to create test automation suites and utilities to support manual testing. Sometimes you may be lucky enough to find a person who can fill both roles. Often though, these will be different individuals. The SME and technical testers each bring something different to the table.

  • One approach: give the potential tester an application (user interface, command line, whatever you usually work with) and a test case. Now, not just any test case, take a badly written, vague, maybe partially uncomprehensive test case. Tell the potential tester to roll up the sleeves. What I would expect is constructive criticism towards the test case. For a test report credibility the biggest holes in the test case should be filled with something (either offering to edit the test case, or describing the executed tests in a test report). The tester should also sport some creativity in steps that call for "try different variables". Your application should also have something worth bug reporting appearing in this test testing, just to see how the applicant approaches a possible bug.

    In my opinion one of the big issues is the bug hunt in an interview. I don't think that many people are comfortable trying out different things and narrowing down the exact bug and workarounds for it when someone is watching over their shoulder. So the result is less likely to be excellent, even if you have a real star sitting on the other side of the table.

  • Lots of good advice already given here already; a couple more thoughts I'd add:

    • get an understanding of the types of applications they've tested in the past and ask questions about the apps. A tester that really gets into the apps s/he is testing will probably do the same for you. If their experience is in testing desktop apps, and you're producing web apps, or vice-versa, think about the nuances that are unique (web apps: back button, browser differences, font settings, etc., etc.; desktop apps: installation processes, hardware configs, etc.) and try to see if they understand the differences and are ready to adapt if necessary.
    • Another key area is test planning -- just as it's important to design code before writing it, any non-trival testing exercise should be planned out and documented. Give them information about the small app someone else mentioned, and ask them to outline a test plan. What questions do they ask? Do they ask who makes the final ship/launch decision and what their criteria are? Then, ask suggested by another, look at a bug report.
    • Do they think of their test plan in modules or sections that can be reused as the system under test evolves over time?
    • Experience with automation tools, and the judgement of when to use them, is also important.
    • What tools have they used in the past to track bugs and communicate with programmers and/or management? Can they express how much of the testing job is complete, how much remains, and the risks to the plan (i.e., the time to test something written by a new programmer, or in a new technology is harder to predict than something the organization has more experience in)?

    Good luck -- success here can be as critical as in hiring programmers.

  • Our QA Manager at the company I work at has put a lot of thought into this topic. He wrote an article about it that can be found here

    Here is a quick summary of aspects he looks at when looking for software testers:

    In my experience, there are attributes common to good software testers that indicate potential for almost any testing position, regardless of industry or development technology. For almost a decade, I have often used the following as a guideline of the basic attributes I look for:

    • Customer-focussed, Quality-minded
    • Troubleshooting and Problem-solving skills
    • Good communicator – written and spoken
    • Thinks like a Hacker – Analytical and likes to break software for fun or the challenge.

    For a senior tester, I would add the following basic attributes to the above list:

    • Critical Thinking and Systems Thinking skills
    • Reverse Engineering and/or Modelling skills
    • Adaptable and flexible
    • Understands the financial cost of Quality
    • Ethical, has integrity
    • Commitment to learning, open-minded
    Mark Irvine : Gorg, your link to that article dos not work...
  • It all depends on what kind of QA person you looking to hire- I have following suggestions based on who you looking to hire

    1. To hire Automation expert - Give him to record some script and then evaluate the quality and the detail coverage of his script
    2. To hire Sys/integration testing expert - Give him a use case and ask him to come up with the test scenarios related to it and check how detail and creative a person can get to cover most of the scenarios
    3. To hire UAT testers - Just select a person who has the previous business experience working in the similar area
  • Find the ones that want to know how things work. They will be willing to let their minds turn and come up with creative ways to break your stuff. If they can answer questions pertaining to how things work they are probably fit for such a task.

  • Technical knowledge is a good to have for a QA person. He has to understand the working of an application from a much wider prospective than a developer, who would most of the time be restricted to his own component. The ability to develop small hacks and a perceived sense of knowing what can go wrong in a given component.

    Another thing that a tester should have is the ability to ask questions. He should be curious to know what and why and also get to the how. He should not assume things, as once he does start assuming things, his ability as a tester goes down.

    He should be able to write good and clear bug reports. The steps to reproduce a bug is a major bane for most developers ad we get a lot of questions after a bug has been written, which could have been easily resolved, if the bug report was comprehensive and written clearly. Hard to reproduce issues should have substantial evidence with them, so that these can be resolved without spending time on justifying a "cannot reproduce".

    You have put in a good analogy of a tester with a product manager, these two roles are the ones who know the overall working of the product, while not actually getting into the internals. But a tester would be more keen on what ways can he/she devise to break the product, while a product manager, is more concerned with joining the pieces up and getting a perception of what the user actually would look for.

    I would choose a person who is both technically sound and has a clear understanding of testing techniques. His logical and analytical abilities should be very good. Languages and Tools can be taught (if a basic knowledge of a HLL is there), but not logic and analysis of a problem/product.

    My best has been to give the person being interviewed a use case like the address bar of the IE and let him find test cases or give him a function like memcopy and work out wat can go wrong with it and what all is to be tested to release the same.

    For the above example, he should be able to nail down the minor issues quickly (you are the judge for this) and then get on to borderline cases and issues which are hard to find. He should be in control of the tests, not the tests be in control of him.

  • a) Case Reduction

    As per 17 of 26. A tester needs to be able to reduce defect reproduction steps to the simplest failing case.

    You interview for this by presenting the candidate with a contrived defect that appears in the course of a moderately complex use case in your actual product. If time is tight, provide an anecdotal description of that unabridged use case and ask how they would document it. A good candidate will begin with an attempt to get the failure to occur in fewer steps.

    b) Intelligent Diagnosis

    A concise failing case is a good start. Next, great testers provide relevant contextual information that helps the developer fix the bug ASAP.

    Many bugs are trivial to fix once the developer knows where to look. A few minutes of diagnostic work by a competent tester can go a long way toward this.

    E.g., if your team is building a web application, hire testers who are capable of using a Javascript debugger, know how to check web server logs, and can access the version control change set where the defect appeared, etc. In many cases the source of a defect will be transparent even to non-dev testers when they look at this info. Including the relevant bits in the defect report can save lots of time for the developer.

    You interview for this by presenting the candidate with a contrived defect in your actual system and provide access to the resources above. Monitor the extent to which they use the diagnostic tools as they document the defect.

    If time is tight, ask some basic screening questions relevant to your business and tools. E.g. given shell access to a directory with web server error logs, what command would you use to monitor log events?

    c) Personality

    You've worked with effective testers in the past, so you have some idea of the personality attributes you are looking for.

    Use your own judgement to evaluate this. But remember to mind your own judgement. Weight it more heavily than technical competency when making your hire decision.

    You can train for technical competency. Personality is another matter.

    You interview for this by asking the candidate a series of open-ended questions and giving him or her a chance to speak at length on some subject that they should be familiar with. Ask about interactions with former co-workers, bosses, customers, etc. Who was your favorite / least favorite, etc.

  • Hey.
    You have some great answers above: Bug reports, communication skills, waching candidate at work with some app. I really liked one about shortening the test case to hunt the bug, and one with criticizing badly written test case. Those two were less obvious yet so important.
    But In addition I would add one more question, ask him or her to propose tests but not for the application. Ask for possible tests for a ball pen (or something else, commonly known yet not related to software). Very simple, yet checks if she or he can be creative, how they approach the problem. Can he or she show some constructive criticism in the way they think. Is candidate ready to jump on this level of abstraction? Does proposed test cases make sense?
    Good tester should think of at least 20 tests without big problems (unless they can't handle stress of job interview). Additionally ask candidate to organize those tests in test suits. How he would group them? What tests should be performed more often than others? This way you will know if he can he bring some value regardless of technology he will need to face.

Relocatable symbols in ELF format (assembly language)

We are developing a port of the GNU Assembler for a client architecture. Now the problem being faced is that:

If an immediate operand to an instruction is an expression involving more than one relocatable symbols, how is it handled in output file in elf format. What will be the relocation information produced in such a case?

For example:

j label1 + label2

where label1 and label2 are defined in relocatable sections, they might be the same sections or different relocatable sections.

From stackoverflow
  • I know jack about ELF and only a little more about linking but...

    I would expect that each operand is handled the same way that it would be if there was only one.

    OTOH might the issue be that the format for j alters depending on where the labels are? If so, I think you're sunk as linkers aren't smart enough to do that sort of thing (the ADA build system IIRC might be smarter than most so you might look at it.)

  • ELF doesn't know about instructions, per se. It knows about particular encodings of symbol offsets within instructions. In the assembler, you would need to output two relocation records, each with the corresponding [address,type,symbol] triplet to properly patch that portion of the instruction. The linker wouldn't necessarily even know that these two records point to the same instruction.

    The ELF relocation types are completely CPU-dependent (or, to be more precise, ISA-dependent), so you are free to define whatever relocations you need for a new architecture.

    It's hard to be more specific without details of the instruction encoding.

  • I would expect one entry per address for every instruction that needs relocation.

    Objdump might be able to display the relocation table of an executable or object file, but I don't know the flags offhand.

    My suggestion is to try to dig up an x86 (or other CISC) instruction that does something similar to what your client arch does, and see what relocations are generated when you assemble/link it.

Garbage Collecting objects which keep track of their own instances in an internal Map

In the constructor of my class, I map the current object (this), along with its key (a string entered as a parameter in the constructor) into a static LinkedHashMap so I can reference the object by the string anywhere I might need it later.

Here's the code (if it helps):

public class DataEntry {
    /** Internal global list of DataEntry objects. */
    private static LinkedHashMap _INTERNAL_LIST;

    /** The data entry's name. */
    private String NAME;

    /** The value this data entry represents. */
    private Object VALUE;


    /** Defines a DataEntry object with a name and a value. */
    public DataEntry( String name, Object value )
    {
        if( _INTERNAL_LIST == null )
        {
            _INTERNAL_LIST = new LinkedHashMap();
        }

        _INTERNAL_LIST.put( name, this );

        NAME = name;
        VALUE = value;
    }
}

The problem? Instances of this class won't get garbage collected when I'm done using them.

I'm just curious if there's a way to have instances of this class clean themselves up when I'm done using them without having to manually call a Remove() method or something each time (to remove its reference in the internal LinkedHashMap when I'm no longer using them, I mean).

From stackoverflow
  • What you want to use seems to be a weak reference. The concept is that weak references are not strong enough to force an object not to be GC'ed. I don't have much experience with them but you can learn more here.

  • Make the values WeakReferences (or SoftReferences) instead. That way the values can still be garbage collected. You'll still have entries in the map, of course - but you can periodically clear out the map of any entries where the Weak/SoftReference is now empty.

    Morten Christiansen : Damn, you beat me to the weak references :)
    Jon Skeet : Was busy editing - WeakHashMap isn't really suitable as it's the keys which end up being weak, not the values. You'll effectively have to write something somewhat similar, but it probably doesn't need to be quite as powerful if you're only using it for one particular situation.
    Daddy Warbox : Ok thanks. Yeah I was afraid of that. I'll probably just stick with using Remove methods and do it the lazy way then. :P
  • Making an object visible to others before its constructor is complete is not thread safe.

    It's not clear how the map is being used in this case, but suppose there's a static method like this in the class:

    public static DataEntry getEntry(String name) {
      return _INTERNAL_LIST.get(name);
    }
    

    Another thread, running concurrently, can access a DataEntry while it is being created, and start to use an entry with an uninitialized VALUE. Even you reorder the code in the constructor so that adding the new instance to the map is the last thing you do, the JVM is allowed to reorder the instructions so that the object is added to the list first. Or, if the class is extended, the subclass initialization could take place after the object has been published.

    If more than one thread accesses the interacts with the DataEntry class, you could have a concurrency bug that is platform dependent, intermittent, and very tough to diagnose.

    The article, "Safe Construction," by Brian Goetz has more information on this topic.

    Back to the original question: using WeakReference, as mentioned by others, is a good approach, but rather than iterating over every entry in the map, I'd recommend creating a wrapper for your values that extends WeakReference (it could be your DataEntry itself, or a helper), and queuing each reference in a ReferenceQueue. That way, you can quickly poll the queue for any collected entries, and remove them from the map. This could be done by a background thread (blocking on remove) started in a class initializer, or any stale entries could be cleaned (by polling) each time a new entry is added.

    If your program is multi-threaded, you should abandon LinkedHashMap for a map from java.util.concurrent, or wrap the LinkedHashMap with Collections.synchronizedMap().

    Daddy Warbox : Thanks for the additional information. Multi-threading is a bridge I may eventually need to cross, but for now I'm just bumbling my way through the basics. Anyway I'll consider that alternate approach.

Do real programmers network and share?

In a previous question about homework on stackoverflow I made the following statement:

I think it's extremely important for students to learn that real-world programmers work together, learn from each other, support each other, and share their knowledge and insights. It's this type of networking that inspires and excites us.

This was down-voted, and I'm guessing someone thought I was being facetious, which I was not. In my long career as a programmer, I've always been in an environment where sharing (sometimes called "leveraging" or "reuse") and mentoring were encouraged, and people were rewarded for doing these well.

Is this a typical experience, or am I just very lucky (and maybe naive)? Are you rewarded more for teamwork or solo accomplishments?

From stackoverflow
  • I think your original answer might have been down voted because the original question was

    Can and how does one ask about homework on StackOverflow, and what guidelines should members use when responding to homework questions?

    And your answer (while insightful) did not directly relate to the question.

    To answer the current question, yes -- real programmers network and share.

    Here's how I have learned to network and share in my career:

    • Get to know various recruiters personally (if you're a contract programmer, make sure you're going out to lunch with recruiters on a regular basis)
    • Complete your profile on LinkedIn, and make sure your profile is up to date and you have recommendations from others (and give recommendations to others)
    • Go to various conferences to see what other programmers are doing. Examples? Microsoft PDC, Facebook developer's conference, Microsoft MIX, jQuery development conference,
    • Go to local dev events, like local user's groups.
    • Stay in touch with past co-workers. LinkedIn is a good start, but when was the last time you called up somebody you worked with 5 years ago and just took them out to lunch to chat?
  • Surely SO itself is an example of networking and sharing - as is open-source. So yes, it happens a lot of the time on the net to start with. In my experience it happens at work as well, with mentoring, code reviews, tech talks etc.

    Paul : I envy you for your situation.
  • In a modern IT department, "networking" or "collaborating" is fundamental.

    Some fields where this applies:

    • teamwork: teamwork is just necessary to accomplish great objectives (like rewriting from scratch a big corporate system)
    • collaborative tools: source control systems, bug tracking applications, IMs, etc. are just examples of collaborative tools that boost productivity on large scale projects.
    • internal mentoring/training: an appropriate training and mentoring process is vital for a modern company, and gives value to all the employees.
  • I consider networking, communicating and working with other developers to be very important for personal and professional growth.

    Human-human interaction is much more conductive to problem solving than human-computer interaction, and sometimes you can find a solution just by describing your problem to another person.

  • In my experience, sharing knowledge and mentoring has been very common in every-day work. I've been the most junior developer in some teams and the most senior in others, and I've always got to learn a lot from the most experienced guys, as well as guiding others who had less experience than me (and yes, you can learn from them too). I don't know about material rewards and as far as I know there wasn't any kind of policy on "networking", but I'd say most people I've worked with are naturally open and willing to collaborate with each other.

  • Doesn't the existence of this site show beyond a doubt that programmers do share knowledge quite extensively? :)

  • I'm sure that there are many who don't, but I wouldn't want to work with any of them. I think it is critical to your success to both learn from and teach others. Learning from others is critical; teaching is less so but arguably more effective as you will really have to know your stuff.

  • Yes, but, it is not for you, It is for me, practically.

  • I find networking to be invaluable, and not just code networking. I run a business, so it's vital for me to talk to people in a wide variety of roles. More developers could benefit from taking advantage of external networking options, even if only to try to pick up a bit of extra cash.

    On the other side, networking allows me to keep in touch with some really clever people, which means that I've got to learn some great stuff because these people are really at the top of their game. Done properly, networking is a huge benefit to you, so I can only encourage it.

  • At my current job, I work with 2 of the most talented programmers I've ever worked with. I call them talented because they REALLY get things done and churned out, and I can easily read their code. It's high quality and produced quickly.

    However, these 2 guys don't share with anyone, really. It's not a malicious thing, they just don't have the desire to mentor others. I've done (and do) everything I can to get their lazy asses :) to teach me some things, and it's like pulling teeth.

    One guy is very talented, but when you ask him to explain some code (not from a technical perspective, but from a business logic perspective), he says really insulting things like "so, do you understand what is happening here? Probably not..." He doesn't MEAN to be a complete egotistical bastard, but he is. I call him on it all the time and we just both laugh, because he knows it is true.

    Those guys don't share.

    Now, I'm personally not even a senior developer in my current job, but in my last one where we were using VB6, there wasn't much I didn't know about the language and common techniques to solve problems. Back then I mentored and shared every chance I got.

    So, from my anecdotal perspective, 33% share and 66% don't. YMMV.

  • Here is what I have learned about coding and teams and collaboration were I work.

    1.) The code and the design is freely available from other projects or can be obtained.
    2.) People don't have "TIME" to explain why they did what they did.
    a.) The exception being if your involved in a code review.
    3.) Things are very competitive (In all the wrong ways like rankings).
    4.) If you ask too many questions of the "Gurus" You are considered to be a poor problem solver and a drag on the team.
    5.) Code reuse across projects happens. But only if the people who started the project knew to do this. Sometimes there are people who share the wealth of what there doing on projects with other people that were working on like projects. This happens randomly or through word of mouth.
    6.) Sometimes other peoples work is crap. It takes experience to know not to use their stuff.

    Here is the thing, my first project was like drinking from a fire hose. Learning process, design, corporate culture, how to deal with personality conflicts, coding techniques and style, and poor resource management. These were all demanded to be already known out of the gate. Training is a joke, and mentoring, though given lip service, just doesn't happen. Also, there are people who will take your ignorance and use it as a weapon to back stab you with management to make themselves look like the arbitrators of all things Software Engineering (and it works too). Another example is if your team was green and the one guy who wasn't is bombarded with questions, then his/her productivity will drop (and/or he will be burnt out and resentful) consequently claming him/her up and damaging your reputation.

    Solutions:

    Try not to work for a company who has this as a culture (unavoidable in my case for personnel reasons). Have a very thick skin. Seek out a friendly face (usually the people who work nights by choice). I would suggest you find out who this might be and it should be someone not on your team. A caveat to this would be don't ask him/her the wrong questions. The wrong questions being questions you could easily look up. Also, do not ask him/her too many questions. Pick the questions well to show that your intelligent and diligent and that you just need guidance. I can not emphasize enough, who you ask is extremely important. Also, there could people on your team who are in your shoes (or have been). Enlist your peers that are in the same situation and collectively you could learn together if all of you are prepared (good way to network). The key to the preparation is diligence and studying. Even if you have to work many hours on your dime. If you don't know something, you better study like its a final in college. Because guess what, it is like finals every day your first couple of years if you are typical of most coders I have met when they first start out.

  • I would love to be in such a encouraging and sharing environment. Usually I try to share, or encourage others to share what best practices, tricks, experiences they have. But they always look at me like I am some kind of monster, for being open and honest.

Get access to ForeignKey objects at parent save in Django

Hi,

I am trying to make a combined image of all images added to a modell in django with inline editing and a ForeignKey. Ive got these models (simplified):

class Modell(models.Model): title = models.CharField('beskrivelse', max_length=200) slug = models.SlugField() is_public = models.BooleanField('publisert', default=True)

def __unicode__(self):
    return self.title

def save(self, **kwargs):
    super(Modell, self).save(**kwargs)

    on_modell_saved(self)

class Image(models.Model): modell = models.ForeignKey(Modell, related_name="images") image = ThumbnailImageField('bilde', upload_to=get_upload_path_image)

class Meta:
    verbose_name = 'bilde'
    verbose_name_plural = 'bilder'

def __unicode__(self):
    return str(self.image)

Then i add Image to the Modell with AdminInline, so when i save the Modell i save x number of images.

But when I try to do something with Modell.images.all in the on_modell_saved function i cant get hold of the objects. Ive got this function that is executed at Modell.save()

def on_modell_saved(instance): for img in instance.images.all(): print img

This only prints something the second time i save the Modell and not the first time. So anybody know how to call a function after all items that you are adding with AdminInline is saved?

From stackoverflow
  • The Modell instance isn't being saved when you add a new image; only the Image instance is being saved.

    Move your function call into the Image model and you'll be good.

    def on_image_saved(instance):
        for img in Image.objects.filter(modell=instance.modell)
            print img
    
    class Image(models.Model):
        modell = models.ForeignKey(Modell, related_name="images")
        image = ThumbnailImageField('bilde', upload_to=get_upload_path_image)
    
        class Meta:
            verbose_name = 'bilde'
            verbose_name_plural = 'bilder'
    
        def __unicode__(self):
            return str(self.image)
    
        def save(self, **kwargs):
            super(Image, self).save(**kwargs)
    
            on_image_saved(self)
    
    Espen Christensen : I think you misunderstood, because i newer add images manually, but i add images at the same time as i add a new Modell. I add images inline in the add Modell form. So then the Modell is saved, isnt it? If you do it your way, the on_image_saved is called one time for each image, i dont want that...
    Daniel : The foreign key is on the Image table, not the Modell table, so the image can't be added until the Modell it links to is created. They will be added one at a time, after the Modell instance I don't see this as a problem. But if it is, there are other hooks provided by the admin app that may help.
  • Modell and Image are two seperate models connected with a ForeignKey. Even though they both seem to be saved together, they don't. They are saved one by one (first the Modell or first the Images).

    Now logically Images are saved after Modell. Because they have a ForeignKey pointing to Modell and if you try to save them first, because there's no Modell yes, they would point to nothing (which is possible with null=True).

    So by the time Modell.save() is called Images don't exist.

    Solution depends on what you want to do? I suppose the aim here is not just printing out the Images.

    Espen Christensen : Yeah, that sounds about right, of course there need to be a Modell before the Image can be saved and related to the modell. No the aim is not just to print out the images. In Images ive overrided the save to make thumbs, and in the Modell save, i want to combine all these images to a filmstrip.
    muhuk : I don't why it has to be Modell.save() as long as the filmstrip is updated. I wish you had stated this in your question. Because in this case all you have to do is to call a Modell.update_filmstrip() function from ImageManager.create() and Image.delete() (assuming images are immutable)
  • I dit solve it somehow, but it is farm from optimal, I did the modell_on_save function on Image save, this works, but the bad thing that if there are 5 images related and saved to the modell, there will be 5 calls to the function, and that is bad. I would like it to only happen after the last one...

    Daniel : That's the way to do it. The save() method has nothing to do with the admin interface.. it's called on all model instance saves, irregardless of it's source. If you hooked just on the admin save, that would have the problem of not working if you add an image from the shell or by another method.

Array of Queues in VB.Net

Probably a very dumb question, but I want to create an array of queues in vb.net - so I can reference each queue with an index:

eg

commandQueue(1).enqueue("itemtext")

commandQueue(2).enqueue("othertext")

where commandQueue(1) refers to a separate queue than commandQueue(2)

I've got all tangled up trying to define an object array and put queues in.

Yes of course I can do it with old fashioned arrays, pointers etc, doing the management by hand, but this seemed so much more elegant...

From stackoverflow
  • What's wrong with this solution?

    Dim commandQueue As Queue(Of T)()
    

    There's nothing “old fashioned” about this solution. However, dynamic memories might sometimes be better suited:

    Dim commandQueue As New List(Of Queue(Of T))()
    

    In both cases, you need to initialize each queue before using it! In the case of an array, the array has to be initialized as well:

    ' Either directly: '
    Dim commandQueue(9) As Queue(Of T)
    ' or, arguably clearer because the array length is mentioned explicitly: '
    Dim commandQueue As Queue(Of T)() = Nothing ' `= Nothing` prevents compiler warning '
    Array.Resize(commandQueue, 10)
    

Listing the files in a directory of the current JAR file

I am making a game in JAVA where I want to come up with a list of files in a certain directory in my jar so I can make sure to have a list of those classes to be used in the game.

For example say in my jar I have a directory

mtd/entity/creep/

I want to get a list of all the .class files in that directory using java code from another class in the jar.

What is the best code to do so?

From stackoverflow
  • Old java1.4 code, but that would give you the idea:

    private static List getClassesFromJARFile(String jar, String packageName) throws Error
    {
        final List classes = new ArrayList();
        JarInputStream jarFile = null;
        try
        {
         jarFile = new JarInputStream(new FileInputStream(jar));
         JarEntry jarEntry;
         do 
         {     
          try
          {
           jarEntry = jarFile.getNextJarEntry();
          }
          catch(IOException ioe)
          {
           throw new CCException.Error("Unable to get next jar entry from jar file '"+jar+"'", ioe);
          }
          if (jarEntry != null) 
          {
           extractClassFromJar(jar, packageName, classes, jarEntry);
          }
         } while (jarEntry != null);
         closeJarFile(jarFile);
        }
        catch(IOException ioe)
        {
         throw new CCException.Error("Unable to get Jar input stream from '"+jar+"'", ioe);
        }
        finally
        {
         closeJarFile(jarFile);
        }
       return classes;
    }
    private static void extractClassFromJar(final String jar, final String packageName, final List classes, JarEntry jarEntry) throws Error
    {
        String className = jarEntry.getName();
        if (className.endsWith(".class")) 
        {
         className = className.substring(0, className.length() - ".class".length());
         if (className.startsWith(packageName))
         {
          try
          {
           classes.add(Class.forName(className.replace('/', '.')));
          } catch (ClassNotFoundException cnfe)
          {
           throw new CCException.Error("unable to find class named " + className.replace('/', '.') + "' within jar '" + jar + "'", cnfe);
          }
         }
        }
    }
    private static void closeJarFile(final JarInputStream jarFile)
    {
        if(jarFile != null) 
        { 
         try
         {
          jarFile.close(); 
         }
         catch(IOException ioe)
         {
          mockAction();
         }
        }
    }
    
    James Van Boxtel : After a little bit of messing with this I got it to work. Thank you very much!
    Dan : Ooh, this happens to be exactly what I need here right now - thanks!!
    VonC : Cool, glad to help :)
  • It's not possible, as Java doesn't provide direct access to the jar file the classes are loaded from. You could try to parse the java.class.path system property to find it, but that wouldn't work under all circumstances. Or you could restrict on where the jar file has to reside, or provide the list of the classes in a different way (for example via the manifest file).

    Ilja Preuß : what's wrong about this answer? I assumed that the bigger problem would be finding the path to the jar file - actually extracting the content should be quite trivial.
  • Probably the best approach is to list the classes at compile time.

    There is a fragile runtime approach. Take you Class (MyClass.class of this.getClass()). Call getProtectionDomain. Call getCodeSource. Call getLocation. Call openConnection. (Alternatively open a resource.) Cast to JarURLConnection. Call getJarFile. Call entries. Iterate through checking getName. I really do not recommend this approach.

  • Remember that JAR files are just ZIP files renamed, and it's very easy to read the contents of ZIP files in Java:

     File jarName = null;
     try
     {
      jarName = new File (Dir.class.getProtectionDomain().getCodeSource().getLocation().toURI());
     }
     catch (Exception e)
     {
      e.printStackTrace(); 
     }
    
     try 
     {
          ZipFile zf=new ZipFile(jarName.getAbsoluteFile());
          Enumeration e=zf.entries();
          while (e.hasMoreElements()) 
          {
              ZipEntry ze=(ZipEntry)e.nextElement();
              System.out.println(ze.getName());
          }
          zf.close();
       } catch (IOException e) 
       {
          e.printStackTrace();
       }
    

What do you ask at an interview for a QA position?

There are a ton of questions on this site about interview questions for programmers, but what about QA engineers?

How can I make sure I'm getting somebody who really knows how to put test plans together and execute them?

How much in the way of technical skills should I demand? I've worked with a few testers before who knew basic SQL, and that was great, because they could interact with the UI and then go check to make sure everything looked correct afterwards in the db.

Of course, if they're too technical they just end up programming and you lose your tester. :P

Are there any standard tools that testers use that they should be familar with?

Has anybody had luck combining the QA role with product management? It seems like a perfect fit to me.

We all know we're supposed to have dedicated testers, but I bet few of us do. We should know how to hire one when we actually get the chance.

From stackoverflow
  • Some of the best questions I've heard in the quality assurance arena revolve around real-world scenarios. The questions can range from "Given this well-known web application (take your pick: Gmail, Hotmail, Stack Overflow...), generate a list of test cases. How would you test each one?" Not-so-straightforward questions, such as "How would you test a vending machine?" or "How would you test this chair?" can also give some great insights on whether or not the candidate you're interviewing has the right QA mindset.

    I'd also put an emphasis on metrics that the person considers to be important factors in software quality. Some "spot the bug in this chunk of code" type questions can help identify a candidate that is able to perform meaningful code inspection. I'd also look at whether or not the candidate has previously driven improvements in known-good test metrics at other jobs: high code coverage, unit test coverage, test automation, build verification and so on.

    Technical knowledge is also exceedingly important. The problem is finding someone with that mindset who prefers to apply their knowledge towards breaking things. A solid tester with these skills will run circles around other testers; you simply cannot get someone with a point-and-click level of testing to perform in the face of common requirements. Consider a scenario such as "We're changing the way validation works for this querystring parameter; look at 10 gigs worth of log files to determine if this would break anything in our production environment." You'll need a tester with effective coding skills to make that decision.

    Mark Bessey : For whatever reason, some folks find the "describe how you'd test a chair" questions off-putting. It might be best to stick with questions a little closer to the actual job. Ask them about how they'd test a simple application.
  • You have a bowl with 200 fish in it. Of these fish 99% are not guppies. How many fish should you remove so that 2% of what remains are guppies. Show your work.

    This is about confusing requirements. It is said this way to change perspectives multiple times during the same question. It is meant to see if they can figure out what they are to test.

  • It might be worth asking them to explain the differences between various testing approaches (who does it, what is it for)? ie:

    • Unit testing
    • Smoke testing
    • Integration testing
    • System testing
    • Acceptance testing
    • etc...

    Wiki may have some good source information here

  • I would ask if the tester has ever heard of James Bach. If not I would encourage them to hie to the nearest browser and watch yon video with all haste.

  • There's a similar discussion here that may help.

    Eric Z Beard : Wow, I searched for a while and never found that! Dang, I didn't mean to ask a duplicate.
  • It all depends on what kind of QA person you looking to hire- I have following suggestions based on who you looking to hire

    1. To hire Automation expert - Give him to record some script and then evaluate the quality and the detail coverage of his script
    2. To hire Sys/integration testing expert - Give him a use case and ask him to come up with the test scenarios related to it and check how detail and creative a person can get to cover most of the scenarios
    3. To hire UAT testers - Just select a person who has the previous business experience working in the similar area
  • Technical knowledge is a good to have for a QA person. He has to understand the working of an application from a much wider prospective than a developer, who would most of the time be restricted to his own component. The ability to develop small hacks and a perceived sense of knowing what can go wrong in a given component.

    Another thing that a tester should have is the ability to ask questions. He should be curious to know what and why and also get to the how. He should not assume things, as once he does start assuming things, his ability as a tester goes down.

    You have put in a good analogy of a tester with a product manager, these two roles are the ones who know the overall working of the product, while not actually getting into the internals. But a tester would be more keen on what ways can he/she devise to break the product, while a product manager, is more concerned with joining the pieces up and getting a perception of what the user actually would look for.

    I would choose a person who is both technically sound and has a clear understanding of testing techniques. His logical and analytical abilities should be very good. Languages and Tools can be taught (if a basic knowledge of a HLL is there), but not logic and analysis of a problem/product.

    My best has been to give the person being interviewed a use case like the address bar of the IE and let him find test cases or give him a function like memcopy and work out wat can go wrong with it and what all is to be tested to release the same.

MappedSuperclass Alternatives in Grails

In many past projects, I used this JPA / Hibernate approach to add auditing capabilities to a system. It's very effective and unobtrusive.

Is there a Grails @MappedSuperclass alternative (short of coding domain model objects in Java instead of Groovy)? How can one declare a parent class in a table-per-subclass approach without having a table created for it? I've read the GORM documentation (5.2.3 Inheritance in GORM) but besides the table-per-hierarchy vs. table-per-subclass discussion, I did not find any details on how to do this.

Alternatively, what is the recommended way to achieve this type of auditing in Grails?

Thank you in advance for your time.

From stackoverflow
  • OK, did a little bit more searching and I answered my own question :)

    Essentially, it's as simple as declaring the MappedSuperclass as abstract and grails will not create a table for it. I realized by re-reading the manual (RTFM basically...works wonders): "GORM supports inheritance both from abstract base classes and concrete persistent GORM entities." I.e. concrete classes are persistent, so abstract ones are not. Pays to read more carefully.

    E.g.

    abstract class Auditable {
        Date dateCreated
        Date lastUpdated
    }
    
    class Book extends Auditable {
        String title
        String description
    }
    

    Only the book table will be created and it will have the

    date_created

    and

    last_updated

    columns. Furthermore, as an added bonus, the dateCreated and lastUpdated properties are auto time-stamped by Grails.

    Hope this helps others.

  • Yes, it really help me at this monent. Thanks your ambition.