Categories

## Can someone summarise visibility choices for Java interfaces?

Can someone summarise visibility choices for Java interfaces?

10 years, 9 months ago

Active
10 years, 9 months ago

Viewed
196 times

margin-bottom:0;
}

1

I have two questions really:

1) When would you use a package-private interface?

2) Is there a way to have a public interface which is closed for implementation outside its package?

java oop api-design

share|improve this question

asked May 17 ’09 at 20:53

GeorgiGeorgi

|

3

active

oldest

5

1) when the interface is only needed in the scope of your package. For example an interface could make your code more readable, but the callers of the package have no need for it.

2) No, this isn’t possible. See this link for more info. An interface defines no implementation. How could you close it for implementation then?

answered May 17 ’09 at 21:00

kgiannakakiskgiannakakis

|

2

Package private interfaces are only useful in cases such implementations of the strategy pattern, where by there are several implementations that you may wish to use but dont want the world to be aware of the types.

answered May 17 ’09 at 21:26

mP.mP.

|

0

1) You may have utility methods used by multiple classes in your package which should never be called externally. Or they may be only needed by one class, but that class is so large you want to move some methods to another class for maintainability.

2) I would have to try it out (sorry, I’m rushing out the door now), but you might be able to effectively do that by declaring a protected default constructor in the interface.

answered May 17 ’09 at 21:25

dj_segfaultdj_segfault

You can’t declare constructors in an interface, note. Above note is right, if it’s public, it can be implemented anywhere.

– Sean Owen
May 17 ’09 at 22:56

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

Related

3219How do I efficiently iterate over each entry in a Java Map?761Interface vs Base class808What does it mean to “program to an interface”?490Why can’t I define a static method in a Java interface?1392Interface vs Abstract Class (general OO)1693Comparing Java enum members: == or equals()?462How should I have explained the difference between an Interface and an Abstract class?519Interface with default methods vs Abstract class in Java 81348Why not inherit from List<T>?331Why is “final” not allowed in Java 8 interface methods?

Hot Network Questions

How to write this function in idiomatic bash?

What’s the difference between a rolled chord and a broken chord?

Buddhism broke up my marriage

Is it a reasonable strategy to keep the ratio of investments constant?

What exactly is the difference between all these dairy products?

Why doesn’t \$1 work in this small bash function?

What is the likely result of rent control in Berlin?

Make shapefile from raster-bounds in Python

What’s the right way to place these capacitors

How is Russia able to maintain the 2nd most powerful military in the world at a fraction of the cost of the US?

My pushups don’t increase

tubular tire replacement

Is it safe to plug a power strip into a voltage converter?

How to implement BlazeFace?

Transform dollars in exact change

Sum of squares and partitions

Where in 5e does it state that the Plane Shift spell’s target plane has to be the plane that its tuning fork is attuned to?

Embedding Sets of Sets

Apollo 4 vs Apollo 8 plume

A drinks party underwater?

Does music all over the world tend to centre on a single note which is returned to, and split up the range of pitches most fundamentally into octaves?

Why haven’t the Borg tried to assimilate the Talosians from Talos IV?

more hot questions

Question feed

Question feed

lang-java

Categories

## AuthenticateRequest event

AuthenticateRequest event

10 years, 9 months ago

Active
7 years, 7 months ago

Viewed
68k times

margin-bottom:0;
}

41

18

Q 1. To my understanding FormsAuthenticationModule is subscribed to AuthenticateRequest event, and thus only after this event is fired, is FormsAuthenticationModule called. But the following quotes got me a bit confused:

The AuthenticateRequest event signals that the configured authentication mechanism has authenticated the current request.

Doesn’t the above quote suggest that when AuthenticateRequest event is raised, request (aka user) is already authenticated?

Subscribing to the AuthenticateRequest event ensures that the request will be authenticated before processing the attached module or event handler.

As far as I understand this quote, if we subscribe to AuthenticatedRequest, then our event handler will be called prior to FormsAuthenticationModule? Thus Application_AuthenticateRequest() will be called before FormsAuthenticationModule is called?

Q 2. Book I’m learning from suggests that within Application_AuthenticateRequest() we are able to verify whether user is a member of specific role, and if not, we can add the user automatically:

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated && Roles.Enabled)
{

//here we can subscribe user to a role via Roles.AddUserToRole()
}
}

Judging from the above code, Application_AuthenticateRequest() is called after FormsAuthenticationModule has been invoked, but somewhere else same book implies that Application_AuthenticateRequest() is called prior to FormsAuthenticationModule:

Application_AuthenticateRequest is called just before authentication is performed.
This is a jumping-off point for creating your own authentication logic.

What am I missing?

Thanx

c# asp.net authentication forms-authentication httpapplication

share|improve this question

edited Jul 10 ’12 at 10:59

escist

asked May 17 ’09 at 20:53

SourceCSourceC

|

2

active

oldest

52

It seems that the FormsAuthenticationModule gets handled first. This module is normally earlier than any custom module in the ASP.NET pipeline, so when AuthenticateRequest is fired, FormsAuthenticationModule will get called first, do its job and then your module’s event handler will be called.

If you really want to dig deep into this, I suggest trying to debug the ASP.NET code yourself. Here is a post how to set up your VS:

http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx

EDIT: I was able to confirm this behavior by setting up a web project with custom module and event handlers in Global.asax. Take a look at the source code of HttpApplication.InitInternal, the order of initialization is as follows:

initialization of integrated modules: FormsAuthenticationModule hooks up to HttpApplication.AuthenticateRequest event
initialization of custom modules: custom module hooks up to HttpApplication.AuthenticateRequest event
initialization of Global class (global.asax): here we hook up to the AuthenticateRequest event
HttpApplication.InitInternal searches for methods on Global class following the specific name pattern (e.g. Application_AuthenticateRequest), matches them to event and hooks up

After the initialization, when the AuthenticateRequest fires, the event handlers are called in the order they where initialized, so:

FormsAuthenticationModule.AuthenticateRequest event handler
CustomModule.AuthenticateRequest event handler
Global.AuthenticateRequest event handler
Global.Application_AuthenticateRequest method

Unless I missed something, there is no mechanism for stopping the event handlers to fire, so no matter what the result of FormsAuthenticationModule.AuthenticateRequest, the next handlers will still be called. I hope that helps.

edited May 17 ’09 at 23:07

answered May 17 ’09 at 21:40

bbmudbbmud

Q1 If I understand you correctly, then when AuthenticateRequest fires, FormsAuthenticationModule is called first, then Application_AuthenticateRequest() and only then are custom authentication modules called? Q2 – But what about that MSDN quote (“The AuthenticateRequest event signals that the configured authentication mechanism has authenticated the current request”), which implies that AuthenticateRequest is fired only after FormsAuthenticationModule does its job?

– SourceC
May 17 ’09 at 22:10

1

Detailed answer in the post. Regarding Q2 – I guess it is not entirely true: “The AuthenticateRequest event signals that the configured authentication mechanism has authenticated the current request” – it certainly went through the event handler on FormsAuthenticationModule, but we do not know the result 😉

– bbmud
May 17 ’09 at 23:10

1

thanx. You’ve really helped me out with this

– SourceC
May 18 ’09 at 0:09

1

One little note: the FormsAuthenticationModule.Authenticate event (not called AuthenticateRequest) is called [during the Application.AuthenticateRequest event](FormsAuthenticationModule). You can register to that event just as you can to any other, using the predefined names in global.asax.

– Abel
Aug 26 ’10 at 0:38

Thank you so much for this post. I expected the HttpApplication class to have an interface where it explicitly defined the Application_AuthenticateRequest() method.

– dionysus
Oct 28 ’16 at 13:56

|

5

If you want access to the User object, I’d suggest you use

protected void Application_Start()
{
PostAuthenticateRequest += Application_PostAuthenticateRequest;
}

protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
if(User.Identity.IsAuthenticated)
{
//Do stuff here
}
}

answered Feb 20 ’12 at 12:03

ShelakelShelakel

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Not the answer you’re looking for? Browse other questions tagged c# asp.net authentication forms-authentication httpapplication or ask your own question.

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

15

Infinite redirect loop for Basic or Windows authentication?

6

How would an HttpModule for Custom Authentication interact with Windows Authentication?

3

How to know when login is successful working with the asp.net web application template

0

Custom FormsAuthenticationTicket validation

0

Allow unauthenticated access while keeping IIS Windows authentication and occasional impersonation

0

Global.asax or http handler

0

Related

0Why should derived classes handle an event without attaching a delegate?1Handling Login.Authenticate event0Why should we choose PrincipalPermission over IsInRole()?3RoleManagerModule and RolePrincipal object3If authentication ticket also contains information about roles, then why…?4Data binding and user controls1FormsAuthentication.RedirectFromLoginPage – really strange and inconsistent results779Ajax request returns 200 OK, but an error event is fired instead of success284Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated

Hot Network Questions

Generic Heap Implementation in C#

How safe it is in the long run to regularly invest in the stock market?

Feeding a newborn throughout the night without letting him cry

Counting the occurrence of a specific letter within a string (QGIS)?

“Have you been granted any UK visas in the last 10 years?”

How could humans reach distant stars and still stay as a united government if you can’t use faster than light travel

Viability of a Matchlock Rotary Gun?

Strange JOIN ON clause in T-SQL

How to best deal with cliques at the table during “downtime”?

How to cut pipe squarely using an angle grinder

What exactly is the difference between all these dairy products?

Square-Cube Digit Usage

Why would a part be available as 4.99k and 5k?

Would lightning be an effective weapon against Cybermen?

Does music all over the world tend to centre on a single note which is returned to, and split up the range of pitches most fundamentally into octaves?

Once they thought that I am a hoax – What am I?

Trying to draw benzene triozonide using chemfig

Deciphering a sentence

Catching Pokemon with TikZ … and why ducks matter

How dangerous are RCS thrusters?

Clip a wall to a 6 or 7L pole

Transform dollars in exact change

combinatorial proof of Catalan’s identity

more hot questions

Question feed

Question feed

lang-cs

Categories

## editing a wav files using python

editing a wav files using python

10 years, 9 months ago

Active
2 years, 6 months ago

Viewed
21k times

margin-bottom:0;
}

4

8

Between each word in the wav file I have full silence (I checked with Hex workshop and silence is represented with 0’s).

How can I cut the non-silence sound?

I’m programming using python.

Thanks!

python audio

share|improve this question

edited Aug 12 ’17 at 1:19

Joshua Dawson

asked May 17 ’09 at 20:54

John TerryJohn Terry

You should consider clarifying your question a little bit. I want to know if you’re trying to remove the silence, or actually split your audio into separate chunks?

– Soviut
May 18 ’09 at 3:26

|

6

active

oldest

17

Python has a wav module. You can use it to open a wav file for reading and use the getframes(1)’ command to walk through the file frame by frame.

import wave
w = wave.open(‘beeps.wav’, ‘r’)
for i in range():

The frame returned will be a byte string with hex values in it. If the file is stereo the result will look something like this (4 bytes):

‘xe2xffxe2xff’

If its mono, it will have half the data (2 bytes):

‘xe2xff’

Each channel is 2 bytes long because the audio is 16 bit. If is 8 bit, each channel will only be one byte. You can use the getsampwidth() method to determine this. Also, getchannels() will determine if its mono or stereo.

You can loop over these bytes to see if they all equal zero, meaning both channels are silent. In the following example I use the ord() function to convert the ‘xe2’ hex values to integers.

import wave
w = wave.open(‘beeps.wav’, ‘r’)
for i in range(w.getnframes()):
### read 1 frame and the position will updated ###

all_zero = True
for j in range(len(frame)):
# check if amplitude is greater than 0
if ord(frame[j]) > 0:
all_zero = False
break

if all_zero:
print ‘silence found at frame %s’ % w.tell()
print ‘silence found at second %s’ % (w.tell()/w..getframerate())

It is worth noting that a single frame of silence doesn’t necessarily denote empty space since the amplitude may cross the 0 mark normal frequencies. Therefore, it is recommended that a certain number of frames at 0 be observed before deciding if the region is, in fact, silent.

edited Jan 28 ’14 at 10:24

Jeff

answered May 17 ’09 at 23:50

SoviutSoviut

1

bytes can occur in the pure sine wave when crossing 0! Imagine a 44100Hz sampled file on a 11025Hz sine wave to see what I mean. I don’t -1, as the rest of the answer is very good.

– Paweł Polewicz
May 19 ’09 at 8:51

1

readframes(i) returns i frames in sequence, not 1 frame at position i. So your loop will return 1 frame, then 2 frames, then 3 frames, etc. it should be readframes(1) not readframes(i).

– gravitron
Dec 2 ’11 at 17:24

1

Fixed, though I’m taking your word on this.

– Soviut
Dec 3 ’11 at 5:25

Remember that 8-bit wavs are unsigned while 16-bit wavs are signed. Not sure how python’s wave handles this. I’d rather use a higher-level library like audiolab.

– endolith
Mar 21 ’12 at 16:00

@Soviut What is ord(frame[j]) ? Is it the amplitude of the wave?

– Jaseem
Oct 28 ’12 at 21:36

|
show 1 more comment

6

I have been doing some research on this topic for a project I’m working on and I came across a few problems with the solution provided, namely the method for determining silence is incorrect. A “more correct” implementation would be:

import struct
import wave

wave_file = wave.open(“sound_file.wav”, “r”)

for i in range(wave_file.getnframes()):

# check for silence
silent = True
# wave frame samples are stored in little endian**
# this example works for a single channel 16-bit per sample encoding
unpacked_signed_value = struct.unpack(“<h”, current_frame) # *
if abs(unpacked_signed_value[0]) > 500:
silent = False

if silent:
print “Frame %s is silent.” % wave_file.tell()
else
print “Frame %s is not silent.” % wave_file.tell()

*Struct Unpacking will be useful here: https://docs.python.org/2/library/struct.html

**A good reference I found explaining the format of wave files for dealing with different size bit-encodings and multiple channels is: http://www.piclist.com/techref/io/serial/midi/wave.html

Using the built-in ord() function in Python on the first element of the string object returned by the readframes(x) method will not work correctly.

Another key point is that multiple channel audio is interleaved and thus a little extra logic is needed for dealing with channels. Again, the link above goes into detail about this.

Hopefully this helps someone in the future.

Here are some of the more important points from the link, and what I found helpful.

Data Organization

All data is stored in 8-bit bytes, arranged in Intel 80×86 (ie, little endian) format. The bytes of multiple-byte values are stored with the low-order (ie, least significant) bytes first. Data bits are as follows (ie, shown with bit numbers on top):

7 6 5 4 3 2 1 0
+———————–+
char: | lsb msb |
+———————–+

7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8
+———————–+———————–+
short: | lsb byte 0 | byte 1 msb |
+———————–+———————–+

7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 23 22 21 20 19 18 17 16 31 30 29 28 27 26 25 24
+———————–+———————–+———————–+———————–+
long: | lsb byte 0 | byte 1 | byte 2 | byte 3 msb |
+———————–+———————–+———————–+———————–+

Interleaving

For multichannel sounds (for example, a stereo waveform), single sample points from each channel are interleaved. For example, assume a stereo (ie, 2 channel) waveform. Instead of storing all of the sample points for the left channel first, and then storing all of the sample points for the right channel next, you “mix” the two channels’ sample points together. You would store the first sample point of the left channel. Next, you would store the first sample point of the right channel. Next, you would store the second sample point of the left channel. Next, you would store the second sample point of the right channel, and so on, alternating between storing the next sample point of each channel. This is what is meant by interleaved data; you store the next sample point of each of the channels in turn, so that the sample points that are meant to be “played” (ie, sent to a DAC) simultaneously are stored contiguously.

edited Aug 5 ’14 at 4:54

answered Aug 5 ’14 at 2:05

|

2

See also How to edit raw PCM audio data without an audio library?

edited May 23 ’17 at 12:25

Community♦

answered May 18 ’09 at 15:19

tzottzot

|

1

I have no experience with this, but have a look at the wave module present in the standard library. That may do what you want. Otherwise you’ll have to read the file as a byte stream an cut out sequences of 0-bytes (but you cannot just cut out all 0-bytes, as that would invalidate the file…)

answered May 17 ’09 at 21:00

Stephan202Stephan202

|

1

You might want to try using sox, a command-line sound processing tool. It has many modes, one of them is silence:

silence: Removes silence from the beginning, middle, or end of a sound file. Silence is anything below a specified threshold.

It supports multiple sound formats and it’s quite fast, so parsing large files shouldn’t be a problem.

To remove silence from the middle of a file, specify a below_periods that is negative. This value is then treated as a positive value and is also used to indicate the effect should restart processing as specified by the above_periods, making it suitable for removing periods of silence in the middle of the sound file.

I haven’t found any python building for libsox, though, but You can use it as You use all command line programs in python (or You can rewrite it – use sox sources for guidance then).

answered May 17 ’09 at 21:46

Paweł PolewiczPaweł Polewicz

|

1

You will need to come up with some threshold value of a minimum number of consecutive zeros before you cut them. Otherwise you’ll be removing perfectly valid zeros from the middle of normal audio data. You can iterate through the wave file, copying any non-zero values, and buffering up zero values. When you’re buffering zeroes and eventually come across the next non-zero, if the buffer has fewer samples that the threshold, copy them over, otherwise discard it.

Python is not a great tool for this sort of task though. 🙁

answered May 18 ’09 at 12:44

KylotanKylotan

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

94

Detect & Record Audio in Python

9

How to edit raw PCM audio data without an audio library?

Related

5417How do I check whether a file exists without exceptions?4731Calling an external command from Python5569What are metaclasses in Python?2330How do I copy a file in Python?3014Finding the index of an item given a list containing it in Python5816Does Python have a ternary conditional operator?2737How to get the current time in Python3473How do I list all files of a directory?3600Does Python have a string ‘contains’ substring method?

Hot Network Questions

“Have you been granted any UK visas in the last 10 years?”

Is there a way to save a command in Ubuntu terminal if I haven’t entered it?

Is a dystopian surveillance state computationally possible?

EOL Win7 out, Ubuntu in

What is the likely result of rent control in Berlin?

Why haven’t the Borg tried to assimilate the Talosians from Talos IV?

Single Digit Representations of Natural Numbers

What does “Shocks/Chills enemies as though dealing X% more damage” mean?

How to prevent crew from accidentally teleporting oneself outside a spaceship with portal gun?

Does music all over the world tend to centre on a single note which is returned to, and split up the range of pitches most fundamentally into octaves?

Was Change UK the shortest-lived political party ever?

How is Russia able to maintain the 2nd most powerful military in the world at a fraction of the cost of the US?

Which subatomic particle does each company use in quantum computing?

My pushups don’t increase

I used a fork of a GitHub repository whose paper I cited – should I also cite the fork?

Do not vote, one vote will not reverse election results. What is wrong with this reasoning?

How dangerous are RCS thrusters?

Continental US Air Routes that Require More than 2 Stops?

What is the best strategy for an amateur to last as many moves as possible against a GM?

One hand was “rotated” through higher dimensions -> two right (or left hands) – Broadcast on 20th century US TV

An effective way for interstellar communication?

Catching Pokemon with TikZ … and why ducks matter

Would lightning be an effective weapon against Cybermen?

What’s the difference between a rolled chord and a broken chord?

more hot questions

Question feed

Question feed

lang-py

Categories

## Greasemonkey script for inserting math in gmail

Greasemonkey script for inserting math in gmail

10 years, 9 months ago

Active
2 years, 3 months ago

Viewed
3k times

margin-bottom:0;
}

7

4

I wish an easy way to communicate mathematical equations with gmail.

There’s a javascript script called AsciiMath, which should translate Tex-like equations into standard mathML.

I thought that it would be nice to use this script with GM. I thought that before sending the email, this script would convert all the TeX-like equations in your email to MathML. Thus the reader which is using FF (or IE with MathPlayer installed) would be able to easily read those equations.

Ideally, I wish to somehow keep the original TeX-like equations in a plain-text message, so that it would be readable by plain text email clients, such as mutt.

Obviously the weakest link here is the client software, which most likely doesn’t support MathML. Still if my correspondent is using Firefox and some kind of webmail (which is pretty reasonable) – it should work.

My question is, is it possible? Did anyone do that?

Do you see any technical problems with this approach (gmail filtering the MathML, client not parsing it correctly etc.)?

Any smarter ideas?

javascript email latex gmail mathml

share|improve this question

asked May 17 ’09 at 20:54

Elazar LeibovichElazar Leibovich

|

4

active

oldest

6

GmailTeX does exactly what you want. It is pure javascript so it works in Firefox, Chrome, Opera.

answered Jun 14 ’10 at 1:52

saturnsaturn

1

Awesome! That guy taught my Calc 2 class.

– krousey
Sep 9 ’10 at 14:22

|

2

What about using texify and converting it just to a html image or a link to that image? This would save some work with parsing and converting the tex math code and wold work fine even with simple mail clients.

answered May 17 ’09 at 21:17

cubecube

Most clients would, by default, block images linked with other websites. And it would make all your correspondence depend on textify. This is possible, if I’ll find out most email clients show the alt-text instead of the image by default. Thanks.

– Elazar Leibovich
May 18 ’09 at 7:06

1

texify.com no longer allows direct hot-linking of images; I use code.google.com/apis/chart/docs/gallery/formulas.html now.

– ephemient
Feb 20 ’10 at 21:41

|

0

Depending on whom you communicate with the easiest solution is sometimes to email raw tex.

answered May 18 ’09 at 15:00

secondsecond

|

0

As far as I can figure out, GmailTeX (suggested in the top answer) does not work in Firefox anymore.

I can suggest the browser plugin MathQuill for Gmail (also exists for Chrome), which allows to edit formulas within the Gmail compose window, and converts them into pictures. (Like GmailTeX in concept, but with an interactive editor.)

Disclaimer: I am the author of the plugin.

edited Nov 27 ’17 at 9:57

answered Nov 23 ’17 at 9:39

Dominique UnruhDominique Unruh

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Not the answer you’re looking for? Browse other questions tagged javascript email latex gmail mathml or ask your own question.

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

4

Run Javascript on the body of a Gmail message

Related

861Sending email in .NET through Gmail1309Why don’t self-closing script elements work?1432Where should I put <script> tags in HTML markup?2810How to insert an item into an array at a specific index (JavaScript)?387Send email using the GMail SMTP server from a PHP page43What’s the best way to write Mathematical Equations on the Web?403Inserting code in this LaTeX document with indentation10MathJax/jsMath alternatives?5Setup for Gmail in Emacs VM1Send Events to Google Analytics for Gmail Incoming Emails

Hot Network Questions

Word square thriller

PTIJ: Joseph and the time machine

How can I provide an answer to Neural Network skeptics?

Where in 5e does it state that the Plane Shift spell’s target plane has to be the plane that its tuning fork is attuned to?

Instructor listening in secretly in simulated intake assignment — allowed? Ethical?

Would lightning be an effective weapon against Cybermen?

Are creatures with the immune to poisoned condition immune to poison damage?

Physical Meaning of the Coriolis Force

What is the phrase represented by this rebus?

What is it called when opposite colored pawns up against each other?

Graph Union with Color Properties Kept

Do not vote, one vote will not reverse election results. What is wrong with this reasoning?

Why haven’t the Borg tried to assimilate the Talosians from Talos IV?

How dangerous are RCS thrusters?

Transform dollars in exact change

Counting the occurrence of a specific letter within a string (QGIS)?

Should I tell interviewer that I will use their offer to renegotiate current rate first?

What exactly is the difference between all these dairy products?

Is a dystopian surveillance state computationally possible?

Summing a sub-square of a quarter of an infinite chessboard

Feeding a newborn throughout the night without letting him cry

What does 5以内 mean in 数学作业要在3分钟之内完成90道5以内的加减法题?

Is it a reasonable strategy to keep the ratio of investments constant?

How to cut pipe squarely using an angle grinder

more hot questions

Question feed

Question feed

default

Categories

## What is the difference between a .cpp file and a .h file?

What is the difference between a .cpp file and a .h file?

10 years, 9 months ago

Active
3 years, 3 months ago

Viewed
117k times

margin-bottom:0;
}

61

12

Because I’ve made .cpp files then transfered them into .h files, the only difference I can find is that you can’t #include .cpp files. Is there any difference that I am missing?

share|improve this question

edited May 18 ’09 at 16:56

Kent Fredric

asked May 17 ’09 at 20:54

user98188user98188

1

To understand people’s answers below, you might need to ask another question: i.e. “What’s the difference between a ‘declaration’ and a ‘definition’ in C++?”

– ChrisW
May 17 ’09 at 21:00

1

I know the difference between a declaration and a definition.

– user98188
May 17 ’09 at 21:23

2

You can include anything you want, but linking stage will break if you include global variables into more than one compilation units. That’s why there is a convention to not link .cpp files.

– John Smith
May 17 ’09 at 22:16

|

8

active

oldest

61

The C++ build system (compiler) knows no difference, so it’s all one of conventions.

The convention is that .h files are declarations, and .cpp files are definitions.

That’s why .h files are #included — we include the declarations.

answered May 17 ’09 at 20:57

MackerMacker

The C++ build system does differentiate – try running g++ on a .h file and a .cpp file and see what happens, for example.

– anon
May 17 ’09 at 21:09

I know that .cpp files are used (most of the time) to define functions/classes/etc that have been declared in .h files, but you can define variables in .h files too.

– user98188
May 17 ’09 at 21:25

5

@Neil Butterworth: Yes the G++ compiler understands the convention, but you can make it compile by forcing the language.

– Martin York
May 18 ’09 at 15:03

|

24

The .cpp file is the compilation unit : it’s the real source code file that will be compiled (in C++).

The .h (header) files are files that will be virtually copy/pasted in the .cpp files where the #include precompiler instruction appears. Once the headers code is inserted in the .cpp code, the compilation of the .cpp can start.

answered May 17 ’09 at 20:59

KlaimKlaim

1

Why do you say THE .cpp file and not A .cpp file?

– user98188
May 17 ’09 at 21:26

12

@Keand64: Because the compiler looks at only one .cpp file at a time when compiling things. It reads a .cpp file, reads all the #included .h files, compiles the whole thing, writes a .o (or .obj) file, and then proceeds to the next .cpp file.

– Greg Hewgill
May 17 ’09 at 21:50

Does this mean that .cpp and .h must have the same name?

– fathergorry
20 hours ago

|

12

I know the difference between a declaration and a definition.

Whereas:

A CPP file includes the definitions from any header which it includes (because CPP and header file together become a single ‘translation unit’)
A header file might be included by more than one CPP file
The linker typically won’t like anything defined in more than one CPP file

Therefore any definitions in a header file should be inline or static. Header files also contain declarations which are used by more than one CPP file.

Definitions that are neither static nor inline are placed in CPP files. Also, any declarations that are only needed within one CPP file are often placed within that CPP file itself, nstead of in any (sharable) header file.

answered May 17 ’09 at 21:37

ChrisWChrisW

|

9

A header (.h, .hpp, …) file contains

Class definitions ( class X { … }; )
Inline function definitions ( inline int get_cpus() { … } )
Function declarations ( void help(); )
Object declarations ( extern int debug_enabled; )

A source file (.c, .cpp, .cxx) contains

Function definitions ( void help() { … } or void X::f() { … } )
Object definitions ( int debug_enabled = 1; )

However, the convention that headers are named with a .h suffix and source files are named with a .cpp suffix is not really required. One can always tell a good compiler how to treat some file, irrespective of its file-name suffix ( -x <file-type> for gcc. Like -x c++ ).

Source files will contain definitions that must be present only once in the whole program. So if you include a source file somewhere and then link the result of compilation of that file and then the one of the source file itself together, then of course you will get linker errors, because you have those definitions now appear twice: Once in the included source file, and then in the file that included it. That’s why you had problems with including the .cpp file.

answered May 17 ’09 at 21:32

Johannes Schaub – litbJohannes Schaub – litb

|

7

.h files, or header files, are used to list the publicly accessible instance variables and and methods in the class declaration. .cpp files, or implementation files, are used to actually implement those methods and use those instance variables.

The reason they are separate is because .h files aren’t compiled into binary code while .cpp files are. Take a library, for example. Say you are the author and you don’t want it to be open source. So you distribute the compiled binary library and the header files to your customers. That allows them to easily see all the information about your library’s classes they can use without being able to see how you implemented those methods. They are more for the people using your code rather than the compiler. As was said before: it’s the convention.

answered May 17 ’09 at 21:00

Marc WMarc W

|

2

Others have already offered good explanations, but I thought I should clarify the differences between the various extensions:

Source Files for C: .c

Source Files for C++: .cpp

Of course, as it has already been pointed out, these are just conventions. The compiler doesn’t actually pay any attention to them – it’s purely for the benefit of the coder.

answered May 17 ’09 at 21:04

NoldorinNoldorin

4

Most people actually use .h for C++ too.

– Zifre
May 17 ’09 at 21:35

@Zifre: Yes, hence my saying that these are recommended naming conventions, even though many may not follow them.

– Noldorin
May 17 ’09 at 22:05

|

2

A good rule of thumb is “.h files should have declarations [potentially] used by multiple source files, but no code that gets run.”

answered May 17 ’09 at 21:13

dj_segfaultdj_segfault

|

1

By convention, .h files are included by other files, and never compiled directly by themselves. .cpp files are – again, by convention – the roots of the compilation process; they include .h files directly or indirectly, but generally not .cpp files.

answered May 17 ’09 at 20:57

bdonlanbdonlan

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

Visit chat

6

Why are function bodies in C/C++ placed in separate source code files instead of headers?

3

1

Difference between C++ files

-7

Why is there a difference between a .cpp file and a .h file?

1

I am having trouble with a multiply defined symbol — main

-6

What kind of information is stored in a .cpp file extension?

Related

2266What is the difference between #include <filename> and #include “filename”?3188What are the differences between a pointer variable and a reference variable in C++?506Storing C++ template function definitions in a .CPP file2836What does the explicit keyword mean?5048How do I include a JavaScript file in another JavaScript file?8758What is the “–>” operator in C++?1267Why do we need virtual functions in C++?1189Difference between require, include, require_once and include_once?1857C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?865What is the difference between ‘typedef’ and ‘using’ in C++11?

Hot Network Questions

If you start casting a new concentration spell while concentrating on Haste, does the wave of lethargy interrupt the casting of the new spell?

Buying and selling the same stock. How is gain for taxes calculated?

An effective way for interstellar communication?

Physical Meaning of the Coriolis Force

91 year old father allowed to fly a plane again?

Deciphering a sentence

Graph Union with Color Properties Kept

Catching Pokemon with TikZ … and why ducks matter

English term for German “Ausgangssperre”

What is the minimum height to a crawl space, and where did you get that information?

One hand was “rotated” through higher dimensions -> two right (or left hands) – Broadcast on 20th century US TV

Instructor listening in secretly in simulated intake assignment — allowed? Ethical?

How to Utilize Dragons That are too Small to Ride in Warfare?

How were the 70’s and 80’s coin-op programmed?

Why isn’t the current split between the transistor and the LED in this NOT transistor circuit?

Sum of squares and partitions

Where in 5e does it state that the Plane Shift spell’s target plane has to be the plane that its tuning fork is attuned to?

Continental US Air Routes that Require More than 2 Stops?

What is the best strategy for an amateur to last as many moves as possible against a GM?

What’s the right way to place these capacitors

What is it called when opposite colored pawns up against each other?

The everyday spear

Why haven’t the Borg tried to assimilate the Talosians from Talos IV?

How do you convey that the minimum size of an input is X characters?

more hot questions

Question feed

Question feed

lang-cpp

Categories

## Naming convention for Django views?

Naming convention for Django views?

10 years, 9 months ago

Active
5 years, 2 months ago

Viewed
3k times

margin-bottom:0;
}

5

2

I’m building a website (in Django) and am confused about the right naming convention to use for my functions. Trivial example: let’s say I have a page that lets the user decide whether they want to see image A or image B. Once the user submits the decision, the site displays the image the user requested.

Here are the two functions I would have in my views module:

def function1(request):
“””Returns the page that presents the user with the choice between A and B”””

def function2(request):
“””Takes in the submitted form and returns a page with the image the user requested.”””

What is the convention for naming the functions that do this? I see at least two feasible ways:

Option 1: function1: “decide”, function2: “view_image”

Option 2: function1: “view_choices”, function2: “decide”

The central issue is that each of these functions does 2 things: (1) process and store the data the user submitted, and (2) return the next page, which may or may not be related to the user’s input. So should I name my functions after (1) or (2)?

django naming-conventions

share|improve this question

edited May 17 ’09 at 21:31

Soviut

asked May 17 ’09 at 20:55

RexERexE

|

4

active

oldest

8

Typically the convention is some kind of CRUD (create, retrieve, update, delete). I personally use index, detail, create, update, delete for my actions. However, I don’t think this applies to your custom functions.

Really it sounds like your functions should be merged into the same “choose” function. You then either display the form or the result depending on whether the result was a POST or not.

Note: I’ve heavily coppied this example form the django docs on form handling.

def choose(request):
“””
Presents the user with an image selection form and displays the result.
“””
if request.method == ‘POST’: # If the form has been submitted…
form = ChoiceForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
# …
return HttpResponseRedirect(‘/thanks/’) # Redirect after POST
else:
form = ChoiceForm() # An unbound form

return render_to_response(‘choose.html’, {
‘form’: form,
})

edited May 17 ’09 at 22:35

answered May 17 ’09 at 21:29

SoviutSoviut

Thanks Soviut! This might be just what I’m looking for. But I’m wondering — would this “choose” function also contain the code to return the page with the picture, or would that code belong in another function? (I wouldn’t be redirecting to ‘/thanks/’ in my case.)

– RexE
May 18 ’09 at 2:05

2

@RexE: If the form is POSTed (which it should be if it modifies data), then you should redirect after processing the data to a different view that displays the page. Otherwise you expose the user to confusing messages and possibly unintentionally executing the action multiple times if they try to refresh the page.

– Carl Meyer
May 18 ’09 at 13:28

@Carl: In most cases I’d agree, except in situations where you’re doing something like returning a search result, but still displaying the search box at the top of the page, in that case redirection is unnecessary. This may be the case with the OP’s question.

– Soviut
May 18 ’09 at 21:31

2

@Soviut: if you’re just displaying a search result, then you should be using GET, not POST.

– Carl Meyer
May 19 ’09 at 13:29

|

1

As long as you have those nice comments in, I suspect it won’t ever be an issue for you.

Anyway, it’s best to name functions based on what they do so function1 could be “displayImageChoices” and function2 could be “displayImage”.

IE, function1 takes some input and displays some choices, function2 takes some input and displays an image.

answered May 17 ’09 at 20:58

Neil TroddenNeil Trodden

3

PEP8 (python.org/dev/peps/pep-0008) says: “Function names should be lowercase, with words separated by underscores as necessary to improve readability. mixedCase is allowed only in contexts where that’s already the prevailing style (e.g. threading.py), to retain backwards compatibility.”

– Andy Baker
May 18 ’09 at 8:37

That’s a good point, I was focusing on “what the names convey”, rather than camelCase/formatting conventions.

– Neil Trodden
May 18 ’09 at 9:07

|

1

I’d use something similar to the built in views (object_list, object_detail, etc) where applicable. (Always a good idea)

The rest would then follow that notion (item_action) as far as possible.

answered May 17 ’09 at 21:33

MackeMacke

|

-1

I know this is a little outdated now, but since the switch to class based views.

PEP8 (python.org/dev/peps/pep-0008) naming conventions for classes would be capitalisation of each word, with no spaces. If you still utilise the function style views, then it would be lower case function names with spaces replaced by underscores for readability.

For example with class based views:

class MyClassBasedView():

Function based

def my_function_based_view():

answered Dec 24 ’14 at 15:56

Neil HickmanNeil Hickman

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Not the answer you’re looking for? Browse other questions tagged django naming-conventions or ask your own question.

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

Related

750What is the naming convention in Python for variable and function names?404C# naming convention for constants?1247What is the meaning of a single and a double underscore before an object name?514REST URI convention – Singular or plural name of resource while creating it

Hot Network Questions

2 buttons that do the same thing

Buddhism broke up my marriage

What are the repercussions of being able to finish a short rest in only 10 minutes instead of taking 1 hour?

How to remove the broken ball end of a 0.9 mm hex key that is stuck inside the socket

Someone on my team is sending bigoted emails to another member on my team

Is traveling to Italy safe?

siunitx, is feature of the mode=text` changed?

Counting the occurrence of a specific letter within a string (QGIS)?

Strange JOIN ON clause in T-SQL

Single Digit Representations of Natural Numbers

What do the ’80/40′ and ‘keyboard’ buttons on my Apple IIc do?

91 year old father allowed to fly a plane again?

Is it okay to work on colleagues’ ideas after they leave academia?

Why isn’t the current split between the transistor and the LED in this NOT transistor circuit?

Buying and selling the same stock. How is gain for taxes calculated?

Can I search games by estimated play time?

Feeding a newborn throughout the night without letting him cry

Continental US Air Routes that Require More than 2 Stops?

How to press a touch sensitive elevator button without touching it

Graph Union with Color Properties Kept

Why are people rioting in Delhi?

Clip a wall to a 6 or 7L pole

What’s the right way to place these capacitors

more hot questions

Question feed

Question feed

default

Categories

## How to make two web sites appear as one – What features are important?

How to make two web sites appear as one – What features are important?

10 years, 9 months ago

Active
10 years, 9 months ago

Viewed
131 times

margin-bottom:0;
}

0

1

I am about to write a tender. The solution might be a PHP based CMS. Later I might want to integrate an ASP.NET framework and make it look like one site.

What features would make this relatively easy.
Would OpenId and similar make a difference?
In the PHP world Joomla is supposed to be more integrative than Druapal. What are the important differences here?
Are there spesific frameworks in ASP.NET, Python or Ruby that are more open to integration than others?

drupal web openid joomla

share|improve this question

asked May 17 ’09 at 20:55

OlavOlav

|

2

active

oldest

1

The most important thing is going to be putting as much of the look-and-feel in a format that can be shared by any platforms. That means you should develop a standard set of CSS files and (X)HTML files which can be imported (or directly presented) in any of those platform options. Think about it as writing a dynamic library that can be loaded by different programs.

Using OpenID for authentication, if all of your platform options support it, would be nice, but remember that each platform is going to require additional user metadata be stored for each user (preferences, last login, permissions/roles, etc) which you’ll still have to wrangle between them. OpenID only solves the authentication problem, not the authorization or preferences problems.

Lastly, since there are so many options, I would stick to cross-platform solutions. That will leave you the most options going forward. There’s no compelling advantage IMHO to using ASP.NET if there’s a chance you may one day integrate with other systems or move to another system.

answered May 17 ’09 at 21:09

dj_segfaultdj_segfault

|

1

I think that most important thing is to choose the right server. The server needs to have adequate modules. Apache would be good choice as it supports all that you want, including mod_aspnet (which I didn’t test, but many people say it works).

If you think asp.net integration is certanly going to come, I would choose Windows as OS as it will certanly be easier.

You could also install reverse proxy that would decide which server to render content based on request – if user request aspx page, proxy will connect to the IIS and windoze page, if it asks for php it can connect to other server. The problem with this approach is shared memory & state, which could be solved with carefull design to support this – like shared database holding all state information and model data….

OpenID doesn’t make a difference – there are libs for any framework you choose.

answered May 17 ’09 at 21:05

majkinetormajkinetor

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Not the answer you’re looking for? Browse other questions tagged drupal web openid joomla or ask your own question.

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

Related

51What is the benefit of using ONLY OpenID authentication on a site?9Is there an OpenID 2.0 plugin for Symfony?13Implementing OpenID in ASP.net “Properly” – Membership or Authentication Provider?0Joomla Standalone Script in PHP – Handshake1Question on building a Joomla web site for data driven content1how to make it easy for users to register at my site?0Full-featured web framework/CMS for building web sites based on imported offline content0Tell Joomla to be set to logged-in status via outside PHP script

Hot Network Questions

Summing a sub-square of a quarter of an infinite chessboard

What’s the difference between a rolled chord and a broken chord?

Why would a part be available as 4.99k and 5k?

Someone on my team is sending bigoted emails to another member on my team

(RGS 2/5) How many strings can you count within these character classes?

Is it a reasonable strategy to keep the ratio of investments constant?

What are the repercussions of being able to finish a short rest in only 10 minutes instead of taking 1 hour?

Is it okay to work on colleagues’ ideas after they leave academia?

Clip a wall to a 6 or 7L pole

Continental US Air Routes that Require More than 2 Stops?

Sorting list on multiple criteria based on means of subgroups

Deciphering a sentence

Are creatures with the immune to poisoned condition immune to poison damage?

How to Utilize Dragons That are too Small to Ride in Warfare?

Graph Union with Color Properties Kept

Should I tell interviewer that I will use their offer to renegotiate current rate first?

What is the phrase represented by this rebus?

If the ISS had an emergency, how long would it take to get a rocket to it?

Embedding Sets of Sets

Substructure search with RDKit

How to straighten a sagging wooden house?

A random sphere containing the center of the unit cube

アップは? バッチリです。How to understand this exchange?

more hot questions

Question feed

Question feed

default

Categories

## How to combine 2 LINQ into one

How to combine 2 LINQ into one

10 years, 9 months ago

Active
4 years, 2 months ago

Viewed
801 times

margin-bottom:0;
}

0

I am trying to populate a treeview control with some info and for that I am using 2 separate LINQ statements as follows;

Dim a = From i In CustomerTable _
Group By ShipToCustName = i.Item(6), BillToCustName = i.Item(4) Into Details = Group, Count() _
Order By ShipToCustName

Dim b = From x In a _
Group By ShipToName = x.ShipToCustName Into Group, Count() _
Order By ShipToName

For Each item In b
Console.WriteLine(“Shitp To Location: ” + item.ShipToName)
For Each x In item.Group
Console.WriteLine(“…BillTo:” + x.BillToCustName)
For Each ticket In x.Details
Console.WriteLine(“……TicketNum” + ticket.Item(0).ToString)

Next
Next
Next

Is there a way to combine A and B into one query ? Any help please …

linq

share|improve this question

edited Dec 14 ’15 at 5:26

marc_s

asked May 17 ’09 at 21:00

KirillKirill

|

1

active

oldest

3

Well, really B is a single query. Remember that what comes back from a Linq statement is an IQueryable, not the actual result. This means that B combines its own expressions with that of A, but retrieval is not performed until you enumerate B. So B really is just a single query.

answered May 17 ’09 at 21:07

spenderspender

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

Related

1013LINQ query on a DataTable661Dynamic LINQ OrderBy on IEnumerable<T> / IQueryable<T>707LINQ equivalent of foreach for IEnumerable<T>1560Multiple “order by” in LINQ814When to use .First and when to use .FirstOrDefault with LINQ?1Linq Join Question705LINQ Aggregate algorithm explained1035Group by in LINQ1How to group linq query by dynamic items

Hot Network Questions

Is it a reasonable strategy to keep the ratio of investments constant?

Why are people rioting in Delhi?

If you start casting a new concentration spell while concentrating on Haste, does the wave of lethargy interrupt the casting of the new spell?

How to remove the broken ball end of a 0.9 mm hex key that is stuck inside the socket

How to straighten a sagging wooden house?

Is technical debt management problem more of a culture issue or insight issue

If a broad long-term investment in the stock market is such a good deal, why don’t banks do the “obvious” things?

Trivial homology with local system

Is a dystopian surveillance state computationally possible?

Why haven’t the Borg haven’t tried to assimilate the Talosians from Talos IV?

Summing a sub-square of a quarter of an infinite chessboard

What’s the right way to place these capacitors

What do we know about the (earlier) Terminator 3 script?

Transform dollars in exact change

What’s the difference between a rolled chord and a broken chord?

How were the 70’s and 80’s coin-op programmed?

Buddhism broke up my marriage

Which subatomic particle does each company use in quantum computing?

“Have you been granted any UK visas in the last 10 years?”

Word square thriller

Query replace regexp with a distant match?

What is the phrase represented by this rebus?

more hot questions

Question feed

Question feed

default

Categories

## What is the difference between the shape and structure of an object?

What is the difference between the shape and structure of an object?

10 years, 9 months ago

Active
4 years, 3 months ago

Viewed
4k times

margin-bottom:0;
}

0

I see it used a lot in context of data. From ScottGu’s post:

One of the really powerful
capabilities provided by LINQ and
query syntax is the ability for you to
define new classes that are separate
from the data being queried, and to
then use them to control the shape and
structure of the data being returned
by the query.

What does he mean when he refers to shape of the data?

oop language-agnostic

share|improve this question

edited Nov 5 ’15 at 10:56

Brian Tompsett – 汤莱恩

asked May 17 ’09 at 21:05

aleembaleemb

6

I don’t think it does! Can you please give a more detailed example of what you mean?

– Neil Trodden
May 17 ’09 at 21:06

@Neil: added some context. hopefully that should make it clearer

– aleemb
May 17 ’09 at 21:27

Thanks, I know people in the know understood it, I’m just looking it from the point of view of a clueless noob – ie me! 🙂

– Neil Trodden
May 17 ’09 at 22:23

|

4

active

oldest

1

consider shape to be the objects “api” while the structure is it’s internal implementation. In a well designed system the shape will remain static while the structure may change significantly.

answered May 17 ’09 at 21:13

ennuikillerennuikiller

|

3

I think these are informal terms, and the definitions are subjective. I would use “shape” to refer to how the object fits in with other objects in the system. (Compare “surface area”, which is a rough (no pun intended 🙂 measure of the complexity of the object’s interface.) I’d use “structure” to refer to how the object is designed and implemented internally.

Hence you can have classes that have a good “shape”, but a structure like crepe paper. That’s probably easier to refactor than the other way around: a poor shape, but good implementation. (I’m sure some folks would question whether the latter is even possible.)

edited May 17 ’09 at 21:22

answered May 17 ’09 at 21:10

Dan BreslauDan Breslau

|

1

The shape is any spatial attributes (especially as defined by outline) of the object, whereas the structure is the manner of construction of the object and the arrangement of its parts. Of course, that can apply to any type of object. 🙂

answered May 17 ’09 at 21:10

karim79karim79

|

1

Generally, I would consider the shape of an a class to be the public methods and properties that the class offers. The structure would be the internal constructs and representation used. In the context of the quoted material, I would take it to mean that by allowing one to define the return type of a query using anonymous or alternate named classes, you can redefine the data returned by query, constraining and transforming its shape from the original data source.

For example, say you have a user table that is related to a contacts table. Using LINQ and anonymous class as the selection, you can return a user with primary contact object without having to define a particular view; using only LINQ.

var userWithContact = from u in db.Users
select new
{
Name = u.Name,
.Where( c => c.Type = “self” ).First().Address
};

answered May 17 ’09 at 22:21

tvanfossontvanfosson

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Not the answer you’re looking for? Browse other questions tagged oop language-agnostic or ask your own question.

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

Related

7979What and where are the stack and heap?5567What are metaclasses in Python?3040What is dependency injection?3468Difference between staticmethod and classmethod1704What’s the difference between a method and a function?670What’s the difference between faking, mocking, and stubbing?1554What is the difference between an abstract function and a virtual function?1205What are the differences between type() and isinstance()?1733What is the difference between an interface and abstract class?1106Reference – What does this error mean in PHP?

Hot Network Questions

stroke of multiple color vs single color

tubular tire replacement

Docker: One container per database?

Square-Cube Digit Usage

Would my species even create a government?

Why would a part be available as 4.99k and 5k?

Is there a way to save a command in Ubuntu terminal if I haven’t entered it?

If a broad long-term investment in the stock market is such a good deal, why don’t banks do the “obvious” things?

Small FizzBuzz program

Buddhism broke up my marriage

Cops-and-robbers when the criminals have near-perfect knowledge of the cops?

Motivation for Karoubi envelope/ idempotent completion

Interactive Discord bot for tabletop RPG

Is Ann Arbor within reasonable Lyft/Uber range of DTW?

Word square thriller

What does space have to do with providing “fresh water … without the need for aquifers or pipes?” as Steven Kwast suggested?

How is Challenge Rating (CR) calculated for a mixed group of multiple monsters in regards to the Treasure Table?

Someone on my team is sending bigoted emails to another member on my team

What do the ’80/40′ and ‘keyboard’ buttons on my Apple IIc do?

Deciphering a sentence

What exactly is the difference between all these dairy products?

Single Digit Representations of Natural Numbers

more hot questions

Question feed

Question feed

Categories

## What are the disadvantages of Aspect-Oriented Programming (AOP)?

What are the disadvantages of Aspect-Oriented Programming (AOP)?

10 years, 9 months ago

Active
5 years, 8 months ago

Viewed
12k times

margin-bottom:0;
}

26

7

What are the possible and critical disadvantages of Aspect-Oriented Programming?

For example: cryptic debugging for newbies (readability impact)

aop

share|improve this question

edited May 17 ’09 at 21:09

Thomas Owens

asked May 17 ’09 at 21:06

user2427user2427

|

7

active

oldest

8

Poor toolchain support – debuggers, profilers etc may not know about the AOP and so may work on code as if all the aspects had been replaced by procedural code
Code bloat – small source can lead to much larger object code as code is “weaved” throughout the code base

answered May 17 ’09 at 21:13

MackerMacker

|

13

I think the biggest problem is that nobody knows how to define the semantics of an aspect, or how to declare join points non-procedurally.

If you can’t define what an aspect does independently of the context in which it will be embedded, or define the effects that it has in such a way that it doesn’t damage the context in which it is embedded, you (and tools) can’t reason about what it does reliably. (You’ll note the most common example of aspects is “logging”, which is defined as “write some stuff to a log stream the application doesn’t know anything about”, because this is pretty safe). This violates David Parnas’ key notion of information hiding. One of the worst examples of aspects that I see are ones that insert synchronization primitives into code; this effects the sequence of possible interactions that code can have. How can you possibly know this is safe (won’t deadlock? won’t livelock? won’t fail to protect? is recoverable in the face of a thrown exception in a synchronization partner?) unless the application only does trivial things already.

Join points are now typically defined by providing some kind of identifier wildcarding (e.g, “put this aspect into any method named “DataBaseAccess*”. For this to work, the folks writing the affected methods have to signal the intention for their code to be aspectized by naming their code in a funny way; that’s hardly modular. Worse, why should the victim of an aspect even have to know that it exists? And consider what happens if you simply rename some methods; the aspect is no longer injected where it is needed, and your application breaks. What is needed are join point specifications which are intentional; somehow, the aspect has to know where it is needed without the programmers placing a neon sign at each usage point. (AspectJ has some control-flow related join points which seem a bit better in this regard).

So aspects are kind of interesting idea, but I think they are technologically immature. And that immaturity makes their usage fragile. And that’s where the problem lies.
(I’m a big fan of automated software engineering tools [see my bio] just not this way).

edited Jun 13 ’14 at 23:36

Pacerier

answered Dec 22 ’11 at 17:42

Ira BaxterIra Baxter

4

+1, The string matching of method names is an extremely horrible (fragile) way to inject pointcuts.

– Pacerier
Jun 13 ’14 at 23:40

|

8

I think the biggest disadvantage is using AOP well. People use it in places where it doesn’t make sense, for example, and will not use it where it does.

For example, a factory pattern is obviously something that AOP can do better, as DI can also do it well, but the observer pattern is simpler when using AOP, as is the strategy pattern.

It will be harder to unit test, esp if you do the weaving at runtime.

If weaving at runtime then you also take a performance hit.

Having a good way to model what is going on when mixing AOP with classes is a problem, as UML I don’t think is a good model at that point.

Unless you are using Eclipse then tools do have problems, but, with Eclipse and AJDT AOP is much easier.

We still use junit and nunit for example, and so have to modify our code to allow unit tests to run, when using priviledged mode AOP could do better unit tests by testing private methods also, and we don’t have to change our programs just to make them work with unit-testing. This is another example of not really understanding how AOP can be helpful, we are still chained in many ways to the past with unit-test frameworks and current design pattern implementations and don’t see how AOP could help us do better coding.

answered May 17 ’09 at 22:04

James BlackJames Black

Is it really harder to unit test? Shouldn’t the unit tests test the aspects and now have nothing to do with depending on how they are woven?

– Zombies
Oct 28 ’11 at 14:18

1

@Zombies – How do you test the aspects by themselves, since the only way to do that is to include them. If you weave at runtime then it has to be set up to do the weaving when the test runs.

– James Black
Oct 28 ’11 at 20:52

Humble question from a newbie: What factory pattern has with cross-cutting concerns? I mean, why AOP do it better?

– Keyne Viana
Oct 5 ’12 at 3:30

1

AspectJ is useful for more than just cross-cutting concerns. You may find this article to be useful, for example, regarding AspectJ and design patterns: homepages.cwi.nl/~storm/teaching/reader/HannemannKiczales02.pdf

– James Black
Oct 5 ’12 at 15:40

|

7

Maintenance and Debugging. With aop, you suddenly have code that is being run at a given point ( method entry, exit, whatever ) but in just looking at the code, you have no clue that it’s even getting called, especially if the aop configuration is in another file, like xml config. If the advice causes some changes, then while debugging an application, things may look strange with no explanation. This doesn’t affect only newbies.

answered May 17 ’09 at 21:44

digitaljoeldigitaljoel

|

2

I would not call it a critical disadvantage, but the biggest problem I have seen is one of developer experience and ability to adapt. Not all developers yet understand the difference between declarative and imperative programming.

We make use of the policy injection application block in EntLib 4.1 pretty extensively as well as Unity for DI and it’s just not something that sinks in quickly for some people. I find my self explaining over and over again to the same people why the application is not behaving in the way they expect. It generally starts off them explaining something and me saying “see that declaration above the method.” 🙂 Some people get it right away, love it and become extremely productive — others struggle.

Learning curve is not unique to AOP, but it seems to have a higher learning curve that other things that your average developer encounters.

answered May 17 ’09 at 21:15

JP AliotoJP Alioto

|

0

With regard to the maintenance/debugging argument, aspect-oriented programming tends to go hand-in-hand with all the other aspects of agile software-development practices.

These practices tend to remove debugging from the picture, replacing it with unit testing and test-driven development.

In addition, it may be much easier to maintain a small, clear code footprint with advice than a large, incomprehensible code footprint without advice (the advice being the thing that transforms a large, incomprehensible code footprint into a small, clear code footprint).

answered May 17 ’09 at 22:12

yfeldblumyfeldblum

|

0

Because the power of AOP, if there is a bug your crosscutting, it can cause to widespread problems. On the otherhand, someone might change the join points in a program – e.g., by renaming or moving methods – in ways that the aspect writer did not expect, with unintended consequences. One advantage of modularizing crosscutting concerns is enabling one programmer to affect the entire system easily.

answered Nov 20 ’10 at 12:12

hhafezhhafez

|

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Submit

Post as a guest

Name

Email
Required, but never shown

Blog

The eight factors of happiness for developers

This week, #StackOverflowKnows outlaw wifi, GPU weakness, and neutrinos per…

Featured on Meta

The company’s commitment to rebuilding the relationship with you, our community

The Q1 2020 Community Roadmap is on the Blog

Planned maintenance scheduled for Saturday, March 7, 2020 at 14:00 UTC (9AM…

What is the mission of Meta, as a community?

43

Most interesting non-mainstream language?

8

Spring Roo and aspect-oriented programming

Related

194Aspect Oriented Programming vs. Object-Oriented Programming224What is aspect-oriented programming?7Aspect-oriented programming in Java17Aspect-oriented programming in android595Uncatchable ChuckNorrisException

Hot Network Questions

What do these numbers above the terminal jetway mean for pilots?

Crossword Honeycomb – 1

How do you tell that a minimum size of an input is X characters?

Cops-and-robbers when the criminals have near-perfect knowledge of the cops?

Is there a way to get a history of transaction log used space in SQL Server?

Is a dystopian surveillance state computationally possible?

The everyday spear

Summing a sub-square of a quarter of an infinite chessboard

Why isn’t the current split between the transistor and the LED in this NOT transistor circuit?

stroke of multiple color vs single color

PTIJ: Whose rabbinical supervision would Achashverush have used?

Clip a wall to a 6 or 7L pole

Trivial homology with local system

Instructor listening in secretly in simulated intake assignment — allowed? Ethical?

How could humans reach distant stars and still stay as a united government if you can’t use faster than light travel

What exactly is the difference between all these dairy products?

Should I tell interviewer that I will use their offer to renegotiate current rate first?

Is traveling to Italy safe?

Is Ann Arbor within reasonable Lyft/Uber range of DTW?

What is the likely result of rent control in Berlin?

Why do unfinished basements need GFCI outlets?

(RGS 2/5) How many strings can you count within these character classes?

more hot questions

Question feed