|
Not very horrific, but I think it is kind of cute:
#define UNUSED1(a) a=a
#define UNUSED2(a,b) a=a,b=b
#define UNUSED3(a,b,c) a=a,b=b,c=c
#define UNUSED4(a,b,c,d) a=a,b=b,c=c,d=d
What use could these UNUSED functions possibly have? Well, I
had to ask one of the other programmers. If you have unused
parameters in a functions parameter list, a warning occurs
"unused parameters in the parameter list" or something like
that. How to get rid of those pesky unused parameters? Call
the UNUSED function with those unused parameters. The UNUSED
function will use the unused parameters, making them used
parameters instead. Now no warning for unused parameters will
occur! Problem solved!
|
|
|
|
|
this is a common practice.
you can do either one of the following :
void MyClass::MyMethod( int i, CString& s )
{
UNUSED( i );
UNUSED( s );
}
or
void MyClass::MyMethod( int , CString& )
{
}
or
void MyClass::MyMethod( int, CString& )
{
}
|
|
|
|
|
I'm sure it's "common practice", but why have unused parameters in the first place? It's aint right, I tells ya!
|
|
|
|
|
This is not correct.
When using a given framework, one can't choose the functions signature.
Sometimes we only need to know when an event has occured, but extra information is given which we don't need.
You could hide all warnings with the #pragma directive but that is dangerous, because that will hide alsoo the correct warnings.
Therefore you should remove/comment the parameter from the function signature or use the parameter.
Most compiler will ignore the a=a line when builded so there is no speed constaint.
I preffer to comment the unused paramters out
codito ergo sum
|
|
|
|
|
BadKarma wrote: Therefore you should remove/comment the parameter from the function signature or use the parameter.
You can also get the harmless warnings.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Ahh just start ignoring those harmless warnings...
That way lies madness!
I'm pretty sure I would not like to live in a world in which I would never be offended.
I am absolutely certain I don't want to live in a world in which you would never be offended.
Dave
|
|
|
|
|
Automatically VS2005 generated code:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
Actually it is just deceiving compiler to avoid warnings.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
for example, in MFC :
you have a message handler for the Left button down :
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
In my code ( or yours ) you might not need to use the nFlags parameter, so you do something like :
void CMyWindow::OnLButtonDown(UINT , CPoint point)
{
}
|
|
|
|
|
The only reason it may be "common practice" is a policy of no warnings or to eliminate irritating warnings about something that does no harm. I have never seen it done, as it is a method/function signature thing and commenting out the parameters makes more since (aka: /*parameter*/). On the plus side, modern compilers will normally optimize out self assignment, so using such macros eliminates the warning with out producing uneeded code (well it is supposed to anyway). The down side is wasting time typing in bull<blank> code that has nothing to do with what the method/function does.
It is interesting, but I do not like the idea at all.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Because the parameters are part of a published and widely used API, and as a result redefining the signature isn't an option even if the parameter is no longer needed?
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop.
-- Matthew Faithfull
|
|
|
|
|
It is horrific indeed.
#define UNUSED(a) a=a
could suffer from side effects caused by the assignment operator.
Consider
int x = 3;
UNUSED(++x);
return x;
Which will be the value of x?
Or it could be a function that returns an unused variable, such as
int& f(int& x) {
return ++x;
}
main() {
int x = 2, y;
UNUSED(y = f(x), y);
}
and we end up in
int& f(int& x) {
return ++x;
}
main() {
int x = 2, y;
(y = f(x), y) = (y = f(x), y);
}
UNUSED should mean one will not use the parameter in subsequent operations, but won't alter the content, nor produce side-effects - so let evaluate it but don't use the result.
UNREFERENCED_PARAMETER(a) or even ((void)(a)) will do here. Those UNUSED are really pain in the a** here.
Nuclear launch detected
|
|
|
|
|
The cleanest way I've found which compiles with both /W4 and cleanly with lint, is simply to cast the variables to void, like so (C example, but works with C++)
int myfunction (int unusedarg)
{
(void) unusedarg;
return (1);
}
Mike
|
|
|
|
|
So, I'm looking at the code for one our apps, and all of the source files start with comments like:
OK, thanks for telling me that you've been following our file-naming convention. But what does the class do?
|
|
|
|
|
What about an automated tool that deletes all code having less than 10% of comments in?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Won't do. You can easily meet the 10% quota by writing things like:
void CFoo::LogMessage(const CString& strMsg)
|
|
|
|
|
what about an automated routine that deletes all code from incompentant programmers
|
|
|
|
|
Gimme back my code!!!!!!!!!!!!!!!!!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
This is very probably a template for new source files which was never changed.
For what the class does - Use the code, Luke!
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
jhwurmbach wrote: For what the class does - Use the code, Luke!
Well, yeah. But such headers requires the reader having to scroll more, thus adding to the wear and tear on his/her finger joints. That is bad, and might result in a shortened life span as a programmer.
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
What? You mean you don't have the audio/visual integration tool based on the Apache weapons officer helmet that tracks your eye movement and interprets you verbal commands? Man, life became much easier when I put on the helmet. I can't wait until they finish getting the jack put in my cerebelum so I can just think code.
|
|
|
|
|
Be very aware of this (or maybe it's common knowledge, and somehow I missed this vital info all these years).
If you accidentelly leave tracing enabled on a production site, be aware that anyone can see the details for the past xx requests. Now normally this info is fairly mundane - control hierarchy and server variables.
However, if you store connection strings in the HttpContext object, they will get output in the trace!! Could be very risky.
Of course normally you would use the connectionstrings helper which is available with ASP.NET 2.0 onwards, however if you have an older app, you may be doing this (e.g. when you Server.MapPath() to your local access database or something, and later upgrade to SQL server but keep the connection string in httpcontext object )
"For fifty bucks I'd put my face in their soup and blow." - George Costanza
CP article: SmartPager - a Flickr-style pager control with go-to-page popup layer.
|
|
|
|
|
So, if you forget to turn off debugging code and do some pretty stupid stuff around your storing of connections, and some user manages to try this and figure it out, you could be in trouble if your network isn't properly secured.
Subtle.
|
|
|
|
|
Paddy Boyd wrote: forget to turn off debugging code
Yep, sloppy. Makes a stronger case for specifically scheduling code-reviews a while after initial development.
Paddy Boyd wrote: pretty stupid stuff around your storing of connections
OK, so apart from this potential scenario, what reason would you give me for NOT storing a connection string in the application state? (Bear in mind it has to call Server.MapPath .. so ConfigurationSettings.AppSettings is no good - and I'm talking .NET 1.1 here).
Paddy Boyd wrote: Subtle.
Yes it is. Especially for traditional ASP programmers - you just don't expect your Application variables to ever be visible to the public like that.
"For fifty bucks I'd put my face in their soup and blow." - George Costanza
CP article: SmartPager - a Flickr-style pager control with go-to-page popup layer.
|
|
|
|
|
Hi, I am in the trouber of the error while the project trys to saving the data to child table. The error message
is shown below:
NHibernate.ADOException: could not insert: [ConsoleApplication1.user][SQL: INSERT INTO user (UNAME, NID) VALUES (?, ?)] --->
So confused that why it cannot get values to save. NHibernate I used is version 1.2. The code files are list below, please help me out here.
Thanks in advance.
app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.2.0.4000,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<nhibernate>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<add key="hibernate.connection.connection_string" value="Server=;initial catalog=;Persist Security Info=True;User ID=;Password="/>
</nhibernate>
</configuration>
user.hbm.xml:
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="ConsoleApplication1.user, ConsoleApplication1" table="user">
<id name="UID" type="System.Int32" column="UID" unsaved-value="0">
<generator class="native" />
</id>
<property name="UNAME" type="System.String" column="UNAME" not-null="false" />
<many-to-one name="Nationality" class="ConsoleApplication1.nationality, ConsoleApplication1" fetch="select" cascade="all">
<column name="NID" not-null="false" />
</many-to-one>
</class>
</hibernate-mapping>
user.hbm.cs:
namespace ConsoleApplication1 {
[System.SerializableAttribute()]
public class Abstractuser {
private int uID;
private string uNAME;
private ConsoleApplication1.nationality nationality;
public virtual int UID {
get {
return this.uID;
}
set {
this.uID = value;
}
}
public virtual string UNAME {
get {
return this.uNAME;
}
set {
this.uNAME = value;
}
}
public virtual ConsoleApplication1.nationality Nationality {
get {
return this.nationality;
}
set {
this.nationality = value;
}
}
}
[System.SerializableAttribute()]
public partial class user : Abstractuser {
}
}
nationality.hbm.xml:
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="ConsoleApplication1.nationality, ConsoleApplication1" table="nationality">
<id name="NID" type="System.Int32" column="NID" unsaved-value="0">
<generator class="native" />
</id>
<property name="NATIONALITY" type="System.String" column="NATIONALITY" not-null="false" />
<bag name="User" inverse="true" lazy="true" cascade="all">
<key>
<column name="NID" not-null="false" />
</key>
<one-to-many class="ConsoleApplication1.user, ConsoleApplication1" />
</bag>
</class>
</hibernate-mapping>
nationality.hbm.cs:
namespace ConsoleApplication1 {
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ConsoleApplication1.user))]
[System.Xml.Serialization.SoapIncludeAttribute(typeof(ConsoleApplication1.user))]
public class Abstractnationality {
private int nID;
private string nATIONALITY;
private System.Collections.IList user;
public virtual int NID {
get {
return this.nID;
}
set {
this.nID = value;
}
}
public virtual string NATIONALITY {
get {
return this.nATIONALITY;
}
set {
this.nATIONALITY = value;
}
}
public virtual System.Collections.IList User {
get {
return this.user;
}
set {
this.user = value;
}
}
}
[System.SerializableAttribute()]
public partial class nationality : Abstractnationality {
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly("ConsoleApplication1");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
nationality nat = (nationality)session.Get(typeof(nationality), 1);
user u = new user();
u.UNAME = "Pall";
u.Nationality = nat;
nat.User.Add(u);
try
{
if (!session.IsConnected)
{
session.Reconnect();
}
session.Save(u); // Error occured at this line!!
transaction.Commit();
session.Close();
}
catch (Exception e)
{
string s = e.ToString();
}
}
}
}
|
|
|
|
|
yeah, i see the horror in this
(yes|no|maybe)*
|
|
|
|