Programming Theory

Programming theory deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features, along with introductory programming concepts like program structure, variable declaration and conditional and looping constructs. Sub-disciplines include the formal semantics of programming languages, type theory, program analysis and transformation, comparative programming language analysis, metaprogramming, domain-specific languages, compiler construction and run-time systems.

Share tech news, updates, or what's on your mind.

Sign up to Post

My WPF project has a MainWindow. The MainWindow has an "Open File" button on the toolbar. The "Open FIle" button when clicked sends an event to my VIewModel saying, "Hey, the user clicked the "Open File" button.

My ViewModel responds with "I need to display an Open File Dialog." It displays the Win32 Open File Dialog, and subscribes to that dialog's "OK" button click event.

User selects a file and clicks "OK".

My ViewModel responds to the "OK" click event, gets the file name from the Open File Dialog, and passes it to the Model, telling the Model, "Hey, the user wants to open this file."

Now I'm thinking of testability. I don't have Visual Studio Enterprise. I should be able to test my ViewModel without it actually displaying an Open File Dialog.

I had a situation where the ViewModel forgot to subscribe to the Open File Dialog's "OK" button click event. I now want to be able to test for this in my unit tests.

And I'm not sure how to do that.

(I'm also not sure if my View (MainWindow) should send a click event "User clicked the Open File icon", or if my View should send a Command "User wants to open a file." I'm thinking Command, since then the VIew can send the same Command when the user clicks the menu option for File Open. Otherwise I have my ViewModel handling the menu File Open click event separately. Are Commands preferable?)
0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

http://codingbat.com/prob/p117630
public Map<String, Integer> wordCount(String[] strings) {
  Map<String, Integer> map=new HashMap<String, Integer>();
  for(String str: strings){
    int i=0;
    if(str.equals(str)){
      i++;
    }
    map.put(str,i);
  }
  return map;
}

Open in new window

Expected      Run            
wordCount(["a", "b", "a", "c", "b"]) → {"a": 2, "b": 2, "c": 1}      {"a": 1, "b": 1, "c": 1}      X      
wordCount(["c", "b", "a"]) → {"a": 1, "b": 1, "c": 1}      {"a": 1, "b": 1, "c": 1}      OK      
wordCount(["c", "c", "c", "c"]) → {"c": 4}      {"c": 1}      X      
wordCount([]) → {}      {}      OK      
wordCount(["this", "and", "this", ""]) → {"": 1, "and": 1, "this": 2}      {"": 1, "and": 1, "this": 1}      X      
wordCount(["x", "y", "x", "Y", "X"]) → {"x": 2, "X": 1, "y": 1, "Y": 1}      {"x": 1, "X": 1, "y": 1, "Y": 1}      X      
wordCount(["123", "0", "123", "1"]) → {"0": 1, "1": 1, "123": 2}      {"0": 1, "1": 1, "123": 1}      X      
wordCount(["d", "a", "e", "d", "a", "d", "b", "b", "z", "a", "a", "b", "z", "x", "b", "f", "x", "two", "b", "one", "two"]) → {"a": 4, "b": 5, "d": 3, "e": 1, "f": 1, "one": 1, "x": 2, "z": 2, "two": 2}      {"a": 1, "b": 1, "d": 1, "e": 1, "f": 1, "one": 1, "x": 1, "z": 1, "two": 1}      X      
wordCount(["apple", "banana", "apple", "apple", "tea", "coffee", "banana"]) → {"banana": 2, "apple": 3, "tea": 1, "coffee": 1}      {"banana": 1, "apple": 1, "tea": 1, "coffee": 1}      X      
other tests
X      

how to fix and improve my code for above challenge?
please advise
0
when i am trying below challenge
http://codingbat.com/prob/p115012

as below
public Map<String, String> mapAB3(Map<String, String> map) {
  if(map.get("a")!=null ){
    
    map.put("b",map.get("a"));
  }
  
   if(map.get("b")!=null){
     map.put("a",map.get("b"));
   }
   return map;
}

Open in new window


public Map<String, String> mapAB3(Map<String, String> map) {
  if(map.get("a")!=null ){
   
    map.put("b",map.get("a"));
  }
 
   if(map.get("b")!=null){
     map.put("a",map.get("b"));
   }
   return map;
}
I am failing one edge case. how to improve my code and fix it. please advise
0
Hi,

I like to see some .class files generated in EAR file. Is there any java free decompiler to do this within eclipse and outside eclipse as well. please advise
0
Hi,


what is difference between below 3 lines




 map.put("ab", map.get("a").concat(map.get("b")));



map.put("ab", map.get("a")+ map.get("b"));

map.put("ab", "null" + map.get("b"));


I passed all tests
http://codingbat.com/prob/p107259
Looking for ways to improve my code and also avoid Null pointer exceptions


Expected	Run		
mapAB({"a": "Hi", "b": "There"}) → {"a": "Hi", "ab": "HiThere", "b": "There"}	{"a": "Hi", "ab": "HiThere", "b": "There"}	OK	
mapAB({"a": "Hi"}) → {"a": "Hi"}	{"a": "Hi"}	OK	
mapAB({"b": "There"}) → {"b": "There"}	{"b": "There"}	OK	
mapAB({"c": "meh"}) → {"c": "meh"}	{"c": "meh"}	OK	
mapAB({"a": "aaa", "ab": "nope", "b": "bbb", "c": "ccc"}) → {"a": "aaa", "ab": "aaabbb", "b": "bbb", "c": "ccc"}	{"a": "aaa", "ab": "aaabbb", "b": "bbb", "c": "ccc"}	OK	
mapAB({"ab": "nope", "b": "bbb", "c": "ccc"}) → {"ab": "nope", "b": "bbb", "c": "ccc"}	{"ab": "nope", "b": "bbb", "c": "ccc"}	OK

Open in new window


please advise
0
Hi,

public Map<String, String> topping2(Map<String, String> map) {
  if(map.get("ice cream")!=null){
    map.put("yogurt", map.get("ice cream"));
  }
  if(map.get("spinach")!=null){
    map.put("nuts", map.get("spinach"));
  }
  else{
    map=map;
  }
  return map;
}

Open in new window

how above code different from below code

public Map<String, String> topping2(Map<String, String> map) {
//public Map < String, String > topping1(Map < String, String > map) {
   // map.put("spinach", "nuts");
    if (map.containsKey("spinach")) {
        map.put("spinach", "nuts");
   }
      if (map.containsKey("ice cream")) {
        map.put("yogurt", map.get("ice cream"));
       // map.put("ice cream", map.get("ice cream"));

   }
    return map;
}

Open in new window


my above first code fails below test
http://codingbat.com/prob/p196458

Expected      Run            
topping2({"ice cream": "cherry"}) → {"yogurt": "cherry", "ice cream": "cherry"}      {"yogurt": "cherry", "ice cream": "cherry"}      OK      
topping2({"spinach": "dirt", "ice cream": "cherry"}) → {"yogurt": "cherry", "spinach": "nuts", "ice cream": "cherry"}      {"yogurt": "cherry", "spinach": "dirt", "ice cream": "cherry", "nuts": "dirt"}      X      
topping2({"yogurt": "salt"}) → {"yogurt": "salt"}      {"yogurt": "salt"}      OK      
topping2({"yogurt": "salt", "bread": "butter"}) → {"yogurt": "salt", "bread": "butter"}      {"yogurt": "salt", "bread": "butter"}      OK      
topping2({}) → {}      {}      OK      
topping2({"ice cream": "air", "salad": "oil"}) → {"yogurt": "air", "ice cream": "air", "salad": "oil"}      {"yogurt": "air", "ice cream": "air", "salad": "oil"}      OK      
0
Hi,

How below solution is different from

public Map<String, String> topping3(Map<String, String> map) {
 // Map<String, String> map=null;
  if(map.get("potato")!=null){
    map.put("fries",map.get("potato"));
  }
    if(map.get("salad")!=null){
    map.put("spinatch",map.get("salad"));
  }
  else
  map=map;
  return map;
  
}

Open in new window


below solution

public Map < String, String > topping3(Map < String, String > map) {
   // map.put("bread", "butter");
    if (map.containsKey("potato")) {
        map.put("fries", map.get("potato"));

    }
     if (map.containsKey("salad")) {
        map.put("spinach", map.get("salad"));

    }
    return map;
}

Open in new window



please advise.

First one does not pass all tests from
http://codingbat.com/prob/p128461
Expected      Run            
topping3({"potato": "ketchup"}) → {"potato": "ketchup", "fries": "ketchup"}      {"potato": "ketchup", "fries": "ketchup"}      OK      
topping3({"potato": "butter"}) → {"potato": "butter", "fries": "butter"}      {"potato": "butter", "fries": "butter"}      OK      
topping3({"salad": "oil", "potato": "ketchup"}) → {"spinach": "oil", "salad": "oil", "potato": "ketchup", "fries": "ketchup"}      {"salad": "oil", "spinatch": "oil", "potato": "ketchup", "fries": "ketchup"} missing: "spinach": "oil"      X      
topping3({"toast": "butter", "salad": "oil", "potato": "ketchup"}) → {"toast": "butter", "spinach": "oil", "salad": "oil", "potato": "ketchup", "fries": "ketchup"}      {"toast": "butter", "salad": "oil", "spinatch": "oil", "potato": "ketchup", "fries": "ketchup"} missing: "spinach": "oil"      X      
topping3({}) → {}      {}      OK      
topping3({"salad": "pepper", "fries": "salt"}) → {"spinach": "pepper", "salad": "pepper", "fries": "salt"}      {"salad": "pepper", "spinatch": "pepper", "fries": "salt"} missing: "spinach": "pepper"      X      
other tests
OK
0
I seek a list of 20 most important design patterns in computing today.

I am a C#.NET Full Stack developer, so that may bias which patters are the top 20 for me.

I want to make myself a faster programmer and able to code more on my feet under pressure. And having tried and true patterns on the top of your mind, will help.

Thanks.
0
import java.util.*;
import java.util.stream.*;
public class X {
	public static void main(String[] args) {
		List<String> list = Arrays.asList("xxax", "xbxbx", "xxcx", "zzz");
		System.out.println(noX(list));
	}
	public static List<String> noX(List<String> strings) {
		return strings.stream().map(s -> s.replaceAll("x","")).collect(Collectors.toList());
    }	
}

Open in new window

in above program what are Collectors , stream, collect methods. And why map is used in this lamda functional examples
0
http://codingbat.com/prob/p128270
public int[] front11(int[] a, int[] b) {
 
  if (a.length==0) return new int[]{b[0]};
  if (b.length==0) return new int[]{a[0]};
   if ((a.length==0) && (b.length==0)) return new int[]{};
  return new int[]{a[0],b[0]};
}





public int[] front11(int[] a, int[] b) {
    if ((a.length==0) && (b.length==0)) return new int[]{};
  if (a.length==0) return new int[]{b[0]};
  if (b.length==0) return new int[]{a[0]};

  return new int[]{a[0],b[0]};
}




why first one fails below test with ArrayIndexOutOfBoundsException
Expected	Run		
front11([1, 2, 3], [7, 9, 8]) → [1, 7]	[1, 7]	OK	
front11([1], [2]) → [1, 2]	[1, 2]	OK	
front11([1, 7], []) → [1]	[1]	OK	
front11([], [2, 8]) → [2]	[2]	OK	
front11([], []) → []	ArrayIndexOutOfBoundsException: 0 (line:3)	X	
front11([3], [1, 4, 1, 9]) → [3, 1]	[3, 1]	OK	
front11([1, 4, 1, 9], []) → [1]	[1]	OK	
other tests
OK	
Correct for more than half the tests

Your progress graph for this problem

Open in new window


please advise
0
Want to be a Web Developer? Get Certified Today!
LVL 9
Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

I have been reading about the Turing machine lately.  My question for you does the average laptop meet criteria for being a turing machine?  It works different, but I think it can do everything a turning machine can do.

Would you agree or disagree?

Thanks.
0
Hi all,
Does anyone plan before they code?

I usually just dive straight in, I know what I want a certain script to do, but the actual structure, functions, queries etc, I discover and code on the go.

Does anyone write a simplified version of their code before they start (in Word or something)? If so, do you use any specialised tools?
0
A slightly theoretical question.

A company is developing a cloud service based on PHP/mySQL etc. They have the source code on their own servers.

However, they want to start using external developers to create particular features.

How can they share part of the source code with those developers, without giving them access to the whole thing?

I was thinking that something like GitHub might support that, but it doesnt appear that it does.

Any ideas, or products you know of?
It would essentially be giving a certain developer access to a certain file, and then revoking that access when they had completed their work. I guess it would also need some sort of version control.
1
I am trying to sort a multi-dimensional array.  In my code, I capture data (item 'ID' and 'Priority' value) from my SharePoint list and dump it into an array as objects.  For some odd reason, it does not get inserted in the order I expected so I am trying to sort the array by the 'ID'.
Here's my code that created the array of objects.
/*Array will contain two values, item id and new priority value. Global so it can be used in multiple functions.*/
var items = [];
var itemsID = [];
var projItemArray = new Array();
var i = 0;	

/*-------------------------------------------------------------------------------------------------------*/
//Success on data retrieval from 'retrieveListItems()'. Transforms HTML table to datatable and creates
//range functionality.
/*-------------------------------------------------------------------------------------------------------*/		
function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();

    //Will be used to build object array of ID and priorityNumber
    //var projItemArray = new Array();    	

    //1st call to retrieve the level. 2nd call below while loop
    var levels = determineGroup();
    // alert("onQuery: "+levels);

    var i = 0;
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();

        var itemUid = oListItem.get_item('ID');
        var colVal;
        var valSelect = " ";
        if 

Open in new window

0
Does anyone know of a good tutorial on building a survey system using PHP.

I'm having trouble wrapping my head around how branching on a survey works (where some questions are hidden unless the answer to another equals something), in particular how the concept would work in terms of storing that data in a table and then using it at run time.
0
I have been using VBA for some years and have many, increasingly complex applications. I am at a point now where I am spending large amounts of time trying to debug my applications. Procedures which have worked successfully in the past are not working now. I suspect it is to do with the use of events and turning events on and off. But I also use a lot of code tracking procedures and I protect my worksheets. I think that my solution requires me to choose a method of showing my programme flow more visually and to use a diagramming methodology for doing this. I wonder whether I should invest my time in converting my applications to object-based methodologies using classes, and move to UML diagramming. I would greatly value advice on this matter. I attach an application that is confounding me at present. Many thanks for any assistance you can provide.
2017-03-24_SEBIS-Cash-Book_Developm.xlsm
0
Hi All,
Would you recommend a website(s) where it will show me the condensed basics of college level statistics in laymen’s terms – so that quickly I can understand the core and key concepts? and apply those conceptas in real life  
Thank you
0
Hi,
what are differences, advantages, disadvantages between

dao vs facade design patterns used i java and j2ee applications?
please advise
0
Hi All, I am creating a simple module using API.AI where API will ask set of 10 questions and retrieve answers.I In between of these question set i.e. after question 3, i want to handle in between user queries using other intent also but after handling those queries, I want to return back to the original question set i.e. question 4. Can we do this ? if not what is the suitable way of handling such scenario?
0
Free Tool: SSL Checker
LVL 9
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

In API.AI, @system.given-name can recognize English names. I want to create a module for india. Do we have any method by which we can use such kind of concept for indian names?
0
When an application is started, what are the steps it goes through until data is saved and the application is closed? What are the interactions with the registry and .ini files etc.

Ex. - 1. Executable is left mouse clicked. 2. The application takes the credentials and authenticate. 3. Assigns privileges etc.

Where does the security token fit in this sequence?
Where does the registry/ini files fit is this sequence?

I want to put the answer in a diagram to assist with troubleshooting
0
Hi All,

I'm looking for some best practices and lessons learned real world experience.  This is more of a high-level programming architecture for how our programming patterns are going to be laid out.

The one thing I'm sure of is that I want everything to go thru our classes.  I don't want multiple definitions of the same code on multiple pages where we're trying to find out everywhere we need to update them.  The page (we're currently still using webforms) calls the class, the class calls EF, and all custom logic is done inside the class.

The issues we're coming across are when dealing with joins, anonymous types, and the like.  Our developers are worried about select all columns every time for all queries as we've seen that can hamper performance.  If we do dynamic types then we lose intellisense and open ourselves up to runtime errors.  

We've seen a bunch of other sites recommend using custom classes for each result set, but I can picture that getting messy with the amount of tables / joins / applications we have that cross reference each other.  

We can return IQuerables, select the columns with intellisense, but then we're limited to a single object and aren't sure if that'll work if we need to update the data we're retrieving.  

So I'm asking the community what patterns they use and what they wish they knew when designing the way they were going to use EF from the ground up.  Any and all help greatly appreciated.
0
What is counting semaphore?
0
My teacher told me to write a digest paper. What is a digest paper?
0
How would you construct Excel formulas to accomplish the following?

I received a call from my son yesterday who informed me that he and his siblings (including spouses) would like to do a holiday gift exchange and asked if I would randomly come up with a name for each person using the following rules:

• each person is to give one and only one gift
• each person must receive one and only one gift
• no one can be assigned their own name
• no one can be assigned the name of their spouse (if applicable)

I have four children and all but one are married. So if each person is represented by a letter, it would appear as follows (with my biological children in the left column and their spouses on the right):

A — B
C — D
E
G — H

Thanks
0

Programming Theory

Programming theory deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features, along with introductory programming concepts like program structure, variable declaration and conditional and looping constructs. Sub-disciplines include the formal semantics of programming languages, type theory, program analysis and transformation, comparative programming language analysis, metaprogramming, domain-specific languages, compiler construction and run-time systems.